org.apache.avalon.fortress.impl
Class AbstractContainer

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.avalon.fortress.impl.AbstractContainer
All Implemented Interfaces:
Container, Contextualizable, Disposable, Initializable, LogEnabled, Serviceable
Direct Known Subclasses:
DefaultContainer

public abstract class AbstractContainer
extends AbstractLogEnabled
implements Contextualizable, Serviceable, Initializable, Disposable, Container

This abstract implementation provides basic functionality for building an implementation of the Container interface. It exposes a protected getServiceManager() method so that the Container's Manager can expose that to the instantiating class.

Version:
CVS $Revision: 1.41 $ $Date: 2004/02/28 15:16:24 $
Author:
The Avalon Team

Field Summary
static java.lang.String DEFAULT_ENTRY
          The hint map's entry to get the default component type.
protected  java.lang.ClassLoader m_classLoader
          contains the impl's root ClassLoader, which is extracted from m_serviceManager.
protected  org.d_haven.event.Sink m_commandSink
          contains the impl's Sink, which is extracted from m_serviceManager.
protected  Context m_componentContext
          contains the context that will be passed to the components we will create.
protected  java.util.List m_components
          Contains an entry for each ComponentHandler
protected  Context m_context
          contains the impl's context passed in through contextualize().
protected  LifecycleExtensionManager m_extManager
          contains the impl's LifecycleExtensionManager, which is extracted from m_serviceManager.
protected  InstrumentManager m_instrumentManager
          contains the impl's InstrumentManager, which is extracted from m_serviceManager.
protected  LoggerManager m_loggerManager
          contains the impl's LoggerManager, which is extracted from m_serviceManager.
protected  java.util.Map m_mapper
          Contains entries mapping roles to hint maps, where the hint map contains mappings from hints to ComponentHandlers.
protected  MetaInfoManager m_metaManager
          contains the impl's RoleManager, which is extracted from m_serviceManager.
protected  org.d_haven.mpool.PoolManager m_poolManager
          contains the impl's PoolManager, which is extracted from m_serviceManager.
protected  ServiceManager m_serviceManager
          contains the ServiceManager the impl will use, based on the one passed in through service().
protected  java.util.List m_shutDownOrder
           
static java.lang.String SELECTOR_ENTRY
          The component map's entry to get a ServiceSelector.
 
Fields inherited from interface org.apache.avalon.fortress.Container
ROLE
 
Constructor Summary
AbstractContainer()
           
 
Method Summary
protected  void addComponent(ComponentHandlerMetaData metaData)
          Add a Component into the impl.
 void contextualize(Context context)
          Pull the manager items from the context so we can use them to set up the system.
protected  java.util.Map createHintMap()
          Create the hint map for a role.
protected  org.d_haven.mpool.ObjectFactory createObjectFactory(java.lang.String classname, Configuration configuration)
          Create an objectFactory for specified Object configuration.
 void dispose()
          Disposes of all components and frees resources that they consume.
 java.lang.Object get(java.lang.String role, java.lang.Object hint)
          This is the method that the ContainerComponentManager and Selector use to gain access to the ComponentHandlers and ComponentSelectors.
protected  ProxyManager getProxyManager()
          Guarantees that the ProxyManager will be assigned before use.
protected static java.lang.String getRoleKey(java.lang.String role, java.lang.Object hint)
          Get the composite role name based on the specified role and hint.
protected  ServiceManager getServiceManager()
          Exposes to subclasses the service manager which this impl uses to manage its child components.
 boolean has(java.lang.String role, java.lang.Object hint)
          This is the method that the ContainerComponentManager and Selector use to gain access to the ComponentHandlers and ComponentSelectors.
 void initialize()
          Initializes the impl and all the components it hosts so that they are ready to be used.
protected  Context provideComponentContext(Context parent)
          Override this method to control what context will be passed to the components created by this container.
protected  ServiceManager provideServiceManager(ServiceManager parent)
          Override this method to control creation of the serviceManager belonging to this container.
 void service(ServiceManager serviceManager)
          Root ServiceManager.
protected  void setProxyManager(ProxyManager proxyManager)
          Allows you to override the ProxyManager used in the container.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENTRY

public static final java.lang.String DEFAULT_ENTRY
The hint map's entry to get the default component type.

See Also:
Constant Field Values

SELECTOR_ENTRY

public static final java.lang.String SELECTOR_ENTRY
The component map's entry to get a ServiceSelector.

See Also:
Constant Field Values

m_context

protected Context m_context
contains the impl's context passed in through contextualize().


m_serviceManager

protected ServiceManager m_serviceManager
contains the ServiceManager the impl will use, based on the one passed in through service().


m_loggerManager

protected LoggerManager m_loggerManager
contains the impl's LoggerManager, which is extracted from m_serviceManager.


m_poolManager

protected org.d_haven.mpool.PoolManager m_poolManager
contains the impl's PoolManager, which is extracted from m_serviceManager.


m_commandSink

protected org.d_haven.event.Sink m_commandSink
contains the impl's Sink, which is extracted from m_serviceManager.


m_classLoader

protected java.lang.ClassLoader m_classLoader
contains the impl's root ClassLoader, which is extracted from m_serviceManager.


m_metaManager

protected MetaInfoManager m_metaManager
contains the impl's RoleManager, which is extracted from m_serviceManager.


m_instrumentManager

protected InstrumentManager m_instrumentManager
contains the impl's InstrumentManager, which is extracted from m_serviceManager.


m_extManager

protected LifecycleExtensionManager m_extManager
contains the impl's LifecycleExtensionManager, which is extracted from m_serviceManager.


m_componentContext

protected Context m_componentContext
contains the context that will be passed to the components we will create. initialized the first time a component handler is created by a call to provideComponentContext -- override this method to affect the value of this object.


m_mapper

protected java.util.Map m_mapper
Contains entries mapping roles to hint maps, where the hint map contains mappings from hints to ComponentHandlers.


m_components

protected java.util.List m_components
Contains an entry for each ComponentHandler


m_shutDownOrder

protected java.util.List m_shutDownOrder
Constructor Detail

AbstractContainer

public AbstractContainer()
Method Detail

setProxyManager

protected void setProxyManager(ProxyManager proxyManager)
Allows you to override the ProxyManager used in the container. In order for your proxymanager to be used, it must be set prior to adding any components.

Parameters:
proxyManager -

getProxyManager

protected ProxyManager getProxyManager()
                                throws java.lang.Exception
Guarantees that the ProxyManager will be assigned before use. If you do not set the proxy manager, the AbstractContainer will use the ProxyManager.DISCOVER algorithm.

Returns:
the ProxyManager.
Throws:
java.lang.Exception - if there is a problem

contextualize

public void contextualize(Context context)
                   throws ContextException
Pull the manager items from the context so we can use them to set up the system.

Specified by:
contextualize in interface Contextualizable
Parameters:
context - the impl context
Throws:
ContextException - if a contexaulization error occurs

service

public void service(ServiceManager serviceManager)
             throws ServiceException
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.

Specified by:
service in interface Serviceable
Parameters:
serviceManager - the service manager to apply to the impl
Throws:
ServiceException - is a servicing related error occurs

addComponent

protected void addComponent(ComponentHandlerMetaData metaData)
                     throws java.lang.IllegalArgumentException,
                            java.lang.Exception
Add a Component into the impl. This sets the component up for management by the impl by creating an appropriate ComponentHandler.

Parameters:
metaData - the information needed to construct a ComponentHandler for the component
Throws:
java.lang.IllegalArgumentException - if the classname defined by the meta data argument is undefined within the scope of the role manager
java.lang.Exception - if unable to create a Handler for the component

createObjectFactory

protected org.d_haven.mpool.ObjectFactory createObjectFactory(java.lang.String classname,
                                                              Configuration configuration)
                                                       throws java.lang.Exception
Create an objectFactory for specified Object configuration.

Parameters:
classname - the classname of object
configuration - the objests configuration
Returns:
the ObjectFactory
Throws:
java.lang.ClassNotFoundException - if the specified class does not exist
java.lang.Exception

get

public java.lang.Object get(java.lang.String role,
                            java.lang.Object hint)
                     throws ServiceException
This is the method that the ContainerComponentManager and Selector use to gain access to the ComponentHandlers and ComponentSelectors. The actual access of the ComponentHandler is delegated to the Container.

Specified by:
get in interface Container
Parameters:
role - The role we intend to access a Component for.
hint - The hint that we use as a qualifier (note: if null, the default implementation is returned).
Returns:
Object a reference to the ComponentHandler or ComponentSelector for the role/hint combo.
Throws:
ServiceException - if the container cannot get the component

createHintMap

protected java.util.Map createHintMap()
Create the hint map for a role. The map may have to take care for thread-safety. By default a StaticBucketMap is created, but you may change the implementation or increment the number of buckets according your needs.
WARNING: This Map must be threadsafe, so either use the StaticBucketMap or a synchronized Map. Otherwise you will experience erratic behavior due to the nature of the asyncronous component management.

Returns:
the hint map implementation

getRoleKey

protected static java.lang.String getRoleKey(java.lang.String role,
                                             java.lang.Object hint)
Get the composite role name based on the specified role and hint. The default implementation puts a "/" on the end of the rolename and then adds the string representation of the hint. This is used for informational display purposes only.

Parameters:
role -
hint -
Returns:

has

public boolean has(java.lang.String role,
                   java.lang.Object hint)
This is the method that the ContainerComponentManager and Selector use to gain access to the ComponentHandlers and ComponentSelectors. The actual access of the ComponentHandler is delegated to the Container.

Specified by:
has in interface Container
Parameters:
role - The role we intend to access a Component for.
hint - The hint that we use as a qualifier (note: if null, the default implementation is returned).
Returns:
true if a reference to the role exists.

initialize

public void initialize()
                throws CompositeException,
                       java.lang.Exception
Initializes the impl and all the components it hosts so that they are ready to be used. Unless components ask for lazy activation, this is where they are activated.

Specified by:
initialize in interface Initializable
Throws:
CompositeException - if one or more components could not be initialized. The system is running properly so if the missing components are not vital to operation, it should be possible to recover gracefully
java.lang.Exception - if an error occurs

dispose

public void dispose()
Disposes of all components and frees resources that they consume.

Specified by:
dispose in interface Disposable

getServiceManager

protected ServiceManager getServiceManager()
Exposes to subclasses the service manager which this impl uses to manage its child components. The returned ServiceManager is aware of the services passed in to this impl, and services that were passed in through service() are hence available to subclasses.

Returns:
the service manager that contains the child components.

provideServiceManager

protected ServiceManager provideServiceManager(ServiceManager parent)
                                        throws ServiceException
Override this method to control creation of the serviceManager belonging to this container. This serviceManager is passed to child components as they are being created and is exposed via the getServiceManager() method. Invoked from the service() method. However even a self-contained container should be careful about cutting access to parent serviceManager completely, as important (and required) system services including Sink, LoggerManager, InstrumentManager, PoolManager and LifecycleExtensionManager are passed via ServiceManager also. SourceResolver hangs somewhere in between system and "user space" services. It's more or less okay to cut access to them if our child components do not need them and are not containers themselves, but if we have containers as our children they will require these services.

Throws:
ServiceException

provideComponentContext

protected Context provideComponentContext(Context parent)
                                   throws java.lang.Exception
Override this method to control what context will be passed to the components created by this container. Called the first time a component being created - withing this implementation it is a part of the configure() stage. You may derive your context from m_context or create a new one.

Throws:
java.lang.Exception


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