mcconnell 2002/12/20 21:18:22 Modified: merlin/src/java/org/apache/avalon/merlin/container DefaultContainer.java merlin/src/java/org/apache/avalon/merlin/kernel DefaultKernel.java Log: Improvements to the handling of components during shutdown and disposal phases. Revision Changes Path 1.7 +74 -13 avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/container/DefaultContainer.java Index: DefaultContainer.java =================================================================== RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/container/DefaultContainer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- DefaultContainer.java 21 Dec 2002 03:30:24 -0000 1.6 +++ DefaultContainer.java 21 Dec 2002 05:18:22 -0000 1.7 @@ -72,6 +72,7 @@ import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.activity.Startable; import org.apache.avalon.merlin.container.ContainerDescriptor; import org.apache.avalon.merlin.service.Registry; import org.apache.avalon.meta.model.Profile; @@ -269,7 +270,7 @@ while( iterator.hasNext() ) { Appliance appliance = (Appliance) iterator.next(); - m_engine.assemble( appliance ); + appliance.assemble(); } } @@ -390,16 +391,20 @@ Object object = m_componentMap.get( appliance ); if( object != null ) { - if( getLogger().isDebugEnabled() ) + if( object instanceof Startable ) { - final String message = - "stopping: " + appliance; - getLogger().debug( message ); + if( getLogger().isDebugEnabled() ) + { + final String message = + "stopping: " + appliance; + getLogger().debug( message ); + } + ((Startable)object).stop(); + } + else + { + appliance.release( object ); } - - m_componentMap.remove( appliance ); - appliance.release( object ); - appliance.terminate(); } } } @@ -418,9 +423,6 @@ try { container.shutdown(); - m_containerMap.remove( appliance ); - appliance.release( container ); - appliance.terminate(); } catch( Throwable e ) { @@ -442,6 +444,10 @@ { getLogger().debug( "disposal" ); } + + disposeContainers(); + disposeComponents(); + m_engine = null; m_descriptor = null; m_componentMap.clear(); @@ -454,5 +460,60 @@ m_containers = null; m_partition = null; m_path = null; + } + + /** + * Shutdown all subsidiary containers and all components in this container. + * @exception Exception if a shutdown error occurs + */ + protected void disposeComponents() + { + Iterator iterator = m_components.iterator(); + while( iterator.hasNext() ) + { + Appliance appliance = (Appliance) iterator.next(); + Object object = m_componentMap.get( appliance ); + if( object != null ) + { + if( getLogger().isDebugEnabled() ) + { + final String message = + "disposing of: " + appliance; + getLogger().debug( message ); + } + + m_componentMap.remove( appliance ); + appliance.release( object ); + appliance.terminate(); + } + } + } + + /** + * Shutdown the containers in this container. + * @exception Exception if a startup error occurs + */ + protected void disposeContainers() + { + Iterator iterator = m_containers.iterator(); + while( iterator.hasNext() ) + { + Appliance appliance = (Appliance) iterator.next(); + Container container = (Container) m_containerMap.get( appliance ); + try + { + m_containerMap.remove( appliance ); + appliance.release( container ); + appliance.terminate(); + } + catch( Throwable e ) + { + final String error = + "Could not shutdown a subsidiary container: " + + appliance.getName() + + " in container: " + this; + getLogger().warn( error, e ); + } + } } } 1.15 +23 -5 avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.java Index: DefaultKernel.java =================================================================== RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- DefaultKernel.java 20 Dec 2002 11:58:00 -0000 1.14 +++ DefaultKernel.java 21 Dec 2002 05:18:22 -0000 1.15 @@ -350,7 +350,7 @@ Appliance appliance = block.getAppliance(); try { - m_engine.assemble( appliance ); + appliance.assemble(); Container container = (Container)appliance.access(); m_containers.put( block, container ); } @@ -453,10 +453,7 @@ Container container = (Container) m_containers.get( block ); if( container != null ) { - m_containers.remove( block ); container.shutdown(); - block.getAppliance().release( container ); - block.getAppliance().terminate(); } } } @@ -470,6 +467,27 @@ */ public void dispose() { + if( getLogger() != null ) + { + if( getLogger().isInfoEnabled() ) + { + getLogger().info( "commencing disposal phase" ); + } + } + + Iterator iterator = m_blocks.iterator(); + while( iterator.hasNext() ) + { + Block block = (Block) iterator.next(); + Container container = (Container) m_containers.get( block ); + if( container != null ) + { + m_containers.remove( block ); + block.getAppliance().release( container ); + block.getAppliance().terminate(); + } + } + if( getLogger() != null ) { if( getLogger().isInfoEnabled() )
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>