|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.sape.carbon.core.component.DefaultComponentKeeper
The default implemetation of ComponentKeeper. This implementation uses
a HashMap
to store references to all live components. If
requested component does not exist, it delegates to a
ComponentFactory
to create the requested component. It uses
a HashMap
of locks to ensure that a component is constructed
only once.
Field Summary | |
private ComponentFactory |
componentFactory
ComponentFactory used to build all components in the system. |
private Map |
componentMap
Map of all Component s known to the system
keyed by (String) logicalComponentName. |
private List |
componentNameList
List of all component names known to the keeper in order of their creation. |
private Map |
creationLocks
Map of locks used to ensure that component are built only once. |
private org.apache.commons.logging.Log |
log
Provides handle to Apache-commons logger. |
private Map |
nascentComponents
Storage for components that have been created and intialized, but not configured or started. |
private Thread |
shutdownHook
Maintains a reference to the thread for shutting down the component system on JVM exit. |
Constructor Summary | |
protected |
DefaultComponentKeeper(ComponentKeeperConfiguration configuration)
protected constructor prevents direct instantiation but does not prevent extenstion, this is meant to be called by DefaultComponentKeeperFactory |
Method Summary | |
private void |
addComponent(String logicalComponentName,
Component component)
Puts a component into componentMap using logicalComponentName as the key and adds logicalComponentName to the end of componentNameList. |
private void |
configure(ComponentKeeperConfiguration keeperConfiguration)
Lifecycle method to configure the keeper. |
void |
destroyAllComponents()
Destroys all components. |
void |
destroyComponent(String logicalComponentName)
Destroys the component specified by the name parameter. |
Component |
fetchComponent(String logicalComponentName)
Gets a reference to the component specified by the name parameter. |
private Component |
fetchNewComponent(String logicalComponentName)
This method fetches a new component. |
private Component |
getComponent(String logicalComponentName)
Gets a component from componentMap using logicalComponentName as the key. |
Collection |
getComponentNames()
This implementation returns a copy of the keySet of the internal map of components. |
private Object |
getCreationLock(String name)
Gets the lock object used to synchronize the creation of the component signified by the supplied name. |
protected void |
registerShutdownHook()
Creates a new shutdown hook, if one does not already exist, and registers it with the JVM shutdown hook. |
private Component |
removeComponent(String logicalComponentName)
Removes the component keyed by logicalComponentName from componentMap and removes logicalComponentName from componentNameList. |
private void |
startComponent(String logicalComponentName,
Component component)
Calls the Lifecycle subsystem to configure and start the component. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private org.apache.commons.logging.Log log
private ComponentFactory componentFactory
ComponentFactory used to build all components in the system.
private Map creationLocks
private Map componentMap
Map of all Component
s known to the system
keyed by (String) logicalComponentName.
private Map nascentComponents
private List componentNameList
List of all component names known to the keeper in order of their creation. Used in destroyAllComponents to determine the order in which to destroy components.
The List implementation used is LinkedList. This is because it is fast when it comes to appending or removing items. LikedLists are not optimized for Random access, but this will be rare (only when destroyComponent is called outside of destroyAllComponents).
private Thread shutdownHook
Constructor Detail |
protected DefaultComponentKeeper(ComponentKeeperConfiguration configuration)
configuration
- the configuration of this component keeperMethod Detail |
protected void registerShutdownHook()
Creates a new shutdown hook, if one does not already exist, and registers it with the JVM shutdown hook.
Runtime.addShutdownHook(java.lang.Thread)
public Component fetchComponent(String logicalComponentName)
Gets a reference to the component specified by the name parameter. Builds the component if it has not yet been created.
This implementation delegates to a ComponentFactory
to
build components.
fetchComponent
in interface ComponentKeeper
logicalComponentName
- the name of the component
ComponentNotFoundException
- if the component specified by
logicalComponentName cannot be found in configuration.
InvalidParameterException
- if logicalComponentName is
an empty string or logicalComponentName is nullpublic void destroyAllComponents()
Destroys all components.
This implementation destroys components in the order in which they were created. Note that this will halt all requests for components until all existing components are destroyed.
destroyAllComponents
in interface ComponentKeeper
public void destroyComponent(String logicalComponentName)
Destroys the component specified by the name parameter.
destroyComponent
in interface ComponentKeeper
logicalComponentName
- the name of the componentpublic Collection getComponentNames()
getComponentNames
in interface ComponentKeeper
ComponentKeeper.getComponentNames()
private void configure(ComponentKeeperConfiguration keeperConfiguration)
Lifecycle method to configure the keeper. This method instantiates
ComponentFactory
. This must be called prior to using
the keeper.
keeperConfiguration
- the configuration of this component keeperprivate Component getComponent(String logicalComponentName)
logicalComponentName
- name of the component
private void addComponent(String logicalComponentName, Component component)
logicalComponentName
- name of the componentcomponent
- component object to addprivate Component removeComponent(String logicalComponentName)
logicalComponentName
- name of the component to remove
private Component fetchNewComponent(String logicalComponentName)
This method fetches a new component. It deals with the concurency issues associated with multiple threads requesting a component that has not yet been created at the same time. It ensures that only one thread will create the component. This is done through the follwing logic:
logicalComponentName
- the name of the new component
private void startComponent(String logicalComponentName, Component component)
Calls the Lifecycle subsystem to configure and start the component. When this call completes, the component should be in a LifecycleStateEnum.RUNNING state.
logicalComponentName
- the name of component to startcomponent
- the component to startprivate Object getCreationLock(String name)
name
- the name of the component to get the lock for
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |