org.apache.avalon.fortress.util
Class ContextManager

java.lang.Object
  extended byorg.apache.avalon.fortress.util.ContextManager
All Implemented Interfaces:
ContainerConstants, ContainerManagerConstants, ContextManagerConstants, Disposable, Initializable

public class ContextManager
extends java.lang.Object
implements ContextManagerConstants, Initializable, Disposable

You can get two different contexts from the ContextManager: the container context (m_childContext) and the container manager context (m_containerManagerContext)

You can get two different contexts from the ContextManager: the child context and the impl manager context. The former contains all managers, such as the pool manager etc. necessary for a child impl to create additional child containers. The impl manager context contains all of the child context, but also initialization parameters for the impl, such as a Configuration object, a ComponentLocator, etc., that the impl wants, but does not want to pass on to its children.

The container manager context is used to provide the container manager with all the data needed to initialize the container.

The container context is passed directly to the container.

The ContextManager will sometimes create new components, such as a service manager, a pool manager, etc. It will manage these components and dispose of them properly when it itself is disposed .

Since:
4.1
Version:
CVS $Revision: 1.55 $ $Date: 2004/04/05 12:05:38 $
Author:
Avalon Development Team

Field Summary
protected static Configuration EMPTY_CONFIG
           
protected  DefaultContext m_childContext
          The context of the new impl.
protected  DefaultContext m_containerManagerContext
          Container manager's context.
protected  SourceResolver m_defaultSourceResolver
          Source resolver used to read-in the configurations.
protected  InstrumentManager m_instrumentManager
          The InstrumentManager to be used by the container.
protected  Logger m_logger
           
protected  LoggerManager m_loggerManager
          The logger manager in use.
protected  MetaInfoManager m_metaInfoManager
          The MetaInfoManager to be used by the container.
protected  org.d_haven.mpool.PoolManager m_poolManager
          The PoolManager to be used by the container.
protected  Logger m_primordialLogger
           
protected  Context m_rootContext
          The root context.
protected  org.d_haven.event.Sink m_sink
          The Sink in use.
protected  org.d_haven.event.command.ThreadManager m_threadManager
          The ThreadManager to be used by the container.
 
Fields inherited from interface org.apache.avalon.fortress.util.ContextManagerConstants
CONFIGURATION_URI, INSTRUMENT_MANAGER_CONFIGURATION, INSTRUMENT_MANAGER_CONFIGURATION_URI, LOG_CATEGORY, LOGGER_MANAGER_CONFIGURATION, LOGGER_MANAGER_CONFIGURATION_URI, ROLE_MANAGER_CLASS, ROLE_MANAGER_CONFIGURATION, ROLE_MANAGER_CONFIGURATION_URI
 
Fields inherited from interface org.apache.avalon.fortress.ContainerManagerConstants
COMMAND_FAILURE_HANDLER_CLASS, CONFIGURATION, CONTAINER_CLASS, LOGGER, PARAMETERS, SERVICE_MANAGER
 
Fields inherited from interface org.apache.avalon.fortress.ContainerConstants
CONTEXT_DIRECTORY, THREAD_TIMEOUT, THREADS_CPU, WORK_DIRECTORY
 
Constructor Summary
ContextManager(Context rootContext, Logger logger)
          Create a new ContextManager.
 
Method Summary
protected  void assumeOwnership(java.lang.Object object)
          Method to assume ownership of one of the managers the ContextManager created.
protected  void copyEntry(java.lang.String key)
          Copies the specified entry from the rootContext to the containerManagerContext.
 void dispose()
          Disposes all items that this ContextManager has created.
 void disposeOwned()
          Disposes all items ContextManager has assumed ownership over
protected  boolean entryPresent(Context context, java.lang.String key)
          Checks if a specified entry in context has been supplied by the invoker.
protected  java.lang.Object get(Context context, java.lang.String key, java.lang.Object defaultValue)
          Convenience method to obtain a value, or defer to a default if it does not exist.
 Context getChildContext()
          Finalizes and returns the context.
protected  Configuration getConfiguration(java.lang.String configKey, java.lang.String uriKey)
          Get a configuration based on a config and URI key.
 Context getContainerManagerContext()
          Finalizes and returns the context.
protected  Logger getLogger()
          Get a reference the Logger.
 void initialize()
          Initialize the ContextManager.
protected  void initializeCommandSink()
          Set up the CommandSink to enable asynchronous management.
protected  void initializeConfiguration()
          Load the configuration file that the Container will need to operate.
protected  void initializeContext()
          Initialize the context that will be passed into the impl.
protected  void initializeDefaultSourceResolver()
          Initialize the default source resolver
protected  void initializeInstrumentManager()
          Will set up an InstrumentManager if none is supplied.
protected  void initializeLoggerManager()
          Will set up a LogKitLoggerManager if none is supplied.
protected  void initializeMetaInfoManager()
           
protected  void initializePoolManager()
          Set up the Pool Manager for the managed pool.
protected  void initializeServiceManager()
          Get a reference to the initial ComponentLocator used by the ContainerManager to hold the Components used for parsing the config files and setting up the environment.
protected  void initializeThreadManager()
           
protected  RoleManager obtainRoleManager()
          Set up a RoleManager for the Container if configuration for it has been supplied.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_CONFIG

protected static final Configuration EMPTY_CONFIG

m_rootContext

protected final Context m_rootContext
The root context.


m_childContext

protected final DefaultContext m_childContext
The context of the new impl. This context has the rootContext as its parent. Put everything here that you want the new impl to have in its own context.


m_containerManagerContext

protected final DefaultContext m_containerManagerContext
Container manager's context. This context has the child context as parent. Put things here that you want the impl manager to see, but do not wish to expose to the impl.


m_logger

protected Logger m_logger

m_primordialLogger

protected final Logger m_primordialLogger

m_defaultSourceResolver

protected SourceResolver m_defaultSourceResolver
Source resolver used to read-in the configurations. and provided as a default source resolver if the user has not supplied a ServiceManager.


m_loggerManager

protected LoggerManager m_loggerManager
The logger manager in use. Either supplied via rootContext, or created locally.


m_sink

protected org.d_haven.event.Sink m_sink
The Sink in use. Either supplied via rootContext or created locally.


m_metaInfoManager

protected MetaInfoManager m_metaInfoManager
The MetaInfoManager to be used by the container. Either supplied via rootContext or created locally.


m_poolManager

protected org.d_haven.mpool.PoolManager m_poolManager
The PoolManager to be used by the container. Either supplied via rootContext or created locally.


m_threadManager

protected org.d_haven.event.command.ThreadManager m_threadManager
The ThreadManager to be used by the container. Either supplied via rootContext or created locally.


m_instrumentManager

protected InstrumentManager m_instrumentManager
The InstrumentManager to be used by the container. Either supplied via rootContext or created locally.

Constructor Detail

ContextManager

public ContextManager(Context rootContext,
                      Logger logger)
Create a new ContextManager.

Parameters:
rootContext - the default values.
logger - logger to use when creating new components.
Method Detail

assumeOwnership

protected void assumeOwnership(java.lang.Object object)
Method to assume ownership of one of the managers the ContextManager created. Ownership means that the ContextManager is responsible for destroying the manager when the ContextManager is destroyed.

Parameters:
object - The object being claimed
Throws:
java.lang.IllegalArgumentException - if the object is null.

initialize

public void initialize()
                throws java.lang.Exception
Initialize the ContextManager. This will cause the ContextManager to create any managers it needs.

Specified by:
initialize in interface Initializable
Throws:
java.lang.Exception - if there is a problem at any point in the initialization.

initializeConfiguration

protected void initializeConfiguration()
Load the configuration file that the Container will need to operate.


initializeContext

protected void initializeContext()
                          throws java.lang.Exception
Initialize the context that will be passed into the impl.

Throws:
java.lang.Exception - if any of the parameters cannot be copied properly.

copyEntry

protected void copyEntry(java.lang.String key)
                  throws ContextException
Copies the specified entry from the rootContext to the containerManagerContext.

Throws:
ContextException - if the parameter does not exist

entryPresent

protected boolean entryPresent(Context context,
                               java.lang.String key)
Checks if a specified entry in context has been supplied by the invoker.

Parameters:
context - The context to check
key - The key name to check

dispose

public void dispose()
Disposes all items that this ContextManager has created.

Specified by:
dispose in interface Disposable

disposeOwned

public void disposeOwned()
Disposes all items ContextManager has assumed ownership over


get

protected java.lang.Object get(Context context,
                               java.lang.String key,
                               java.lang.Object defaultValue)
Convenience method to obtain a value, or defer to a default if it does not exist.

Parameters:
context - The context object we intend to get a value from.
key - The key we want to use to get the value.
defaultValue - The default value we return if the key does not exist.

initializeCommandSink

protected void initializeCommandSink()
                              throws java.lang.Exception
Set up the CommandSink to enable asynchronous management.

Throws:
java.lang.Exception - if the CommandSink could not be created.

initializePoolManager

protected void initializePoolManager()
                              throws java.lang.Exception
Set up the Pool Manager for the managed pool.

Throws:
java.lang.Exception - if there is an error.

obtainRoleManager

protected RoleManager obtainRoleManager()
                                 throws java.lang.Exception
Set up a RoleManager for the Container if configuration for it has been supplied.

Throws:
java.lang.Exception - if there is an error.

initializeMetaInfoManager

protected void initializeMetaInfoManager()
                                  throws java.lang.Exception
Throws:
java.lang.Exception

initializeDefaultSourceResolver

protected void initializeDefaultSourceResolver()
                                        throws java.lang.Exception
Initialize the default source resolver

Throws:
java.lang.Exception - when there is an error.

initializeServiceManager

protected void initializeServiceManager()
                                 throws java.lang.Exception
Get a reference to the initial ComponentLocator used by the ContainerManager to hold the Components used for parsing the config files and setting up the environment.

Throws:
java.lang.Exception - when there is an error.

getConfiguration

protected Configuration getConfiguration(java.lang.String configKey,
                                         java.lang.String uriKey)
Get a configuration based on a config and URI key.

Parameters:
configKey - Get the Configuration object directly from the context.
uriKey - Get the uri from the context.

getContainerManagerContext

public Context getContainerManagerContext()
Finalizes and returns the context.

Returns:
a Context

getChildContext

public Context getChildContext()
Finalizes and returns the context.

Returns:
a Context

getLogger

protected Logger getLogger()
Get a reference the Logger.

Returns:
a Logger

initializeLoggerManager

protected void initializeLoggerManager()
                                throws java.lang.Exception
Will set up a LogKitLoggerManager if none is supplied. This can be overridden if you don't want a LogKitLoggerManager.

The postcondition is that childContext.get( LoggerManager.ROLE ) should return a valid logger manager.

Throws:
java.lang.Exception - if it cannot instantiate the LoggerManager

initializeThreadManager

protected void initializeThreadManager()
                                throws java.lang.Exception
Throws:
java.lang.Exception

initializeInstrumentManager

protected void initializeInstrumentManager()
                                    throws java.lang.Exception
Will set up an InstrumentManager if none is supplied. This can be overridden if you don't want an InstrumentManager

The postcondition is that childContext.get( InstrumentManager.ROLE ) should return a valid instrument manager.

Throws:
java.lang.Exception - if it cannot instantiate the InstrumentManager


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.