bloritsch 02/01/25 13:54:02
Modified: src/scratchpad/org/apache/avalon/excalibur/system
ContainerManager.java
Log:
ContainerManager almost usable
Revision Changes Path
1.9 +165 -82
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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ContainerManager.java 25 Jan 2002 21:12:56 -0000 1.8
+++ ContainerManager.java 25 Jan 2002 21:54:02 -0000 1.9
@@ -7,29 +7,16 @@
*/
package org.apache.avalon.excalibur.system;
-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.framework.activity.Suspendable;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.DefaultContext;
-import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.DefaultComponentManager;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import
org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.parameters.Parameterizable;
-import org.apache.avalon.framework.logger.LogEnabled;
-import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.activity.*;
+import org.apache.avalon.framework.context.*;
+import org.apache.avalon.framework.component.*;
+import org.apache.avalon.framework.configuration.*;
+import org.apache.avalon.framework.parameters.*;
+import org.apache.avalon.framework.logger.*;
import org.apache.avalon.excalibur.logger.LoggerManager;
import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
import org.apache.avalon.excalibur.util.ComponentStateValidator;
+import org.apache.avalon.excalibur.source.*;
import java.io.File;
@@ -135,7 +122,7 @@
* </table>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.8 $ $Date: 2002/01/25 21:12:56 $
+ * @version CVS $Revision: 1.9 $ $Date: 2002/01/25 21:54:02 $
*/
public class ContainerManager
{
@@ -150,6 +137,20 @@
public static final String LOG_CATEGORY = "container.logCategory";
public static final String CPU_COUNT = "os.arch.cpus";
+ private static final Configuration EMPTY_CONFIG;
+
+ static
+ {
+ DefaultConfiguration config = new DefaultConfiguration("", "", "",
"");
+ config.makeReadOnly();
+ EMPTY_CONFIG = config;
+ }
+
+ private final DefaultConfigurationBuilder m_configBuilder =
+ new
DefaultConfigurationBuilder();
+ private final DefaultConfigurationSerializer m_configSerialzer =
+ new
DefaultConfigurationSerializer();
+
private final Parameters m_initialParameters;
private final ClassLoader m_contextClassLoader;
private final File m_contextDirectory;
@@ -159,9 +160,8 @@
// private final ThreadManager m_threadManager;
// private final CommandManager m_commandManager;
private ComponentManager m_componentManager;
- private Logger m_defaultLogger;
private Configuration m_containerConfig;
- private Configuration m_LogKitConfig;
+ private Configuration m_logKitConfig;
private Configuration m_roleConfig;
private Context m_containerContext;
private Container m_containerInstance;
@@ -203,19 +203,11 @@
m_contextDirectory = new File(initialParameters.getParameter(
CONTEXT_DIRECTORY, "./" ) );
m_workDirectory = new File( initialParameters.getParameter(
CONTEXT_DIRECTORY, "/tmp" ) );
- m_componentManager = setupComponentManager();
-
- if ( null == defaultLogManager )
- {
- m_logManager = setupLoggerManager();
- }
- else
+ if ( null != defaultLogManager )
{
m_logManager = defaultLogManager;
}
- m_defaultLogger = m_logManager.getDefaultLogger();
-
recycleContainer();
}
@@ -230,25 +222,40 @@
}
/**
- * Get a reference to the LoggerManager used by the ContainerManager.
- */
- protected LoggerManager getLoggerManager()
- {
- if ( m_logManager == null )
- {
- m_logManager = setupLoggerManager();
- }
-
- return m_logManager;
- }
-
- /**
* Get a reference to the initial ComponentManager used by the
ContainerManager
* to hold the Components used for parsing the config files and setting
up the
* environment.
*/
public ComponentManager getComponentManager()
{
+ if ( null == m_componentManager )
+ {
+ DefaultComponentManager manager = new DefaultComponentManager();
+
+ try
+ {
+ SourceResolverImpl resolver = new SourceResolverImpl();
+ resolver.enableLogging( getLogger() );
+ resolver.contextualize( getContext() );
+ resolver.compose( manager );
+ manager.put( resolver.ROLE, resolver );
+
+ DefaultComponentSelector selector = new
DefaultComponentSelector();
+ ResourceSourceFactory resource = new ResourceSourceFactory();
+ resource.enableLogging( getLogger() );
+ selector.put("resource", resource);
+
+ manager.put( resource.ROLE + "Selector", selector );
+ }
+ catch ( Exception e )
+ {
+ getLogger().warn("Could not set up the initial components",
e);
+ }
+
+ manager.makeReadOnly();
+ m_componentManager = manager;
+ }
+
return m_componentManager;
}
@@ -269,9 +276,9 @@
}
catch (Exception e)
{
- if ( m_defaultLogger.isWarnEnabled() )
+ if ( getLogger().isWarnEnabled() )
{
- m_defaultLogger.warn("Caught an exception when
stopping the Container, continuing with shutdown", e);
+ getLogger().warn("Caught an exception when stopping
the Container, continuing with shutdown", e);
}
}
}
@@ -294,9 +301,9 @@
catch ( Exception e )
{
instance = null;
- if ( m_defaultLogger.isFatalErrorEnabled() )
+ if ( getLogger().isFatalErrorEnabled() )
{
- m_defaultLogger.fatalError( "Cannot set up the Container,
this is an error I cannot recover from.", e );
+ getLogger().fatalError( "Cannot set up the Container, this
is an error I cannot recover from.", e );
}
return;
}
@@ -305,27 +312,27 @@
{
if ( instance instanceof Contextualizable )
{
- ( (Contextualizable) instance ).contextualize(
setupContext() );
+ ( (Contextualizable) instance ).contextualize( getContext()
);
}
if ( instance instanceof LogEnabled )
{
- ( (LogEnabled) instance ).enableLogging( m_defaultLogger );
+ ( (LogEnabled) instance ).enableLogging( getLogger() );
}
if ( instance instanceof Composable )
{
- ( (Composable) instance ).compose( m_componentManager );
+ ( (Composable) instance ).compose( getComponentManager() );
}
if ( instance instanceof Configurable )
{
- ( (Configurable) instance ).configure( m_containerConfig );
+ ( (Configurable) instance ).configure( getContainerConfig()
);
}
if ( instance instanceof Parameterizable )
{
- ( (Parameterizable) instance ).parameterize(
Parameters.fromConfiguration( m_containerConfig ) );
+ ( (Parameterizable) instance ).parameterize(
Parameters.fromConfiguration( getContainerConfig() ) );
}
if ( instance instanceof Initializable )
@@ -341,9 +348,9 @@
catch ( Exception e )
{
instance = null;
- if ( m_defaultLogger.isFatalErrorEnabled() )
+ if ( getLogger().isFatalErrorEnabled() )
{
- m_defaultLogger.fatalError( "Cannot set up the Container,
this is an error I cannot recover from.", e );
+ getLogger().fatalError( "Cannot set up the Container, this
is an error I cannot recover from.", e );
}
}
@@ -354,7 +361,7 @@
* Override this if you have any special needs for the Container's
Context.
* Typically, this will f
*/
- protected Context setupContext()
+ protected Context getContext()
{
if ( null == m_containerContext )
{
@@ -368,7 +375,7 @@
m_initialParameters.getParameter(LOG_CATEGORY, null)
);
context.put( Container.CONTEXT_CLASSLOADER, m_contextClassLoader
);
- context.put( Container.ROLE_MANAGER, setupRoleManager() );
+ context.put( Container.ROLE_MANAGER, getRoleManager() );
context.makeReadOnly();
m_containerContext = context;
@@ -378,41 +385,39 @@
}
/**
- * Set up a LogKitLoggerManager if none is supplied. This can be
overridden
- * if you don't want a LogKitLoggerManager.
+ * Get the LoggerManager. Will set up a LogKitLoggerManager if none is
+ * supplied. This can be overridden if you don't want a
LogKitLoggerManager.
*/
- protected LoggerManager setupLoggerManager()
+ public LoggerManager getLoggerManager()
{
if ( null == m_logManager )
{
- m_logManager = new LogKitLoggerManager(
+ LogKitLoggerManager logManager = new LogKitLoggerManager(
m_initialParameters.getParameter(LOG_CATEGORY, null)
);
+
+ try
+ {
+ logManager.contextualize( getContext() );
+ logManager.configure( getLogKitConfig() );
+ }
+ catch (Exception e)
+ {
+ getLogger().warn("Could not completely set up
LogKitLoggerManager", e);
+ }
+
+ m_logManager = logManager;
}
return m_logManager;
}
/**
- * Sets up the ContainerManager's ComponentManager. This
ComponentManager
- * will have all the components necessary to read configuration files and
- * manage the configuration resources. It will also be passed to the
- * Container.
+ * Get a reference the default Logger.
*/
- protected ComponentManager setupComponentManager()
+ public Logger getLogger()
{
- if ( null == m_componentManager )
- {
- DefaultComponentManager manager = new DefaultComponentManager();
- String parser = m_initialParameters.getParameter(XML_PARSER,
"org.apache.avalon.excalibur.xml.JaxpParser");
- //manager.put();
-
- SourceResolver
-
- m_componentManager = manager;
- }
-
- return m_componentManager;
+ return getLoggerManager().getDefaultLogger();
}
/**
@@ -420,7 +425,7 @@
* own logic. This is the RoleManager given to the Container so that the
* Container can interpret it's Configuration.
*/
- protected RoleManager setupRoleManager()
+ protected RoleManager getRoleManager()
{
if ( null == m_roleManager )
{
@@ -435,17 +440,95 @@
try
{
- crm.configure( m_roleConfig );
+ crm.configure( getRoleConfig() );
m_roleManager = crm;
}
catch ( Exception e )
{
- this.m_defaultLogger.warn("There was a problem with the
role configuration, defaulting to ExcaliburComponentManager.", e);
+ getLogger().warn("There was a problem with the role
configuration, defaulting to ExcaliburComponentManager.", e);
m_roleManager = erm;
}
}
}
return m_roleManager;
+ }
+
+ /**
+ * Get the Container Configuration hierarchy.
+ */
+ protected Configuration getContainerConfig()
+ {
+ if ( null == m_containerConfig )
+ {
+ String configFile = m_initialParameters.getParameter(
CONTAINER_CONFIG, "" );
+
+ try
+ {
+ m_containerConfig = m_configBuilder.buildFromFile(
configFile );
+ }
+ catch (Exception e)
+ {
+ if ( getLogger().isWarnEnabled() )
+ {
+ getLogger().warn("Could not read configuration file: " +
configFile, e);
+ m_containerConfig = EMPTY_CONFIG;
+ }
+ }
+ }
+
+ return m_containerConfig;
+ }
+
+ /**
+ * Get the Container Configuration hierarchy.
+ */
+ protected Configuration getRoleConfig()
+ {
+ if ( null == m_containerConfig )
+ {
+ String configFile = m_initialParameters.getParameter(
ROLE_CONFIG, "" );
+
+ try
+ {
+ m_roleConfig = m_configBuilder.buildFromFile( configFile );
+ }
+ catch (Exception e)
+ {
+ if ( getLogger().isWarnEnabled() )
+ {
+ getLogger().warn("Could not read configuration file: " +
configFile, e);
+ m_roleConfig = EMPTY_CONFIG;
+ }
+ }
+ }
+
+ return m_roleConfig;
+ }
+
+ /**
+ * Get the Container Configuration hierarchy.
+ */
+ protected Configuration getLogKitConfig()
+ {
+ if ( null == m_containerConfig )
+ {
+ String configFile = m_initialParameters.getParameter(
LOGKIT_CONFIG, "" );
+
+ try
+ {
+ m_logKitConfig = m_configBuilder.buildFromFile( configFile );
+ }
+ catch (Exception e)
+ {
+ if ( getLogger().isWarnEnabled() )
+ {
+ getLogger().warn("Could not read configuration file: " +
configFile, e);
+ m_logKitConfig = EMPTY_CONFIG;
+ }
+ }
+ }
+
+ return m_logKitConfig;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>