Package org.exoplatform.container
Class ExoContainer
- java.lang.Object
-
- org.exoplatform.container.AbstractContainer
-
- org.exoplatform.container.ExoContainer
-
- All Implemented Interfaces:
Serializable,Container,Disposable,Startable
- Direct Known Subclasses:
PortalContainer,RootContainer,StandaloneContainer
public class ExoContainer extends AbstractContainer
Created by The eXo Platform SAS
The Exo Container is an object responsible for loading services/components. The eXoContainer class is inherited by all the containers, including RootContainer, PortalContainer, and StandaloneContainer. It itself inherits from aContainerwhich allows eXo to apply the Inversion of Control (also known as IoC) principles.- Author:
- Tuan Nguyen
- See Also:
- Serialized Form
- eXo level API
- Provisional
-
-
Field Summary
Fields Modifier and Type Field Description protected ExoContainerContextcontextprotected static org.exoplatform.services.log.LogLOGprotected ExoContainerparentprotected AtomicBooleanstopping-
Fields inherited from class org.exoplatform.container.AbstractContainer
delegate
-
-
Constructor Summary
Constructors Constructor Description ExoContainer()ExoContainer(ExoContainer parent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddComponentLifecylePlugin(ComponentLifecyclePlugin plugin)voidaddContainerLifecylePlugin(ContainerLifecyclePlugin plugin)booleancanBeDisposed()Indicates whether or not the container can be disposedprotected booleancanBeInitialized()Indicates whether or not the container can be initializedbooleancanBeStarted()Indicates whether or not the container can be startedbooleancanBeStopped()Indicates whether or not the container can be stopped<T> TcreateComponent(Class<T> clazz)Creates a component corresponding to the givenClasswith no parameters This is equivalent to callAbstractContainer.createComponent(Class, InitParams)withnullasInitParamsvoiddispose()Dispose this component.ComponentAdapter<?>getComponentAdapter(Object componentKey)Find a component adapter associated with the specified key.<T> ComponentAdapter<T>getComponentAdapter(Object componentKey, Class<T> bindType)This method is equivalent togetComponentAdapter(Object, Class, boolean)withtruefor the parameterautoRegistration<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)This method is equivalent togetComponentAdapterOfType(Class, boolean)withtruefor the parameterautoRegistration<T> ComponentAdapter<T>getComponentAdapterOfType(Class<T> componentType, boolean autoRegistration)Find a component adapter associated with the specified type.ObjectgetComponentInstance(Object componentKey)Retrieve a component instance registered with a specific key.<T> TgetComponentInstance(Object componentKey, Class<T> bindType)This method is equivalent togetComponentInstance(Object, Class, boolean)withtruefor the parameterautoRegistration<T> TgetComponentInstance(Object componentKey, Class<T> bindType, boolean autoRegistration)Retrieve a component instance registered with a specific key.<T> TgetComponentInstanceOfType(Class<T> componentType)This method is equivalent togetComponentInstanceOfType(Class, boolean)withtruefor the parameterautoRegistration<T> TgetComponentInstanceOfType(Class<T> componentType, boolean autoRegistration)Find a component instance matching the specified type.protected ConfigurationgetConfiguration()Gets theConfigurationManagerfrom the givenExoContainerif it exists, then returns the nestedConfigurationotherwise it returnsnullExoContainerContextgetContext()ContextManagergetContextManager()Gives theContextManagerthat has been registeredprotected Collection<ExternalComponentPlugins>getExternalComponentPluginsUnused()Gives all theExternalComponentPluginsthat have not been used,nullif there are all used.ExoContainergetParent()Gives the parent container of this container.static Set<String>getProfiles()static Set<String>getProfilesFromProperty()Returns an unmodifiable set of profiles defined by the value returned by invokingPropertyManager.getProperty(String)with thePropertyManager.RUNTIME_PROFILESproperty.Set<String>getRegisteredComponentNames()static booleanhasProfile(String profileName)Indicates whether the current container has a given profile.static booleanhasProfileInProperty(String profileName)Indicates whether or not a given profile existsprotected voidinitContainerInternal()voidinitialize()Initializes the containerbooleanisContextManagerLoaded()Indicates whether or not theContextManagerhas already been loaded<T> ComponentAdapter<T>registerComponentImplementation(Class<T> componentImplementation)Register a component using the componentImplementation as key.<T> ComponentAdapter<T>registerComponentInstance(T componentInstance)Register an arbitrary object.voidstart()Start this component.voidstart(boolean init)Starts the containervoidstop()Stop this component.protected voidunregisterAllComponents()Unregister all components from container to avoid keeping instances in memory.-
Methods inherited from class org.exoplatform.container.AbstractContainer
accept, createComponent, getComponentAdapters, getComponentAdaptersOfType, getComponentInstancesOfType, getManagementContext, getMBeanServer, getScopingObjectName, getSuccessor, registerComponentImplementation, registerComponentInstance, unregisterComponent
-
-
-
-
Field Detail
-
stopping
protected final AtomicBoolean stopping
-
LOG
protected static final org.exoplatform.services.log.Log LOG
-
context
protected final ExoContainerContext context
-
parent
protected final ExoContainer parent
-
-
Constructor Detail
-
ExoContainer
public ExoContainer()
-
ExoContainer
public ExoContainer(ExoContainer parent)
-
-
Method Detail
-
getProfilesFromProperty
public static Set<String> getProfilesFromProperty()
Returns an unmodifiable set of profiles defined by the value returned by invokingPropertyManager.getProperty(String)with thePropertyManager.RUNTIME_PROFILESproperty.- Returns:
- the set of profiles
-
getProfiles
public static Set<String> getProfiles()
- Returns:
- current container profiles, else return default profiles retrieved
by
getProfilesFromProperty()
-
hasProfileInProperty
public static boolean hasProfileInProperty(String profileName)
Indicates whether or not a given profile exists- Parameters:
profileName- the name of the profile to check- Returns:
trueif the profile exists,falseotherwise.
-
hasProfile
public static boolean hasProfile(String profileName)
Indicates whether the current container has a given profile.- Parameters:
profileName- profile to check- Returns:
trueif currentExoContainerretrieved fromExoContainerContextwas started with the given profile,falseotherwise.
-
getContext
public ExoContainerContext getContext()
-
initContainerInternal
protected void initContainerInternal()
-
dispose
public void dispose()
Description copied from class:AbstractContainerDispose this component. The component should deallocate all resources. The contract for this method defines a single call at the end of this component's life.- Specified by:
disposein interfaceDisposable- Overrides:
disposein classAbstractContainer
-
start
public void start(boolean init)
Starts the container- Parameters:
init- indicates if the container must be initialized first
-
initialize
public void initialize()
Description copied from class:AbstractContainerInitializes the container- Specified by:
initializein interfaceContainer- Overrides:
initializein classAbstractContainer
-
start
public void start()
Description copied from class:AbstractContainerStart this component. Called initially at the begin of the lifecycle. It can be called again after a stop.- Specified by:
startin interfaceStartable- Overrides:
startin classAbstractContainer
-
stop
public void stop()
Description copied from class:AbstractContainerStop this component. Called near the end of the lifecycle. It can be called again after a further start. ImplementDisposableif you need a single call at the definite end of the lifecycle.- Specified by:
stopin interfaceStartable- Overrides:
stopin classAbstractContainer
-
addComponentLifecylePlugin
public void addComponentLifecylePlugin(ComponentLifecyclePlugin plugin)
-
addContainerLifecylePlugin
public void addContainerLifecylePlugin(ContainerLifecyclePlugin plugin)
-
getConfiguration
protected Configuration getConfiguration()
Gets theConfigurationManagerfrom the givenExoContainerif it exists, then returns the nestedConfigurationotherwise it returnsnull
-
getExternalComponentPluginsUnused
protected Collection<ExternalComponentPlugins> getExternalComponentPluginsUnused()
Gives all theExternalComponentPluginsthat have not been used,nullif there are all used.
-
unregisterAllComponents
protected void unregisterAllComponents()
Unregister all components from container to avoid keeping instances in memory.
-
registerComponentImplementation
public <T> ComponentAdapter<T> registerComponentImplementation(Class<T> componentImplementation) throws ContainerException
Register a component using the componentImplementation as key. Calling this method is equivalent to callingregisterComponentImplementation(componentImplementation, componentImplementation).- Parameters:
componentImplementation- the concrete component class.- Returns:
- the ComponentAdapter that has been associated with this component. In the majority of cases, this return
value can be safely ignored, as one of the
getXXX()methods of theContainerinterface can be used to retrieve a reference to the component later on. - Throws:
ContainerException- if registration fails.
-
registerComponentInstance
public <T> ComponentAdapter<T> registerComponentInstance(T componentInstance) throws ContainerException
Register an arbitrary object. The class of the object will be used as a key. Calling this method is equivalent to calling *registerComponentImplementation(componentImplementation, componentImplementation).- Parameters:
componentInstance- the instance of the component to register- Returns:
- the ComponentAdapter that has been associated with this component. In the majority of cases, this return
value can be safely ignored, as one of the
getXXX()methods of theContainerinterface can be used to retrieve a reference to the component later on. - Throws:
ContainerException- if registration fails.
-
createComponent
public <T> T createComponent(Class<T> clazz) throws Exception
Creates a component corresponding to the givenClasswith no parameters This is equivalent to callAbstractContainer.createComponent(Class, InitParams)withnullasInitParams- Parameters:
clazz- the Class of the object to create- Returns:
- an instance of the component
- Throws:
Exception- if any issue occurs while creating the component.
-
getComponentAdapter
public ComponentAdapter<?> getComponentAdapter(Object componentKey)
Find a component adapter associated with the specified key. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched.- Parameters:
componentKey- the key that the component was registered with.- Returns:
- the component adapter associated with this key, or
nullif no component has been registered for the specified key.
-
getComponentInstance
public Object getComponentInstance(Object componentKey)
Retrieve a component instance registered with a specific key. If a component cannot be found in this container, the parent container (if one exists) will be searched.- Parameters:
componentKey- the key that the component was registered with.- Returns:
- an instantiated component, or
nullif no component has been registered for the specified key.
-
getRegisteredComponentNames
public Set<String> getRegisteredComponentNames() throws ContainerException
- Throws:
ContainerException
-
getParent
public ExoContainer getParent()
Gives the parent container of this container.- Returns:
- a
ExoContainerinstance, ornullif this container does not have a parent.
-
canBeStarted
public boolean canBeStarted()
Indicates whether or not the container can be started- Returns:
trueif it can be started,falseotherwise.
-
canBeStopped
public boolean canBeStopped()
Indicates whether or not the container can be stopped- Returns:
trueif it can be stopped,falseotherwise.
-
canBeDisposed
public boolean canBeDisposed()
Indicates whether or not the container can be disposed- Returns:
trueif it can be disposed,falseotherwise.
-
canBeInitialized
protected boolean canBeInitialized()
Indicates whether or not the container can be initialized- Returns:
trueif it can be initialized,falseotherwise.
-
getContextManager
public ContextManager getContextManager()
Gives theContextManagerthat has been registered- Returns:
- the
ContextManagerrelated to this container,nullotherwise.
-
isContextManagerLoaded
public boolean isContextManagerLoaded()
Indicates whether or not theContextManagerhas already been loaded- Returns:
trueif theContextManagerhas been loaded,falseotherwise.
-
getComponentInstanceOfType
public <T> T getComponentInstanceOfType(Class<T> componentType)
This method is equivalent togetComponentInstanceOfType(Class, boolean)withtruefor the parameterautoRegistration
-
getComponentInstanceOfType
public <T> T getComponentInstanceOfType(Class<T> componentType, boolean autoRegistration)
Find a component instance matching the specified type. If none can be found it will try to auto register the component according to the content of the annotationDefinitionByTypeif the parameterautoRegistrationhas been set totrue.- Specified by:
getComponentInstanceOfTypein interfaceContainer- Overrides:
getComponentInstanceOfTypein classAbstractContainer- Parameters:
componentType- the type of the component.autoRegistration- indicates whether the auto registration should be performed or not- Returns:
- the adapter matching the class.
-
getComponentAdapterOfType
public <T> ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType)
This method is equivalent togetComponentAdapterOfType(Class, boolean)withtruefor the parameterautoRegistration- Parameters:
componentType- the type of the component.- Returns:
- the component adapter associated with this class, or
nullif no component has been registered for the specified key.
-
getComponentAdapterOfType
public <T> ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType, boolean autoRegistration)
Find a component adapter associated with the specified type. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched. If none can be found it will try to auto register the component according to the content of the annotationDefinitionByTypeif the parameterautoRegistrationhas been set totrue.- Specified by:
getComponentAdapterOfTypein interfaceContainer- Overrides:
getComponentAdapterOfTypein classAbstractContainer- Parameters:
componentType- the type of the component.autoRegistration- indicates whether the auto registration should be performed or not- Returns:
- the component adapter associated with this class, or
nullif no component has been registered for the specified key.
-
getComponentInstance
public <T> T getComponentInstance(Object componentKey, Class<T> bindType)
This method is equivalent togetComponentInstance(Object, Class, boolean)withtruefor the parameterautoRegistration- Parameters:
componentKey- the key that the component was registered with.bindType- the expected type of the instance if one can be found.- Returns:
- an instantiated component, or
nullif no component has been registered for the specified key.
-
getComponentInstance
public <T> T getComponentInstance(Object componentKey, Class<T> bindType, boolean autoRegistration)
Retrieve a component instance registered with a specific key. If a component cannot be found in this container, the parent container (if one exists) will be searched. If none can be found and the parameterautoRegistrationhas been set totrue, it will try to auto register the component according to the content of:- The annotation
DefinitionByTypeif thecomponentKeyis a class - The annotation
DefinitionByNameif thecomponentKeyis a string - The annotation
DefinitionByQualifierif thecomponentKeyis a qualifier
- Specified by:
getComponentInstancein interfaceContainer- Overrides:
getComponentInstancein classAbstractContainer- Parameters:
componentKey- 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- Returns:
- an instantiated component, or
nullif no component has been registered for the specified key.
- The annotation
-
getComponentAdapter
public <T> ComponentAdapter<T> getComponentAdapter(Object componentKey, Class<T> bindType)
This method is equivalent togetComponentAdapter(Object, Class, boolean)withtruefor the parameterautoRegistration- Parameters:
componentKey- the key that the component was registered with.bindType- the expected raw type of the adapter if one can be found.- Returns:
- the component adapter associated with this key, or
nullif no component has been registered for the specified key.
-
getComponentAdapter
public <T> ComponentAdapter<T> getComponentAdapter(Object componentKey, Class<T> bindType, boolean autoRegistration)
Find a component adapter associated with the specified key. If a component adapter cannot be found in this container, the parent container (if one exists) will be searched. If none can be found and the parameterautoRegistrationhas been set totrue, it will try to auto register the component according to the content of:- The annotation
DefinitionByTypeif thecomponentKeyis a class - The annotation
DefinitionByNameif thecomponentKeyis a string - The annotation
DefinitionByQualifierif thecomponentKeyis a qualifier
- Specified by:
getComponentAdapterin interfaceContainer- Overrides:
getComponentAdapterin classAbstractContainer- Parameters:
componentKey- 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- Returns:
- the component adapter associated with this key, or
nullif no component has been registered for the specified key.
- The annotation
-
-