avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Petri Salmi <petri.sa...@smartner.com>
Subject RE: CommandQueue questions
Date Fri, 14 Mar 2003 07:26:12 GMT


I think this is more like Avalon Users stuff, so I am directing the 
response there.  

On 12. maaliskuuta 2003 22:39, Filip Defoort
[mailto:filip@cirquedigital.com] wrote:

> Hi,
> Couple of questions reg. the CommandQueue (in same spirit of the ones 
> reg. the Cache):
> 1/ is it possible to "manage"/"view" a Queue, that is can a Queue be
> queried to see which commands are running + can running commands 
> be interrupted (I know this is a though one, but I still need some
> way of interrupting long operations, the well-known dough-experience)

AFAIK, the commands are run in for as long as it takes them to complete.
I would suggest that you wrap your long running commands within a 
monitoring instance that can interrupt the process if required.

You could use something like:

public class InterruptableCommand 
    private final Command m_command;
    private final InterruptStatus m_status; 

    public InterruptableCommand ( final Command command,
                                  final InterruptStatus status ) 
       this.m_command = command;
       this.m_status = status;
    public void execute()
        final Thread t = new Thread( 
            new Runnable() 
                public void run() 
            } ); 

	  while( t.isRunning() && 
	         ! status.isInterrupted() )
                Thread.sleep( INTERRUPT_WAIT_MS );
            catch ( InterruptedException ie ) {}
        if ( t.isRunning() ) {
               t.join( INTERRUPT_WAIT_MS );
           catch ( InterruptedException ie ) {}

That way you also end up using the IoC pattern nicely with the 
command.  Now you just need to store the InterruptStatus for every
long running command and update it when user or other interrupting
instance wants to stop command processing.

Anyway, above code is only for illustration, I do not advice you to 
use it anywhere. 

> 2/ can a command send messages to the queue about it's status (e.g. a 
> progress meter for long running commands, providing feedback to the 
> end-user) ?

I would apply here the IoC pattern too. Instead of getting the 
progress meter from queue, implement interface like 
ProgressMeterable etc., which would contain a single method 
setProgressMeter( ProgressMeter meter ).

Now you can use this method in your application to give the progress 
meter to command.   In command you can now just call something

    if ( this.m_progressMeter != null )
        this.m_progressMeter.reportProgress ( this.percentDone );  

while in the UI code you initialize the progress bar and set it to
the command:

    public enqueueCommand( Command longRunning )
        if ( longRunning instanceof ProgressMeterable ) 
            ( (ProgressMeterable) longRunning ).setProgressMeter (
                this.m_statusBar.progressBar );

        // this is also the place to wrap with InterruptableCommand
        // if you feel like it.
	  this.m_queue.enqueue( longRunning );

(assuming of course that your application has a status bar that implements 
the ProgressMeter interface and is updated within regular interval).

Maybe someone with better knowledge of fortress can tell you whether 
these structures already exist there.

- psalmi

To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org

View raw message