Re: Properly Stopping a Stage

Jean Morissette <[email protected]> Fri, 07 Jan 2005 15:57:29 -0500
Newsgroups gmane.comp.java.seda.user
Message-ID <[email protected]>
So, I want to give the possibility to a handler to accelerate a stop 
request, by supporting "rollback".

If a handler detect the stop request, with Thread.interrupted(), it 
should be able to return the events that are not processed yet and stop 
immediately (just return), instead of processing all events.  By 
exemple, a handler that want to be very responsive to stop request could do:

public QueueElementIF[] handleEvents(QueueElementIF[] events) {
   for (int i = 0; i < events.length; i++) {
     if (Thread.interrupted()) {
       // we are requested to stop,
       // so return events not processed (rollback)
       int size = events.length - i;
       QueueElementIF[] remainingEvents = new QueueElementIF[size];
       System.arraycopy(events, i, remainingEvents, 0, size);
       return remainingEvents;
     }
     else {
       // process event
       QueueElementIF event = events[i];
       handleEvent(event);
     }
   }
}

SS would put returning events at the head of the queue (like a Deque). 
So, the next time that handleEvents will be called, the handler will 
receive the events that it has returned.

Comments, suggestions?


Jean Morissette wrote:
> Hi,
> When a stage is requested to stop, we call Thread.interupt for all 
> thread in the ThreadPool after a delay (configurable per stage).
> 
> To ensure that no queue events are lost, stopping a stage this way force 
> the handler to roll-forward.  Roll-forward is not always desirable; 
> suppose that a handler receive 10 elements and that each element take 6 
> secondes to process, so stopping this handler could take 60 secondes!
> 
> So, I would like that SS provide a way to rollback, in response to a 
> stop request.  So, stopping a stage without lossing events could be very 
> fast.  But how achieve that?
> 
> See http://gee.cs.oswego.edu/dl/cpj/cancel.html for reference on 
> rollback and roll-forward.



-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt