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
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 a
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 a
Container which allows eXo to apply
the Inversion of Control (also known as IoC) principles.- Author:
- Tuan Nguyen
- See Also:
- eXo level API
- Provisional
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ExoContainerContextprotected static final org.exoplatform.services.log.Logprotected final ExoContainerprotected final AtomicBooleanFields inherited from class org.exoplatform.container.AbstractContainer
delegate -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidbooleanIndicates whether or not the container can be disposedprotected booleanIndicates whether or not the container can be initializedbooleanIndicates whether or not the container can be startedbooleanIndicates 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.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.getComponentInstance(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 ConfigurationGets theConfigurationManagerfrom the givenExoContainerif it exists, then returns the nestedConfigurationotherwise it returnsnullGives theContextManagerthat has been registeredprotected Collection<ExternalComponentPlugins> Gives all theExternalComponentPluginsthat have not been used,nullif there are all used.Gives the parent container of this container.Returns an unmodifiable set of profiles defined by the value returned by invokingPropertyManager.getProperty(String)with thePropertyManager.RUNTIME_PROFILESproperty.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 voidvoidInitializes the containerbooleanIndicates 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 voidUnregister 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, registerComponentAdapter, registerComponentImplementation, registerComponentInstance, unregisterComponent
-
Field Details
-
stopping
-
LOG
protected static final org.exoplatform.services.log.Log LOG -
context
-
parent
-
-
Constructor Details
-
ExoContainer
public ExoContainer() -
ExoContainer
-
-
Method Details
-
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
- Returns:
- current container profiles, else return default profiles retrieved
by
getProfilesFromProperty()
-
hasProfileInProperty
Indicates whether or not a given profile exists- Parameters:
profileName- the name of the profile to check- Returns:
trueif the profile exists,falseotherwise.
-
hasProfile
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
-
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
-
addContainerLifecylePlugin
-
getConfiguration
Gets theConfigurationManagerfrom the givenExoContainerif it exists, then returns the nestedConfigurationotherwise it returnsnull -
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
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
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
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
- Throws:
ContainerException
-
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
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
This method is equivalent togetComponentInstanceOfType(Class, boolean)withtruefor the parameterautoRegistration -
getComponentInstanceOfType
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
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
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
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
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
-