avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leo Simons" <m...@leosimons.com>
Subject RE: [vote] lifecycle exceptions
Date Thu, 12 Apr 2001 18:35:53 GMT
Excellent analysis here, Berin!

> interface Interruptable extends Executable {


> Regarding the case where something is "startable" with no direct 
> control over
> when it stops, I want to promote the "Command" pattern.  

+1. Agreeing one hundred percent here - this is the best solution
I know for long-running threads.

> Basically, we would have an interface for the Command object like this:
> interface Command {
>     void execute();
> }
> We would either provide a CommandQueue, or have that command object start
> after the Component it affects is fully set up. 

I'm for the latter...It makes sense to have the managing object worry about
how to start the commands. So 

// ...
myComponent.start(); // or should this go after getCommands()?
Iterator commands = ((Commandable)myComponent).getCommands();
for(commands.hasNext()) {
	myThreadPool.add(new WorkerThread(commands.next()));
myComponent.interrupt(); // component is responsible for interrupting
				 // Commands if that is neccessary
myComponent.resume(); // component is responsible for resuming interrupted
			    // commands

// ... shutdown
myThreadPool.stopAll(); // guaranteed before dispose()
myThreadPool.disposeAll(); // guaranteed before dispose()
myComponent = null;
myThreadPool = null; // last reference gone
// ...

is possible. In the above (which will work with Phases in practice),
Command would have to look like this:

interface Command extends Runnable { // or we could extend Thread,
						 // which means even more options
						 // but also a more heavyweight
						 // solution.
	void run() throws CascadingRuntimeException;

which would allow re-use of std pooling systems. It needs to be
guaranteed that getCommands() is called after start() but before
run(), and that the run() of the returned commands is called
right after the run() of the component (I'm not sure this is the
right place for those methods; important is that their point of
execution is clearly defined).

This setup has maximum flexibility while allowing complete
manageability. I'm kinda wondering why the Command pattern was
removed from the code...



	About LSD  = new PersonalInfo();
	LSD.name("Leo Simons");
		http://www.leosimons.com, // personal website
		http://www.atfantasy.com, // fantasy RPG portal
		http://www.the-sign.nl    // web-design company
	] );

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

View raw message