You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/03/04 22:11:50 UTC
cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/util ContextManager.java
bloritsch 02/03/04 13:11:50
Modified: . build.xml
src/scratchpad/org/apache/avalon/excalibur/event
AbstractQueue.java
src/scratchpad/org/apache/avalon/excalibur/system
ContainerManager.java
src/scratchpad/org/apache/avalon/excalibur/system/test
ContainerProfile.java
src/scratchpad/org/apache/avalon/excalibur/system/util
ContextManager.java
Log:
fix isFull() error
Revision Changes Path
1.110 +3 -1 jakarta-avalon-excalibur/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/build.xml,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -r1.109 -r1.110
--- build.xml 3 Mar 2002 06:56:16 -0000 1.109
+++ build.xml 4 Mar 2002 21:11:50 -0000 1.110
@@ -320,11 +320,13 @@
<!-- All tests in the src/test directory -->
<fileset dir="${test.dir}">
<include name="**/test/**"/>
+ <include name="*Test.java"/>
</fileset>
<!-- All tests in the src/scratchpad directory -->
<fileset dir="${scratchpad.dir}">
<include name="**/test/**"/>
+ <include name="*Test.java"/>
</fileset>
</copy>
@@ -341,7 +343,7 @@
optimize="${build.optimize}"
deprecation="${build.deprecation}"
target="1.2">
- <classpath refid="project.class.path" />
+ <classpath refid="test.class.path" />
</javac>
</target>
1.4 +1 -1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/AbstractQueue.java
Index: AbstractQueue.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/event/AbstractQueue.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractQueue.java 2 Jan 2002 12:03:00 -0000 1.3
+++ AbstractQueue.java 4 Mar 2002 21:11:50 -0000 1.4
@@ -39,7 +39,7 @@
*/
public boolean isFull()
{
- return maxSize() - size() > 0;
+ return (maxSize() < 0) ? false : maxSize() - size() <= 0;
}
/**
1.30 +19 -584 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.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- ContainerManager.java 20 Feb 2002 15:24:22 -0000 1.29
+++ ContainerManager.java 4 Mar 2002 21:11:50 -0000 1.30
@@ -7,20 +7,9 @@
*/
package org.apache.avalon.excalibur.system;
-import org.apache.avalon.framework.CascadingRuntimeException;
-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.util.SystemUtil;
-import org.apache.avalon.excalibur.source.*;
-import org.apache.avalon.excalibur.command.*;
-import org.apache.avalon.excalibur.mpool.*;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.excalibur.system.util.*;
import java.io.File;
@@ -110,588 +99,34 @@
* </table>
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
- * @version CVS $Revision: 1.29 $ $Date: 2002/02/20 15:24:22 $
+ * @version CVS $Revision: 1.30 $ $Date: 2002/03/04 21:11:50 $
*/
-public class ContainerManager implements Disposable
+public interface ContainerManager extends Disposable, Initializable
{
- public static final String CONTEXT_DIRECTORY = Container.CONTEXT_DIRECTORY;
- public static final String WORK_DIRECTORY = Container.WORK_DIRECTORY;
- public static final String CONTAINER_CLASS = "container.class";
- public static final String LOGKIT_CONFIG = "container.loggerConfig";
- public static final String ROLE_CONFIG = "container.roles";
- public static final String THREADS_CPU = "container.threadsPerCPU";
- public static final String THREAD_TIMEOUT = "container.threadTimeout";
- public static final String CONTAINER_CONFIG = "container.configFile";
- public static final String LOG_CATEGORY = "container.logCategory";
-
- 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_configSerializer =
- new DefaultConfigurationSerializer();
-
- private final Logger m_primordialLogger;
- private final Parameters m_initialParameters;
- private final ClassLoader m_contextClassLoader;
- private final File m_contextDirectory;
- private final File m_workDirectory;
- private LoggerManager m_logManager;
- private final PoolManager m_poolManager;
- private final ThreadManager m_threadManager;
- private final CommandManager m_commandManager;
- private ComponentManager m_componentManager;
- private Configuration m_containerConfig;
- private Configuration m_logKitConfig;
- private Configuration m_roleConfig;
- private Context m_rootContext;
- private Context m_containerContext;
- private Object m_containerInstance;
- private ComponentStateValidator m_validator;
- private RoleManager m_roleManager;
-
- /**
- * This constructor creates a new ContainerManager with a LogKitLoggerManager
- * for managing your logging categories. If you want another LoggerManager
- * implementation, then use the constructor with two arguments.
- */
- public ContainerManager( final Parameters initialParameters )
- throws InitializationException
- {
- this( initialParameters, new ConsoleLogger() );
- }
-
- /**
- * This constructor creates a new ContainerManager with a PrimordialLogger
- * defined.
- */
- public ContainerManager( final Parameters initialParameters,
- final Logger primordialLogger )
- throws InitializationException
- {
- this( initialParameters, primordialLogger, null, Thread.currentThread().getContextClassLoader() );
- }
-
- /**
- * Create a ContainerManager with all the information in the Context, and the
- * supplied LoggerManager.
- */
- public ContainerManager( final Parameters initialParameters, final LoggerManager defaultLogManager )
- throws InitializationException
- {
- this( initialParameters, defaultLogManager, Thread.currentThread().getContextClassLoader() );
- }
-
- /**
- * Create a ContainerManager with all the information in the Context, and the
- * supplied LoggerManager.
- */
- public ContainerManager( final Parameters initialParameters,
- final LoggerManager defaultLogManager,
- final ClassLoader rootClassLoader )
- throws InitializationException
- {
- this( initialParameters, new ConsoleLogger(), defaultLogManager, rootClassLoader );
- }
-
- /**
- * Create a ContainerManager with all the information in the Context, and the
- * supplied LoggerManager.
- */
- public ContainerManager( final Parameters initialParameters,
- final Logger primordialLogger,
- final LoggerManager defaultLogManager,
- final ClassLoader rootClassLoader )
- throws InitializationException
- {
- m_primordialLogger = ( null == primordialLogger ) ? new ConsoleLogger() : primordialLogger;
- m_initialParameters = initialParameters;
- m_contextClassLoader = rootClassLoader;
- m_contextDirectory = new File(initialParameters.getParameter( CONTEXT_DIRECTORY, "./" ) );
- m_workDirectory = new File( initialParameters.getParameter( CONTEXT_DIRECTORY, "/tmp" ) );
- m_commandManager = new CommandManager();
- m_threadManager = new TPCThreadManager(
- SystemUtil.numProcessors(),
- initialParameters.getParameterAsInteger( THREADS_CPU, 1 ),
- initialParameters.getParameterAsInteger( THREAD_TIMEOUT, 1000 )
- );
- m_threadManager.register( m_commandManager );
- m_poolManager = new DefaultPoolManager( m_commandManager.getCommandQueue() );
-
- if ( null != defaultLogManager )
- {
- m_logManager = defaultLogManager;
- }
-
- recycleContainer();
- }
+ String CONTEXT_DIRECTORY = Container.CONTEXT_DIRECTORY;
+ String WORK_DIRECTORY = Container.WORK_DIRECTORY;
+ String CONTAINER_CLASS = "container.class";
+ String LOGKIT_CONFIG = "container.loggerConfig";
+ String ROLE_CONFIG = "container.roles";
+ String THREADS_CPU = "container.threadsPerCPU";
+ String THREAD_TIMEOUT = "container.threadTimeout";
+ String CONTAINER_CONFIG = "container.configFile";
+ String LOG_CATEGORY = "container.logCategory";
/**
* Get a reference to your Container. Typically, you would cast this to
* whatever interface you will use to interact with it.
*/
- public Object getContainer()
- {
- return m_containerInstance;
- }
-
- /**
- * 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
- {
- DefaultComponentSelector selector = new DefaultComponentSelector();
- ResourceSourceFactory resource = new ResourceSourceFactory();
- resource.enableLogging( getLogger() );
- selector.put("resource", resource);
-
- manager.put( resource.ROLE + "Selector", selector );
-
- SourceResolverImpl resolver = new SourceResolverImpl();
- resolver.enableLogging( getLogger() );
- resolver.contextualize( getRootContext() );
- resolver.compose( manager );
- manager.put( resolver.ROLE, resolver );
- }
- catch ( Exception e )
- {
- getLogger().warn("Could not set up the initial components", e);
- }
-
- manager.makeReadOnly();
- m_componentManager = manager;
- }
-
- return m_componentManager;
- }
-
- protected void initializeContainer()
- {
- if ( null == m_containerInstance )
- {
- Object instance = null;
- try
- {
- instance = 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(true) );
- }
-
- 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 )
- {
- if ( m_containerInstance instanceof Startable )
- {
- try
- {
- m_validator.checkStopped();
- ( (Startable) m_containerInstance ).stop();
- }
- catch (Exception e)
- {
- if ( getLogger().isWarnEnabled() )
- {
- getLogger().warn("Caught an exception when stopping the Container, continuing with shutdown", e);
- }
- }
- }
-
- if ( m_containerInstance instanceof Disposable )
- {
- m_validator.checkDisposed();
- ( (Disposable) m_containerInstance ).dispose();
- }
-
- m_validator = null;
- m_containerInstance = null;
- }
- }
-
- /**
- * 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();
- }
-
- /**
- * Override this if you have any special needs for the Container's Context.
- * Typically, this will f
- */
- protected Context getRootContext()
- {
- if ( null == m_rootContext )
- {
- DefaultContext context = new DefaultContext();
- context.put( CONTEXT_DIRECTORY, m_contextDirectory );
- context.put( WORK_DIRECTORY, m_workDirectory );
- context.put( LOG_CATEGORY,
- m_initialParameters.getParameter(LOG_CATEGORY, null)
- );
- context.put( Container.CONTEXT_CLASSLOADER, m_contextClassLoader );
- context.put( Container.COMMAND_QUEUE, m_commandManager.getCommandQueue() );
-
- context.makeReadOnly();
- m_rootContext = context;
- }
-
- return m_rootContext;
- }
-
- /**
- * Override this if you have any special needs for the Container's Context.
- * Typically, this will f
- */
- protected Context getContext()
- {
- if ( null == m_containerContext )
- {
- DefaultContext context = new DefaultContext( getRootContext() );
- context.put( Container.LOGGER_MANAGER, getLoggerManager() );
- context.put( Container.ROLE_MANAGER, getRoleManager() );
- context.put( Container.POOL_MANAGER, m_poolManager );
-
- context.makeReadOnly();
- m_containerContext = context;
- }
-
- return m_containerContext;
- }
-
- /**
- * Get the LoggerManager. Will set up a LogKitLoggerManager if none is
- * supplied. This can be overridden if you don't want a LogKitLoggerManager.
- */
- public LoggerManager getLoggerManager()
- {
- if ( null == m_logManager )
- {
- LogKitLoggerManager logManager = new LogKitLoggerManager(
- m_initialParameters.getParameter(LOG_CATEGORY, null)
- );
-
- try
- {
- logManager.contextualize( getRootContext() );
- logManager.configure( getLogKitConfig() );
- }
- catch (Exception e)
- {
- // We cannot log the exception as the logger has not been set up.
- throw new CascadingRuntimeException(
- "Could not completely set up LoggerManager.", e );
- }
-
- m_logManager = logManager;
- }
-
- return m_logManager;
- }
+ Object getContainer();
/**
* Get a reference the default Logger.
*/
- public Logger getLogger()
- {
- return getLogger( false );
- }
+ Logger getLogger();
/**
- * Get a reference the default Logger.
+ * Get a reference to the ContextManager. The ContextManager is used to
+ * set up the initial properties for the system.
*/
- public Logger getLogger(final boolean force)
- {
- if ( !force && m_logManager == null )
- {
- return m_primordialLogger;
- }
-
- return getLoggerManager().getDefaultLogger();
- }
-
- /**
- * Sets up the RoleManager. You may override this method to implement your
- * own logic. This is the RoleManager given to the Container so that the
- * Container can interpret it's Configuration.
- */
- protected RoleManager getRoleManager()
- {
- if ( null == m_roleManager )
- {
- if ( null == m_roleConfig )
- {
- m_roleManager = new ExcaliburRoleManager();
- }
- else
- {
- ExcaliburRoleManager erm = new ExcaliburRoleManager();
- ConfigurableRoleManager crm = new ConfigurableRoleManager( erm );
-
- try
- {
- crm.configure( getRoleConfig() );
- m_roleManager = crm;
- }
- catch ( Exception 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, "" );
-
- if ( "".equals( configFile.trim() ) )
- {
- m_containerConfig = EMPTY_CONFIG;
- }
- else
- {
- SourceResolver resolver = null;
- try
- {
- resolver = (SourceResolver) getComponentManager().lookup(SourceResolver.ROLE);
- Source src = resolver.resolve( configFile );
-
- m_containerConfig = m_configBuilder.build( src.getInputStream() );
-
- resolver.release( src );
- }
- catch (Exception e)
- {
- m_containerConfig = EMPTY_CONFIG;
-
- if ( getLogger().isWarnEnabled() )
- {
- getLogger().warn("Could not read configuration file: " + configFile, e);
- }
- }
- finally
- {
- getComponentManager().release(resolver);
- }
- }
- }
-
- return m_containerConfig;
- }
-
- /**
- * Get the Container Configuration hierarchy.
- */
- protected Configuration getRoleConfig()
- {
- if ( null == m_roleConfig )
- {
- String configFile = m_initialParameters.getParameter( ROLE_CONFIG, "" );
-
- if ( "".equals( configFile.trim() ) )
- {
- m_roleConfig = EMPTY_CONFIG;
- }
- else
- {
- SourceResolver resolver = null;
- try
- {
- resolver = (SourceResolver) getComponentManager().lookup(SourceResolver.ROLE);
- Source src = resolver.resolve( configFile );
-
- m_roleConfig = m_configBuilder.build( src.getInputStream() );
-
- resolver.release( src );
- }
- catch (Exception e)
- {
- m_roleConfig = EMPTY_CONFIG;
-
- if ( getLogger().isWarnEnabled() )
- {
- getLogger().warn("Could not read configuration file: " + configFile, e);
- }
- }
- finally
- {
- getComponentManager().release(resolver);
- }
- }
- }
-
- return m_roleConfig;
- }
-
- /**
- * Get the Container Configuration hierarchy.
- */
- protected Configuration getLogKitConfig()
- {
- if ( null == m_logKitConfig )
- {
- String configFile = m_initialParameters.getParameter( LOGKIT_CONFIG, "" );
-
- if ( "".equals( configFile.trim() ) )
- {
- m_logKitConfig = EMPTY_CONFIG;
- }
- else
- {
- SourceResolver resolver = null;
- try
- {
- resolver = (SourceResolver) getComponentManager().lookup(SourceResolver.ROLE);
- Source src = resolver.resolve( configFile );
-
- m_logKitConfig = m_configBuilder.build( src.getInputStream() );
-
- resolver.release( src );
- }
- catch (Exception e)
- {
- m_logKitConfig = EMPTY_CONFIG;
-
- if ( getLogger().isWarnEnabled() )
- {
- getLogger().warn("Could not read configuration file: " + configFile, e);
- }
- }
- finally
- {
- getComponentManager().release(resolver);
- }
- }
- }
-
- 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;
- }
+ ContextManager getContextManager();
}
1.7 +2 -2 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/test/ContainerProfile.java
Index: ContainerProfile.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/test/ContainerProfile.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ContainerProfile.java 26 Feb 2002 02:06:30 -0000 1.6
+++ ContainerProfile.java 4 Mar 2002 21:11:50 -0000 1.7
@@ -31,7 +31,7 @@
* Used as a basis for the PoolComparisonProfile Tests
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
- * @version $Id: ContainerProfile.java,v 1.6 2002/02/26 02:06:30 leif Exp $
+ * @version $Id: ContainerProfile.java,v 1.7 2002/03/04 21:11:50 bloritsch Exp $
*/
public final class ContainerProfile
extends TestCase
@@ -102,7 +102,7 @@
params.setParameter( ContainerManager.LOGKIT_CONFIG, "resource://org/apache/avalon/excalibur/system/test/ContainerProfile.xlog" );
params.setParameter( ContainerManager.THREADS_CPU, "2" );
params.makeReadOnly();
- ContainerManager cm = new ContainerManager( params, new NullLogger() );
+ ContainerManager cm = new RootContainerManager( params, new NullLogger() );
TestContainer container = (TestContainer) cm.getContainer();
assertNotNull(container);
long cmStop = System.currentTimeMillis();
1.4 +6 -3 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/util/ContextManager.java
Index: ContextManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/util/ContextManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ContextManager.java 26 Feb 2002 02:06:30 -0000 1.3
+++ ContextManager.java 4 Mar 2002 21:11:50 -0000 1.4
@@ -26,7 +26,7 @@
* will be possible on it.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
- * @version CVS $Revision: 1.3 $ $Date: 2002/02/26 02:06:30 $
+ * @version CVS $Revision: 1.4 $ $Date: 2002/03/04 21:11:50 $
* @since 4.1
*/
public class ContextManager
@@ -55,6 +55,11 @@
m_currContext = new DefaultContext( m_rootContext );
}
+ public void makeReadOnly()
+ {
+ m_currContext.makeReadOnly();
+ }
+
public Context getContextInstance()
throws ContextException
{
@@ -68,8 +73,6 @@
{
m_currContext.get( Container.LOGGER_MANAGER );
}
-
- m_currContext.makeReadOnly();
return m_currContext;
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>