public class ConcurrentContainer extends AbstractInterceptor
Container based on
java.util.concurrent collections.
Created by The eXo Platform SAS
Author : Nicolas Filotto
nicolas.filotto@exoplatform.com
6 mai 2010| Modifier and Type | Class and Description |
|---|---|
static class |
ConcurrentContainer.CreationalContextComponentAdapter<T>
This class is used as value holder
|
| Modifier and Type | Field and Description |
|---|---|
protected Set<ExoContainer> |
children |
protected Set<ComponentAdapter<?>> |
componentAdapters |
protected ConcurrentMap<Object,ComponentAdapter<?>> |
componentKeyToAdapterCache |
protected CopyOnWriteArrayList<ComponentAdapter<?>> |
orderedComponentAdapters |
holder, parentdelegate| Constructor and Description |
|---|
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. |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(ContainerVisitor visitor)
Accepts a visitor that should visit the child containers, component adapters and component instances.
|
<T> ConcurrentContainer.CreationalContextComponentAdapter<T> |
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) |
<T> T |
createComponent(Class<T> clazz) |
<T> T |
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
|
<T> ComponentAdapter<T> |
getComponentAdapter(Object componentKey,
Class<T> bindType,
boolean autoRegistration)
Find a component adapter associated with the specified key.
|
<T> ComponentAdapter<T> |
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.
|
<T> List<ComponentAdapter<T>> |
getComponentAdaptersOfType(Class<T> componentType)
Retrieve all component adapters inside this container that are associated with the specified type.
|
<T> T |
getComponentInstance(Object componentKey,
Class<T> bindType,
boolean autoRegistration)
Retrieve a component instance registered with a specific key.
|
protected <T> T |
getComponentInstanceFromContext(ComponentAdapter<T> componentAdapter,
Class<T> bindType)
Gets the component instance from the context
|
<T> T |
getComponentInstanceOfType(Class<T> componentType,
boolean autoRegistration)
If no
ComponentAdapter 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 ComponentAdapter. |
List<Object> |
getComponentInstances() |
<T> List<T> |
getComponentInstancesOfType(Class<T> componentType)
Returns a List of components of a certain componentType.
|
protected ComponentAdapterFactory |
getDefaultComponentAdapterFactory() |
ExoContainer |
getHolder() |
protected <T> T |
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
|
<T> boolean |
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.
|
<T> ComponentAdapter<T> |
registerComponentImplementation(Object componentKey,
Class<T> componentImplementation)
Register a component.
|
<T> ComponentAdapter<T> |
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.
|
getId, setParent, setSuccessorgetSuccessorclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetSuccessorprotected final ConcurrentMap<Object,ComponentAdapter<?>> componentKeyToAdapterCache
protected final Set<ComponentAdapter<?>> componentAdapters
protected final CopyOnWriteArrayList<ComponentAdapter<?>> orderedComponentAdapters
protected final Set<ExoContainer> children
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).public Collection<ComponentAdapter<?>> getComponentAdapters()
AbstractContainergetComponentAdapters 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)
AbstractInterceptorInterceptorsetHolder 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
AbstractContainergetComponentAdapter 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 notnull if no component has been registered
for the specified key.ContainerExceptionpublic <T> ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType, boolean autoRegistration)
AbstractContainergetComponentAdapterOfType in interface ContainergetComponentAdapterOfType in class AbstractContainercomponentType - the type of the component.autoRegistration - indicates whether the auto registration should be performed or notnull if no component has been
registered for the specified key.public <T> List<ComponentAdapter<T>> getComponentAdaptersOfType(Class<T> componentType)
AbstractContainergetComponentAdaptersOfType 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 adapterContainerException - if registration fails.public ComponentAdapter<?> unregisterComponent(Object componentKey)
AbstractContainerunregisterComponent 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.ContainerException - if registration of the component fails.protected void addOrderedComponentAdapter(ComponentAdapter<?> componentAdapter)
public List<Object> getComponentInstances() throws ContainerException
ContainerExceptionpublic <T> List<T> getComponentInstancesOfType(Class<T> componentType) throws ContainerException
AbstractContainergetComponentInstancesOfType in interface ContainergetComponentInstancesOfType in class AbstractContainercomponentType - the searched type.ContainerExceptionpublic <T> T getComponentInstance(Object componentKey, Class<T> bindType, boolean autoRegistration) throws ContainerException
AbstractContainergetComponentInstance 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 notnull if no component has been registered for the specified
key.ContainerExceptionprotected <T> T getComponentInstanceFromContext(ComponentAdapter<T> componentAdapter, Class<T> bindType)
public <T> T getComponentInstanceOfType(Class<T> componentType, boolean autoRegistration)
ComponentAdapter 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 ComponentAdapter.getComponentInstanceOfType in interface ContainergetComponentInstanceOfType in class AbstractContainercomponentType - the type of the component.autoRegistration - indicates whether the auto registration should be performed or notContainer.getComponentInstanceOfType(Class, boolean)public <T> ConcurrentContainer.CreationalContextComponentAdapter<T> addComponentToCtx(Object key)
CreationalContext corresponding to the given key, to the dependency resolution
contextkey - 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 contextprotected <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)
AbstractContaineraccept in interface Containeraccept in class AbstractContainervisitor - the visitorpublic ExoContainer getHolder()
public ManagementContext getManagementContext()
ManagementContextgetManagementContext in interface ContainergetManagementContext in class AbstractContainerpublic MBeanServer getMBeanServer()
MBeanServer this method is needed for backward compatibilitygetMBeanServer in interface ContainergetMBeanServer in class AbstractContainerpublic ObjectName getScopingObjectName()
getScopingObjectName in interface ContainergetScopingObjectName in class AbstractContainerpublic <T> T createComponent(Class<T> clazz, InitParams params) throws Exception
Class with the
given InitParamscreateComponent in interface ContainercreateComponent in class AbstractContainerclazz - the Class of the object to createparams - the parameters to use to create the componentException - if any issue occurs while creating the component.public <T> boolean initializeComponent(T instance)
Injecttrue if at least Inject annotation has been found, false otherwiseprotected 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()
Copyright © 2020 eXo Platform SAS. All Rights Reserved.