avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen McConnell <mcconn...@apache.org>
Subject Re: More "academic" ideas [Was: [VOTE] New sandbox project]
Date Thu, 11 Mar 2004 16:34:59 GMT
Hamilton Verissimo de Oliveira (Engenharia - SPO) wrote:
>>Something like:
>>
>>   chain = CreationDestruction --> SetupTeardown -->  StartupShutdown
> 
> 
> Too abstract.
> Put that in code, please.

A lifecycle runs in two directions - setup (forward) and teardown 
(backwards). If your going to create an abstract chain then the chain 
needs to represent the logical steps taken in both directions.  So in 
the above example you have a phase dealing with CreationDesctruction. 
If setup is applied to that phase, then you know that to teardown the 
component you need to invoke teardown on the CreationDesctruction object.

Example (change names to whatever you want):

   List list = new ArrayList();
   list.add( new CreationPhaseHandler() );
   list.add( new InitializationPhaseHandler() );
   list.add( new ExecutionPhaseHandler() );
   PhaseHandler[] chain = convertToArray( list );

So now we have an order list of phase handlers.  From this list we can 
process the in two directions - forward and backwards.

   public void setupChain( PhaseHandler[] chain )
   {
        ArrayList list = new ArrayList(); // list of processed handlers
        for( int i=0; i<chain.length; i++ )
        {
             PhaseHandler handler = chain[i];
             try
             {
                  handler.setup();
                  list.add( handler );
             }
             catch( Throwable e )
             {
                  PhaseHandler[] rollback = convertToArray( list );
                  tearDownChain( rollback );
                  throw e;
             }
        }
   }

   public void tearDownChain( PhaseHandler[] chain )
   {
        for( int i=0; i<chain.length; i++ )
        {
             PhaseHandler handler = chain[i];
             handler.teardown();
        }
   }


Steve.

-- 

|------------------------------------------------|
| Magic by Merlin                                |
| Production by Avalon                           |
|                                                |
| http://avalon.apache.org/merlin                |
| http://dpml.net/merlin/distributions/latest    |
|------------------------------------------------|

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


Mime
View raw message