Return-Path: Delivered-To: apmail-jakarta-avalon-cvs-archive@apache.org Received: (qmail 80851 invoked from network); 5 Feb 2002 22:19:09 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 5 Feb 2002 22:19:09 -0000 Received: (qmail 11764 invoked by uid 97); 5 Feb 2002 22:19:15 -0000 Delivered-To: qmlist-jakarta-archive-avalon-cvs@jakarta.apache.org Received: (qmail 11731 invoked by uid 97); 5 Feb 2002 22:19:14 -0000 Mailing-List: contact avalon-cvs-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list avalon-cvs@jakarta.apache.org Received: (qmail 11720 invoked by uid 97); 5 Feb 2002 22:19:14 -0000 Date: 5 Feb 2002 22:19:06 -0000 Message-ID: <20020205221906.23186.qmail@icarus.apache.org> From: bloritsch@apache.org To: jakarta-avalon-excalibur-cvs@apache.org Subject: cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system ContainerManager.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N bloritsch 02/02/05 14:19:06 Modified: src/scratchpad/org/apache/avalon/excalibur/command TPCThreadManager.java src/scratchpad/org/apache/avalon/excalibur/system ContainerManager.java Log: provide hook for shutdown or disposal of system Revision Changes Path 1.5 +19 -7 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/command/TPCThreadManager.java Index: TPCThreadManager.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/command/TPCThreadManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- TPCThreadManager.java 5 Feb 2002 18:11:51 -0000 1.4 +++ TPCThreadManager.java 5 Feb 2002 22:19:06 -0000 1.5 @@ -7,6 +7,7 @@ */ package org.apache.avalon.excalibur.command; +import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.logger.NullLogger; import org.apache.avalon.excalibur.concurrent.Mutex; @@ -27,14 +28,14 @@ * * @author Berin Loritsch */ -public final class TPCThreadManager implements Runnable, ThreadManager +public final class TPCThreadManager implements Runnable, ThreadManager, Disposable { - private final ThreadPool m_threadPool; - private final Mutex m_mutex = new Mutex(); - private final HashMap m_pipelines = new HashMap(); - private ThreadControl m_threadControl; - private boolean m_done = false; - private final long m_sleepTime; + private final ThreadPool m_threadPool; + private final Mutex m_mutex = new Mutex(); + private final HashMap m_pipelines = new HashMap(); + private ThreadControl m_threadControl; + private boolean m_done = false; + private final long m_sleepTime; /** * The default constructor assumes there is a system property named "os.arch.cpus" @@ -167,6 +168,17 @@ { m_mutex.release(); } + } + + public final void dispose() + { + deregisterAll(); + if ( m_threadPool instanceof Disposable ) + { + ( (Disposable) m_threadPool ).dispose(); + } + + m_threadControl = null; } public void run() 1.20 +129 -73 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ContainerManager.java Index: ContainerManager.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ContainerManager.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- ContainerManager.java 5 Feb 2002 20:38:17 -0000 1.19 +++ ContainerManager.java 5 Feb 2002 22:19:06 -0000 1.20 @@ -116,9 +116,9 @@ * * * @author Berin Loritsch - * @version CVS $Revision: 1.19 $ $Date: 2002/02/05 20:38:17 $ + * @version CVS $Revision: 1.20 $ $Date: 2002/02/05 22:19:06 $ */ -public class ContainerManager +public class ContainerManager implements Disposable { public static final String CONTEXT_DIRECTORY = Container.CONTEXT_DIRECTORY; public static final String WORK_DIRECTORY = Container.WORK_DIRECTORY; @@ -141,7 +141,7 @@ private final DefaultConfigurationBuilder m_configBuilder = new DefaultConfigurationBuilder(); - private final DefaultConfigurationSerializer m_configSerialzer = + private final DefaultConfigurationSerializer m_configSerializer = new DefaultConfigurationSerializer(); private final Parameters m_initialParameters; @@ -257,12 +257,87 @@ return m_componentManager; } - /** - * Override this if you have any special needs for the container (such as - * wanting to use your own class). - */ - protected void recycleContainer() - throws InitializationException + protected void initializeContainer() + { + if ( null == m_containerInstance ) + { + Container instance = null; + try + { + instance = (Container) m_contextClassLoader + .loadClass( m_initialParameters.getParameter( CONTAINER_CLASS ) ) + .newInstance(); + } + catch ( Exception e ) + { + instance = null; + if ( getLogger().isFatalErrorEnabled() ) + { + getLogger().fatalError( "Cannot set up the Container, this is an error I cannot recover from.", e ); + } + return; + } + + m_validator = new ComponentStateValidator( instance ); + + try + { + if ( instance instanceof LogEnabled ) + { + m_validator.checkLogEnabled(); + ( (LogEnabled) instance ).enableLogging( getLogger() ); + } + + if ( instance instanceof Contextualizable ) + { + m_validator.checkContextualized(); + ( (Contextualizable) instance ).contextualize( getContext() ); + } + + if ( instance instanceof Composable ) + { + m_validator.checkComposed(); + ( (Composable) instance ).compose( getComponentManager() ); + } + + if ( instance instanceof Configurable ) + { + m_validator.checkConfigured(); + ( (Configurable) instance ).configure( getContainerConfig() ); + } + + if ( instance instanceof Parameterizable ) + { + m_validator.checkParameterized(); + ( (Parameterizable) instance ).parameterize( Parameters.fromConfiguration( getContainerConfig() ) ); + } + + if ( instance instanceof Initializable ) + { + m_validator.checkInitialized(); + ( (Initializable) instance ).initialize(); + } + + if ( instance instanceof Startable ) + { + m_validator.checkStarted(); + ( (Startable) instance ).start(); + } + } + catch ( Exception e ) + { + instance = null; + if ( getLogger().isFatalErrorEnabled() ) + { + getLogger().fatalError( "Cannot set up the Container, this is an error I cannot recover from.", e ); + } + } + + m_containerInstance = instance; + } + } + + protected void disposeContainer() { if ( null != m_containerInstance ) { @@ -270,6 +345,7 @@ { try { + m_validator.checkStopped(); ( (Startable) m_containerInstance ).stop(); } catch (Exception e) @@ -283,76 +359,24 @@ if ( m_containerInstance instanceof Disposable ) { + m_validator.checkDisposed(); ( (Disposable) m_containerInstance ).dispose(); } + m_validator = null; m_containerInstance = null; } + } - Container instance = null; - try - { - instance = (Container) m_contextClassLoader - .loadClass( m_initialParameters.getParameter( CONTAINER_CLASS ) ) - .newInstance(); - } - catch ( Exception e ) - { - instance = null; - if ( getLogger().isFatalErrorEnabled() ) - { - getLogger().fatalError( "Cannot set up the Container, this is an error I cannot recover from.", e ); - } - return; - } - - try - { - if ( instance instanceof LogEnabled ) - { - ( (LogEnabled) instance ).enableLogging( getLogger() ); - } - - if ( instance instanceof Contextualizable ) - { - ( (Contextualizable) instance ).contextualize( getContext() ); - } - - if ( instance instanceof Composable ) - { - ( (Composable) instance ).compose( getComponentManager() ); - } - - if ( instance instanceof Configurable ) - { - ( (Configurable) instance ).configure( getContainerConfig() ); - } - - if ( instance instanceof Parameterizable ) - { - ( (Parameterizable) instance ).parameterize( Parameters.fromConfiguration( getContainerConfig() ) ); - } - - if ( instance instanceof Initializable ) - { - ( (Initializable) instance ).initialize(); - } - - if ( instance instanceof Startable ) - { - ( (Startable) instance ).start(); - } - } - catch ( Exception e ) - { - instance = null; - if ( getLogger().isFatalErrorEnabled() ) - { - getLogger().fatalError( "Cannot set up the Container, this is an error I cannot recover from.", e ); - } - } - - m_containerInstance = instance; + /** + * Override this if you have any special needs for the container (such as + * wanting to use your own class). + */ + private final void recycleContainer() + throws InitializationException + { + disposeContainer(); + initializeContainer(); } /** @@ -579,5 +603,37 @@ } return m_logKitConfig; + } + + public void dispose() + { + disposeContainer(); + + if ( m_threadManager instanceof Disposable ) + { + ( (Disposable) m_threadManager ).dispose(); + } + + if ( m_logManager instanceof Disposable ) + { + ( (Disposable) m_logManager ).dispose(); + } + + if ( m_roleManager instanceof Disposable ) + { + ( (Disposable) m_roleManager ).dispose(); + } + + if ( m_poolManager instanceof Disposable ) + { + ( (Disposable) m_poolManager ).dispose(); + } + + m_logManager = null; + m_componentManager = null; + m_containerConfig = null; + m_containerContext = null; + m_logKitConfig = null; + m_rootContext = null; } } -- To unsubscribe, e-mail: For additional commands, e-mail: