You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by pr...@apache.org on 2002/06/28 06:50:17 UTC
cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress AbstractContainer.java DefaultContainerManager.java
proyal 2002/06/27 21:50:17
Modified: fortress/src/java/org/apache/excalibur/fortress
AbstractContainer.java DefaultContainerManager.java
Log:
AbstractContainer must implement both Composable
and Serviceable to be a valid replacement for the
ECM. Without both interfaces, one cannot pass
a parent ComponentManager in and have it work.
Changes made:
* AbstractContainer is both Composable and Serviceable
It will complain if you set both, but it will work
with either a ComponentManager or a ServiceManager as
its parent
* DefaultContainerManager now throws exceptions rather
than just logging them. This will eliminate strange
errors in your code where you have to go back and check
the logs
* ComponentStateValidator has been temporarily removed
from DefaultContainerManager as it is unable to deal with
a container that is both Composable and Serviceable.
This was the best I could do to keep backwards-compat.
Revision Changes Path
1.43 +34 -9 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java
Index: AbstractContainer.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- AbstractContainer.java 25 Jun 2002 13:39:37 -0000 1.42
+++ AbstractContainer.java 28 Jun 2002 04:50:17 -0000 1.43
@@ -54,10 +54,11 @@
*/
public abstract class AbstractContainer
extends AbstractLogEnabled
- implements Contextualizable, Serviceable, Configurable, Initializable, Disposable, Container
+ implements Contextualizable, Serviceable, Composable, Configurable, Initializable, Disposable, Container
{
protected Context m_context;
- private ServiceManager m_manager;
+ private ServiceManager m_serviceManager;
+ private ComponentManager m_componentManager;
protected LoggerManager m_logManager;
protected PoolManager m_poolManager;
protected Queue m_commandQueue;
@@ -282,8 +283,8 @@
handler = (ComponentHandler)constructor.newInstance( new Object[]{
klass,
configuration,
- new FortressComponentManager( this, m_manager ),
- new FortressServiceManager( this, m_manager ),
+ getComponentManager(),
+ getServiceManager(),
m_context
} );
}
@@ -388,13 +389,33 @@
}
/**
- * Root ComponentLocator. The Container may choose to have it's ComponentLocator
+ * Root ServiceManager. The Container may choose to have it's ServiceManager
* delegate to the root manager, or it may choose to be entirely self contained.
*/
public void service( ServiceManager manager )
throws ServiceException
{
- m_manager = manager;
+ if( m_componentManager != null && manager != null )
+ {
+ throw new IllegalStateException( "ComponentManager has already been set, cannot use both simultaneously" );
+ }
+
+ m_serviceManager = manager;
+ }
+
+ /**
+ * Root ComponentManager. The Container may choose to have it's ComponentManager
+ * delegate to the root manager, or it may choose to be entirely self contained.
+ */
+ public void compose( ComponentManager componentManager )
+ throws ComponentException
+ {
+ if( m_serviceManager != null && componentManager != null )
+ {
+ throw new IllegalStateException( "ServiceManager has already been set, cannot use both simultaneously" );
+ }
+
+ m_componentManager = componentManager;
}
/**
@@ -485,7 +506,9 @@
*/
protected final ComponentManager getComponentManager()
{
- return new FortressComponentManager( this, m_manager );
+ return m_componentManager == null ?
+ new FortressComponentManager( this, m_serviceManager ) :
+ new FortressComponentManager( this, m_componentManager );
}
/**
@@ -496,7 +519,9 @@
*/
protected final ServiceManager getServiceManager()
{
- return new FortressServiceManager( this, m_manager );
+ return m_serviceManager == null ?
+ new FortressServiceManager( this, m_componentManager ) :
+ new FortressServiceManager( this, m_serviceManager );
}
/**
1.12 +42 -27 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/DefaultContainerManager.java
Index: DefaultContainerManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/DefaultContainerManager.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DefaultContainerManager.java 27 Jun 2002 16:48:36 -0000 1.11
+++ DefaultContainerManager.java 28 Jun 2002 04:50:17 -0000 1.12
@@ -50,7 +50,7 @@
private final Context containerContext;
private Logger logger;
private Object containerInstance;
- private ComponentStateValidator validator;
+// private ComponentStateValidator validator;
public DefaultContainerManager( ContextManager contextManager )
{
@@ -101,12 +101,12 @@
/**
* Initialize the ContainerManager
*/
- public void initialize()
+ public void initialize() throws Exception
{
initializeContainer();
}
- protected void initializeContainer()
+ protected void initializeContainer() throws InitializationException
{
if( null == containerInstance )
{
@@ -118,72 +118,87 @@
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;
+
+ throw new InitializationException( "Cannot set up container. Unable to create container class", e );
}
- validator = new ComponentStateValidator( instance );
+// validator = new ComponentStateValidator( instance );
try
{
if( instance instanceof LogEnabled )
{
- validator.checkLogEnabled();
+// validator.checkLogEnabled();
( (LogEnabled)instance ).enableLogging( logger );
}
if( instance instanceof Contextualizable )
{
- validator.checkContextualized();
+// validator.checkContextualized();
( (Contextualizable)instance ).contextualize( containerContext );
}
if( instance instanceof Composable )
{
- validator.checkComposed();
- ( (Composable)instance ).compose( (ComponentManager)initParameters.get( COMPONENT_MANAGER ) );
+// validator.checkComposed();
+
+ try
+ {
+ final ComponentManager manager = (ComponentManager)initParameters.get( COMPONENT_MANAGER );
+
+ ( (Composable)instance ).compose( manager );
+ }
+ catch( ContextException e )
+ {
+ //Ignore, it may not have a parent component manager
+ }
}
if( instance instanceof Serviceable )
{
- validator.checkServiced();
- ( (Serviceable)instance ).service( (ServiceManager)initParameters.get( SERVICE_MANAGER ) );
+// validator.checkServiced();
+
+ try
+ {
+ final ServiceManager manager = (ServiceManager)initParameters.get( SERVICE_MANAGER );
+
+ ( (Serviceable)instance ).service( manager );
+ }
+ catch( ContextException e )
+ {
+ //Ignore, it may not have a parent service manager
+ }
}
if( instance instanceof Configurable )
{
- validator.checkConfigured();
+// validator.checkConfigured();
( (Configurable)instance ).configure( (Configuration)initParameters.get( CONFIGURATION ) );
}
if( instance instanceof Parameterizable )
{
- validator.checkParameterized();
+// validator.checkParameterized();
( (Parameterizable)instance ).parameterize( (Parameters)initParameters.get( PARAMETERS ) );
}
if( instance instanceof Initializable )
{
- validator.checkInitialized();
+// validator.checkInitialized();
( (Initializable)instance ).initialize();
}
if( instance instanceof Startable )
{
- validator.checkStarted();
+// 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 );
- }
+
+ throw new InitializationException("Cannot set up container. Startup lifecycle failure", e );
}
containerInstance = instance;
@@ -198,7 +213,7 @@
{
try
{
- validator.checkStopped();
+// validator.checkStopped();
( (Startable)containerInstance ).stop();
}
catch( Exception e )
@@ -212,11 +227,11 @@
if( containerInstance instanceof Disposable )
{
- validator.checkDisposed();
+// validator.checkDisposed();
( (Disposable)containerInstance ).dispose();
}
- validator = null;
+// validator = null;
containerInstance = null;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>