Class ThreadSafeComponentManager<T>
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.runtime.plugin.component.ThreadSafeComponentManager<T>
-
- Type Parameters:
T
- The type of handled extensions
- All Implemented Interfaces:
LogEnabled
,Disposable
,Initializable
,Contextualizable
,Serviceable
- Direct Known Subclasses:
PluginsComponentManager
public class ThreadSafeComponentManager<T> extends AbstractLogEnabled implements Contextualizable, Initializable, Disposable, Serviceable
Special ServiceManager able to handle extensions.
It does not actually implements the Avalon ServiceManager interface, to be able to use the Java 5 generic parameter.
This class is also intended to be used "locally" : its lookup(role) method does NOT propagate to the parent manager if the component does not exist.
To use the real ServiceManager, use the PluginsServiceManager subclass instead.
It handles the "PluginAware" interface, implemented by extensions.
It handles the following Avalon interfaces :- LogEnabled
- Contextualizable
- Serviceable
- Configurable
- Parameterizable
- Initializable
- Startable
- Disposable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
ThreadSafeComponentManager.ComponentFactory
-
Field Summary
Fields Modifier and Type Field Description private Map<String,ThreadSafeComponentManager.ComponentFactory>
_componentFactories
Used to map roles to ComponentFactoriesprivate Map<String,T>
_components
(package private) Map<String,T>
_componentsInitializing
(package private) Context
_context
The application context for componentsprivate boolean
_disposed
Is the Manager disposed or not?private boolean
_initialized
Is the Manager initialized?protected ServiceManager
_manager
The Cocoon ServiceManager
-
Constructor Summary
Constructors Constructor Description ThreadSafeComponentManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
_addComponent(String role, ThreadSafeComponentManager.ComponentFactory factory)
void
addComponent(String pluginName, String featureName, String role, Class<? extends T> component, Configuration configuration)
Add a new component to the manager.void
contextualize(Context context)
Set up the Component Context.void
dispose()
Properly dispose of the Child handlers.(package private) ThreadSafeComponentManager.ComponentFactory
getComponentFactory(String pluginName, String featureName, String role, Class<? extends T> componentClass, Configuration configuration)
boolean
hasComponent(T component)
Tests for existence of a component.boolean
hasRole(String role)
Tests for existence of a component for a given role.void
initialize()
Properly initialize of the Child handlers.T
lookup(String role)
Return an instance of a component based on a Role.void
service(ServiceManager manager)
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_manager
protected ServiceManager _manager
The Cocoon ServiceManager
-
_componentsInitializing
Map<String,T> _componentsInitializing
-
_components
private Map<String,T> _components
-
_componentFactories
private Map<String,ThreadSafeComponentManager.ComponentFactory> _componentFactories
Used to map roles to ComponentFactories
-
_disposed
private boolean _disposed
Is the Manager disposed or not?
-
_initialized
private boolean _initialized
Is the Manager initialized?
-
-
Constructor Detail
-
ThreadSafeComponentManager
public ThreadSafeComponentManager()
-
-
Method Detail
-
service
public void service(ServiceManager manager)
- Specified by:
service
in interfaceServiceable
-
contextualize
public void contextualize(Context context)
Set up the Component Context.- Specified by:
contextualize
in interfaceContextualizable
-
lookup
public T lookup(String role) throws ComponentException
Return an instance of a component based on a Role. The Role is usually the Interface Fully Qualified Name(FQN).- Parameters:
role
- The key name of theComponent
to retrieve.- Returns:
- the desired component or null if no component exist for the given role
- Throws:
ComponentException
- if an error occurs
-
hasRole
public boolean hasRole(String role)
Tests for existence of a component for a given role.- Parameters:
role
- a string identifying the key to check.- Returns:
- true if there is a component for the given role, false if not.
-
hasComponent
public boolean hasComponent(T component)
Tests for existence of a component.- Parameters:
component
- to component to check- Returns:
- true if the component exists, false if it does not.
-
initialize
public void initialize() throws Exception
Properly initialize of the Child handlers.- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
dispose
public void dispose()
Properly dispose of the Child handlers.- Specified by:
dispose
in interfaceDisposable
-
addComponent
public void addComponent(String pluginName, String featureName, String role, Class<? extends T> component, Configuration configuration)
Add a new component to the manager.- Parameters:
pluginName
- the plugin containing the componentfeatureName
- the feature containing the componentrole
- the role name for the new component.component
- the class of this component.configuration
- the configuration for this component.
-
_addComponent
void _addComponent(String role, ThreadSafeComponentManager.ComponentFactory factory)
-
getComponentFactory
ThreadSafeComponentManager.ComponentFactory getComponentFactory(String pluginName, String featureName, String role, Class<? extends T> componentClass, Configuration configuration)
-
-