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
-
-
Field Summary
Fields Modifier and Type Field Description protected ServiceManager
_manager
The Cocoon ServiceManager
-
Constructor Summary
Constructors Constructor Description ThreadSafeComponentManager()
Default constructor.ThreadSafeComponentManager(boolean allowCircularDependencies)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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
-
-
Constructor Detail
-
ThreadSafeComponentManager
public ThreadSafeComponentManager()
Default constructor. Allow circular dependencies.
-
ThreadSafeComponentManager
public ThreadSafeComponentManager(boolean allowCircularDependencies)
Constructor.- Parameters:
allowCircularDependencies
- if this manager should allow circular dependencies during initialization
-
-
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.
-
-