|
eXo Kernel :: Container 2.5.0-GA | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.exoplatform.container.AbstractContainer
org.exoplatform.container.AbstractInterceptor
org.exoplatform.container.ConcurrentContainer
public class ConcurrentContainer
This class is aimed to be a ThreadSafe implementation of an Container based on
java.util.concurrent collections.
Created by The eXo Platform SAS
Author : Nicolas Filotto
nicolas.filotto@exoplatform.com
6 mai 2010
| Nested Class Summary | |
|---|---|
static class |
ConcurrentContainer.CreationalContextComponentAdapter<T>
This class is used as value holder |
| Field Summary | |
|---|---|
protected Set<ExoContainer> |
children
|
protected Set<ComponentAdapter<?>> |
componentAdapters
|
protected ConcurrentMap<Object,ComponentAdapter<?>> |
componentKeyToAdapterCache
|
protected CopyOnWriteArrayList<ComponentAdapter<?>> |
orderedComponentAdapters
|
| Fields inherited from class org.exoplatform.container.AbstractInterceptor |
|---|
holder, parent |
| Fields inherited from class org.exoplatform.container.AbstractContainer |
|---|
delegate |
| Constructor Summary | |
|---|---|
ConcurrentContainer()
Creates a new container with the default ComponentAdapterFactory and a parent container. |
|
ConcurrentContainer(ExoContainer holder,
ExoContainer parent)
Creates a new container with the default ComponentAdapterFactory and a parent container. |
|
| Method Summary | ||
|---|---|---|
void |
accept(ContainerVisitor visitor)
Accepts a visitor that should visit the child containers, component adapters and component instances. |
|
|
addComponentToCtx(Object key)
Add the CreationalContext corresponding to the given key, to the dependency resolution
context |
|
protected void |
addMethods(Class<?> c,
Map<String,Method> methodAlreadyRegistered,
Map<Class<?>,Collection<Method>> methodsPerClass)
|
|
protected void |
addOrderedComponentAdapter(ComponentAdapter<?> componentAdapter)
|
|
|
createComponent(Class<T> clazz)
|
|
|
createComponent(Class<T> clazz,
InitParams params)
Creates a component corresponding to the given Class with the
given InitParams |
|
void |
dispose()
Dispose the components of this Container and all its logical child containers. |
|
protected CachingContainer |
getCache()
Gives the cache if already found otherwise it will get it from the interceptor chain |
|
|
getComponentAdapter(Object componentKey,
Class<T> bindType,
boolean autoRegistration)
Find a component adapter associated with the specified key. |
|
|
getComponentAdapterOfType(Class<T> componentType,
boolean autoRegistration)
Find a component adapter associated with the specified type. |
|
Collection<ComponentAdapter<?>> |
getComponentAdapters()
Retrieve all the component adapters inside this container. |
|
|
getComponentAdaptersOfType(Class<T> componentType)
Retrieve all component adapters inside this container that are associated with the specified type. |
|
|
getComponentInstance(Object componentKey,
Class<T> bindType,
boolean autoRegistration)
Retrieve a component instance registered with a specific key. |
|
protected
|
getComponentInstanceFromContext(ComponentAdapter<T> componentAdapter,
Class<T> bindType)
Gets the component instance from the context |
|
|
getComponentInstanceOfType(Class<T> componentType,
boolean autoRegistration)
If no ConcurrentContainer.CreationalContextComponentAdapter can be found it returns null otherwise
it first try to get it from the dependency resolution context if it still cannot
be found we get the instance from the ConcurrentContainer.CreationalContextComponentAdapter. |
|
List<Object> |
getComponentInstances()
|
|
|
getComponentInstancesOfType(Class<T> componentType)
Returns a List of components of a certain componentType. |
|
protected ComponentAdapterFactory |
getDefaultComponentAdapterFactory()
|
|
ExoContainer |
getHolder()
|
|
protected
|
getInstance(ComponentAdapter<T> componentAdapter,
Class<T> type,
boolean autoRegistration)
|
|
ManagementContext |
getManagementContext()
Gives the corresponding ManagementContext |
|
MBeanServer |
getMBeanServer()
Provides the MBeanServer this method is needed for backward compatibility |
|
ObjectName |
getScopingObjectName()
Gives the ObjectName of the container build from the scoping data |
|
void |
initialize()
Initializes the container |
|
|
initializeComponent(T instance)
Initializes the instance by injecting objects into fields and the methods with the annotation Inject |
|
protected ComponentAdapter<?> |
registerComponent(ComponentAdapter<?> componentAdapter)
Register a component via a ComponentAdapter. |
|
|
registerComponentImplementation(Object componentKey,
Class<T> componentImplementation)
Register a component. |
|
|
registerComponentInstance(Object componentKey,
T componentInstance)
Register an arbitrary object as a component in the container. |
|
void |
removeComponentFromCtx(Object key)
Remove the component corresponding to the given key, from the dependency resolution context |
|
void |
setHolder(ExoContainer holder)
Sets the holder which is mostly used when it is required to be able to go through the chain of Interceptor |
|
void |
start()
Start the components of this Container and all its logical child containers. |
|
void |
stop()
Stop the components of this Container and all its logical child containers. |
|
ComponentAdapter<?> |
unregisterComponent(Object componentKey)
Unregister a component by key. |
|
| Methods inherited from class org.exoplatform.container.AbstractInterceptor |
|---|
getId, setParent, setSuccessor |
| Methods inherited from class org.exoplatform.container.AbstractContainer |
|---|
getSuccessor |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.exoplatform.container.spi.Container |
|---|
getSuccessor |
| Field Detail |
|---|
protected final ConcurrentMap<Object,ComponentAdapter<?>> componentKeyToAdapterCache
protected final Set<ComponentAdapter<?>> componentAdapters
protected final CopyOnWriteArrayList<ComponentAdapter<?>> orderedComponentAdapters
protected final Set<ExoContainer> children
| Constructor Detail |
|---|
public ConcurrentContainer()
ComponentAdapterFactory and a parent container.
public ConcurrentContainer(ExoContainer holder,
ExoContainer parent)
ComponentAdapterFactory and a parent container.
holder - the holder of the containerparent - the parent container (used for component dependency lookups).| Method Detail |
|---|
public Collection<ComponentAdapter<?>> getComponentAdapters()
AbstractContainer
getComponentAdapters in interface ContainergetComponentAdapters in class AbstractContainerComponentAdapters inside this container. The collection will
not be modifiable.a variant of this method which returns the component adapters inside this
container that are associated with the specified type.public void setHolder(ExoContainer holder)
AbstractInterceptorInterceptor
setHolder in interface InterceptorsetHolder in class AbstractInterceptorholder - the holder of the containerprotected ComponentAdapterFactory getDefaultComponentAdapterFactory()
public <T> ComponentAdapter<T> getComponentAdapter(Object componentKey,
Class<T> bindType,
boolean autoRegistration)
throws ContainerException
AbstractContainer
getComponentAdapter in interface ContainergetComponentAdapter in class AbstractContainercomponentKey - the key that the component was registered with.bindType - the expected raw type of the adapter if one can be found.autoRegistration - indicates whether the auto registration should be performed or not
null if no component has been registered
for the specified key.
ContainerException
public <T> ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType,
boolean autoRegistration)
AbstractContainer
getComponentAdapterOfType in interface ContainergetComponentAdapterOfType in class AbstractContainercomponentType - the type of the component.autoRegistration - indicates whether the auto registration should be performed or not
null if no component has been
registered for the specified key.public <T> List<ComponentAdapter<T>> getComponentAdaptersOfType(Class<T> componentType)
AbstractContainer
getComponentAdaptersOfType in interface ContainergetComponentAdaptersOfType in class AbstractContainercomponentType - the type of the components.
ComponentAdapters inside this container that are associated with
the specified type. Changes to this collection will not be reflected in the container itself.
protected ComponentAdapter<?> registerComponent(ComponentAdapter<?> componentAdapter)
throws ContainerException
componentAdapter - the adapter
ContainerException - if registration fails.public ComponentAdapter<?> unregisterComponent(Object componentKey)
AbstractContainer
unregisterComponent in interface ContainerunregisterComponent in class AbstractContainercomponentKey - key of the component to unregister.
public <T> ComponentAdapter<T> registerComponentInstance(Object componentKey,
T componentInstance)
throws ContainerException
InstanceComponentAdapter.
registerComponentInstance in interface ContainerregisterComponentInstance in class AbstractContainercomponentKey - a key that identifies the component. Must be unique within the container. The type of the
key object has no semantic significance unless explicitly specified in the implementing
container.componentInstance - an arbitrary object.
getXXX() methods of the
Container interface can be used to retrieve a reference to the component later on.
ContainerException - if registration fails.
public <T> ComponentAdapter<T> registerComponentImplementation(Object componentKey,
Class<T> componentImplementation)
throws ContainerException
ComponentAdapterFactory
passed to the container's constructor.
registerComponentImplementation in interface ContainerregisterComponentImplementation in class AbstractContainercomponentKey - a key that identifies the component. Must be unique within the container. The type
of the key object has no semantic significance unless explicitly specified in the
documentation of the implementing container.componentImplementation - the component's implementation class. This must be a concrete class (ie, a
class that can be instantiated).
getXXX() methods of the
Container interface can be used to retrieve a reference to the component later on.
ContainerExceptionprotected void addOrderedComponentAdapter(ComponentAdapter<?> componentAdapter)
public List<Object> getComponentInstances()
throws ContainerException
ContainerException
public <T> List<T> getComponentInstancesOfType(Class<T> componentType)
throws ContainerException
AbstractContainer
getComponentInstancesOfType in interface ContainergetComponentInstancesOfType in class AbstractContainercomponentType - the searched type.
ContainerException
public <T> T getComponentInstance(Object componentKey,
Class<T> bindType,
boolean autoRegistration)
throws ContainerException
AbstractContainer
getComponentInstance in interface ContainergetComponentInstance in class AbstractContainercomponentKey - the key that the component was registered with.bindType - the expected type of the instance if one can be found.autoRegistration - indicates whether the auto registration should be performed or not
null if no component has been registered for the specified
key.
ContainerException
protected <T> T getComponentInstanceFromContext(ComponentAdapter<T> componentAdapter,
Class<T> bindType)
public <T> T getComponentInstanceOfType(Class<T> componentType,
boolean autoRegistration)
ConcurrentContainer.CreationalContextComponentAdapter can be found it returns null otherwise
it first try to get it from the dependency resolution context if it still cannot
be found we get the instance from the ConcurrentContainer.CreationalContextComponentAdapter.
getComponentInstanceOfType in interface ContainergetComponentInstanceOfType in class AbstractContainercomponentType - the type of the component.autoRegistration - indicates whether the auto registration should be performed or not
Container#getComponentInstanceOfType(java.lang.Class)public <T> ConcurrentContainer.CreationalContextComponentAdapter<T> addComponentToCtx(Object key)
CreationalContext corresponding to the given key, to the dependency resolution
context
key - The key of the component to add to the resolution contextpublic void removeComponentFromCtx(Object key)
key - The key of the component to remove from the context
protected <T> T getInstance(ComponentAdapter<T> componentAdapter,
Class<T> type,
boolean autoRegistration)
public void start()
Startable will be started.
start in interface Startablestart in class AbstractContainerpublic void stop()
Startable will be stopped.
stop in interface Startablestop in class AbstractContainerpublic void dispose()
Disposable will be disposed.
dispose in interface Disposabledispose in class AbstractContainerpublic void accept(ContainerVisitor visitor)
AbstractContainer
accept in interface Containeraccept in class AbstractContainervisitor - the visitorpublic ExoContainer getHolder()
public ManagementContext getManagementContext()
ManagementContext
getManagementContext in interface ContainergetManagementContext in class AbstractContainerpublic MBeanServer getMBeanServer()
MBeanServer this method is needed for backward compatibility
getMBeanServer in interface ContainergetMBeanServer in class AbstractContainerpublic ObjectName getScopingObjectName()
getScopingObjectName in interface ContainergetScopingObjectName in class AbstractContainer
public <T> T createComponent(Class<T> clazz)
throws Exception
Exception
public <T> T createComponent(Class<T> clazz,
InitParams params)
throws Exception
Class with the
given InitParams
createComponent in interface ContainercreateComponent in class AbstractContainerclazz - the Class of the object to createparams - the parameters to use to create the component
Exception - if any issue occurs while creating the component.public <T> boolean initializeComponent(T instance)
Inject
true if at least Inject annotation has been found, false otherwise
protected void addMethods(Class<?> c,
Map<String,Method> methodAlreadyRegistered,
Map<Class<?>,Collection<Method>> methodsPerClass)
public void initialize()
initialize in interface Containerinitialize in class AbstractContainerprotected CachingContainer getCache()
|
eXo Kernel :: Container 2.5.0-GA | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||