Class ComponentManagerImpl
- All Implemented Interfaces:
ComponentManager
- Author:
- Bogdan Stefanescu, Florent Guillaume
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
protected static class
TODO we use for now the same sorter as OSGIRuntimeService - should be improved later.protected static class
Nested classes/interfaces inherited from interface org.nuxeo.runtime.model.ComponentManager
ComponentManager.Listener
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected DescriptorRegistry
protected boolean
protected final ConcurrentMap<ComponentName,
Set<Extension>> protected ComponentRegistry
protected ComponentRegistry
protected List<RegistrationInfo>
The list of standby components (sorted according to the start order) This list is null if component were not yet started or not yet put in standby When putting components in standby all started components are stopped and thestarted
list is assigned tostandby
list then thestarted
field is nullified.protected List<RegistrationInfo>
The list of started components (sorted according to the start order).protected ComponentManagerImpl.Stash
A list of registrations that were deployed while the manager was started. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Activates the givenRegistrationInfo
.protected List<RegistrationInfo>
Activate all the resolved components and return the list of activated components in the activation ordervoid
addComponentListener
(ComponentListener listener) Adds a component listener.void
addListener
(ComponentManager.Listener listener) Add a listener to be notified on manager actions like start / stop components.protected void
protected void
deactivateComponent
(RegistrationInfo ri, boolean isShutdown) Deactivates the givenRegistrationInfo
.protected void
deactivateComponents
(boolean isShutdown) Deactivate all active components in the reverse resolve orderGets the pending extensions by component.getComponent
(ComponentName name) Gets object instance managed by the named component.getComponentProvidingService
(Class<?> serviceClass) Gets the component that provides the given service.Returns the missing registrations, linked to missing target extension points.Get the needed component names.Get the pending extensions.Gets the pending registrations and their dependencies.Gets the component if there is one having the given name.Gets the registered components.protected Collection<ComponentName>
getRegistrations
(int state) final ComponentRegistry
Gets the resolved component names in the order they were resolved<T> T
getService
(Class<T> serviceClass) Gets the service of type serviceClass if such a service was declared by a resolved runtime component.String[]
Get the list of all registered service names An empty array is returned if no registered services are found.Gets the components that fail on applicationStarted notificationprotected static void
handleError
(String message, String componentName, Exception e) boolean
Tests whether components were deployed over the initial snapshot (i.e. the actual registry differs from the snapshot) If no snapshot was done returns false.boolean
Check if a snapshot was doneprotected boolean
Instantiates the givenRegistrationInfo
.boolean
isRegistered
(ComponentName name) Checks whether or not a component with the given name was registered.boolean
Tests whether the components are running.boolean
Tests whether the components are in standby mode.boolean
Tests whether the components were already started.boolean
Tests if the stash is emptystatic void
boolean
refresh()
Shortcut for refresh(false).boolean
refresh
(boolean reset) Refresh the registry using stashed registrations if any.void
Handles the registration of the given registration info.void
registerExtension
(Extension extension) void
void
removeComponentListener
(ComponentListener listener) Removes a component listener.void
removeListener
(ComponentManager.Listener listener) Remove the component manager listener previously added byComponentManager.addListener(Listener)
.boolean
reset()
Reset the registry to the last snapshot if any and stop the components (if they are currently started).void
restart
(boolean reset) Optionally reset the registry to the last snapshot and restart the components.protected void
void
resume()
Start standby components.protected static void
runWihtinTimeout
(long timeout, TimeUnit unit, String warn, Runnable runnable) Log a warning message if the timeout is reached while executing the given runnable.void
setBlacklist
(Set<String> blacklist) protected boolean
Tests whether new registrations should be stashed at registration time.void
shutdown()
Shuts down the component registry.int
size()
Gets the number of registered objects in this registry.void
snapshot()
Make a snapshot of the component registry.void
standby()
Stop all started components but don't deactivate them.void
standby
(int timeoutInSeconds) Same asComponentManager.standby()
but log a warning if the timeout is reached while stopping componentsboolean
start()
Activate and start all resolved components.protected void
Starts the givenRegistrationInfo
.protected void
startComponents
(List<RegistrationInfo> ris, boolean isResume) Start all given componentsboolean
stop()
Stop and deactivate all resolved components.void
stop
(int timeoutInSeconds) Same asComponentManager.stop()
but log a warning if the timeout is reached while stopping componentsprotected void
Stops the givenRegistrationInfo
.protected void
stopComponents
(boolean isStandby) Stop all started components.void
unregister
(ComponentName name) Unregisters a component given its name.void
unregister
(RegistrationInfo regInfo) Handles the unregistration of the given registration info.void
unregisterExtension
(Extension extension) void
void
unstash()
Apply the stash if not empty.protected void
writeDevMetrics
(Watch watch, String type)
-
Field Details
-
pendingExtensions
-
blacklist
-
started
The list of started components (sorted according to the start order). This list is null if the components were not yet started or were stopped- Since:
- 9.2
-
standby
The list of standby components (sorted according to the start order) This list is null if component were not yet started or not yet put in standby When putting components in standby all started components are stopped and thestarted
list is assigned tostandby
list then thestarted
field is nullified. When resuming standby components the started list is restored from the standby list and the standby field is nullified- Since:
- 9.2
-
stash
A list of registrations that were deployed while the manager was started.- Since:
- 9.2
-
registry
- Since:
- 9.2
-
snapshot
- Since:
- 9.2
-
descriptors
- Since:
- 10.3
-
isFlushingStash
protected volatile boolean isFlushingStash- Since:
- 9.2
-
changed
protected volatile boolean changed- Since:
- 9.2
-
-
Constructor Details
-
ComponentManagerImpl
-
-
Method Details
-
getDescriptors
- Since:
- 10.3
-
getRegistry
- Since:
- 9.2
-
getRegistrations
Description copied from interface:ComponentManager
Gets the registered components.- Specified by:
getRegistrations
in interfaceComponentManager
- Returns:
- a read-only collection of components
-
getResolvedRegistrations
Description copied from interface:ComponentManager
Gets the resolved component names in the order they were resolved- Specified by:
getResolvedRegistrations
in interfaceComponentManager
- Since:
- 9.2
-
getPendingRegistrations
Description copied from interface:ComponentManager
Gets the pending registrations and their dependencies.- Specified by:
getPendingRegistrations
in interfaceComponentManager
- Returns:
- the pending registrations
-
getMissingRegistrations
Description copied from interface:ComponentManager
Returns the missing registrations, linked to missing target extension points.- Specified by:
getMissingRegistrations
in interfaceComponentManager
-
getNeededRegistrations
Get the needed component names. The returned set is not a copy -
getPendingExtensions
Get the pending extensions. The returned set is not a copy -
getRegistrationInfo
Description copied from interface:ComponentManager
Gets the component if there is one having the given name.- Specified by:
getRegistrationInfo
in interfaceComponentManager
- Parameters:
name
- the component name- Returns:
- the component if any was registered with that name, null otherwise
-
isRegistered
Description copied from interface:ComponentManager
Checks whether or not a component with the given name was registered.- Specified by:
isRegistered
in interfaceComponentManager
- Parameters:
name
- the object name- Returns:
- true if an object with the given name was registered, false otherwise
-
size
public int size()Description copied from interface:ComponentManager
Gets the number of registered objects in this registry.- Specified by:
size
in interfaceComponentManager
- Returns:
- the number of registered objects
-
getComponent
Description copied from interface:ComponentManager
Gets object instance managed by the named component.- Specified by:
getComponent
in interfaceComponentManager
- Parameters:
name
- the object name- Returns:
- the object instance if any. may be null
-
shutdown
public void shutdown()Description copied from interface:ComponentManager
Shuts down the component registry.This unregisters all objects registered in this registry.
- Specified by:
shutdown
in interfaceComponentManager
-
getBlacklist
- Specified by:
getBlacklist
in interfaceComponentManager
-
setBlacklist
- Specified by:
setBlacklist
in interfaceComponentManager
-
register
Description copied from interface:ComponentManager
Handles the registration of the given registration info.This is called by the main registry when all dependencies of this registration info were solved and the object can be registered.
If true is returned, the object will be added to the main registry under the name given in RegistrationInfo.
- Specified by:
register
in interfaceComponentManager
- Parameters:
ri
- the registration info
-
unregister
Description copied from interface:ComponentManager
Handles the unregistration of the given registration info.This is called by the main registry when the object is unregistered.
If true is returned, the object will be removed from the main registry.
- Specified by:
unregister
in interfaceComponentManager
- Parameters:
regInfo
- the registration info
-
unregister
Description copied from interface:ComponentManager
Unregisters a component given its name.- Specified by:
unregister
in interfaceComponentManager
- Parameters:
name
- the component name
-
addComponentListener
Description copied from interface:ComponentManager
Adds a component listener.Does nothing if the given listener is already registered.
- Specified by:
addComponentListener
in interfaceComponentManager
- Parameters:
listener
- the component listener to add
-
removeComponentListener
Description copied from interface:ComponentManager
Removes a component listener.Does nothing if the given listener is not registered.
- Specified by:
removeComponentListener
in interfaceComponentManager
- Parameters:
listener
- the component listener to remove
-
addListener
Description copied from interface:ComponentManager
Add a listener to be notified on manager actions like start / stop components.- Specified by:
addListener
in interfaceComponentManager
-
removeListener
Description copied from interface:ComponentManager
Remove the component manager listener previously added byComponentManager.addListener(Listener)
. If the listener were not added then nothing is done.- Specified by:
removeListener
in interfaceComponentManager
-
getComponentProvidingService
Description copied from interface:ComponentManager
Gets the component that provides the given service.- Specified by:
getComponentProvidingService
in interfaceComponentManager
- Parameters:
serviceClass
- the service class- Returns:
- the component or null if none
-
getService
Description copied from interface:ComponentManager
Gets the service of type serviceClass if such a service was declared by a resolved runtime component.If the component is not yet activated it will be prior to return the service.
- Specified by:
getService
in interfaceComponentManager
- Type Parameters:
T
- the service type- Parameters:
serviceClass
- the service class- Returns:
- the service object
-
getActivatingRegistrations
Description copied from interface:ComponentManager
Gets the pending extensions by component.- Specified by:
getActivatingRegistrations
in interfaceComponentManager
- Returns:
- the pending extensions
-
getStartFailureRegistrations
Description copied from interface:ComponentManager
Gets the components that fail on applicationStarted notification- Specified by:
getStartFailureRegistrations
in interfaceComponentManager
-
getRegistrations
-
registerExtension
-
unregisterExtension
-
loadContributions
-
registerServices
-
unregisterServices
-
getServices
Description copied from interface:ComponentManager
Get the list of all registered service names An empty array is returned if no registered services are found.- Specified by:
getServices
in interfaceComponentManager
- Returns:
- an array of registered service.
-
handleError
-
activateComponents
Activate all the resolved components and return the list of activated components in the activation order- Returns:
- the list of the activated components in the activation order
- Since:
- 9.2
-
instantiateComponent
Instantiates the givenRegistrationInfo
. This step will instantiate the component.Allows registering listeners on ComponentManager at component instantiation, before all components activation.
Should be called before
activateComponent(RegistrationInfo)
.- Returns:
- false in case of error during instantiation, true otherwise.
- Since:
- 11.3.
-
activateComponent
Activates the givenRegistrationInfo
. This step will activate the component, register extensions and then register services.- Since:
- 9.3
-
deactivateComponents
protected void deactivateComponents(boolean isShutdown) Deactivate all active components in the reverse resolve order- Since:
- 9.2
-
deactivateComponent
Deactivates the givenRegistrationInfo
. This step will unregister the services, unregister the extensions and then deactivate the component.- Since:
- 9.3
-
startComponents
Start all given components- Since:
- 9.2
-
startComponent
Starts the givenRegistrationInfo
. This step will start the component.- Since:
- 9.3
-
stopComponents
protected void stopComponents(boolean isStandby) Stop all started components. Stopping components is done in reverse start order.- Since:
- 9.2
-
stopComponent
Stops the givenRegistrationInfo
. This step will stop the component.- Throws:
InterruptedException
- Since:
- 9.3
-
start
public boolean start()Description copied from interface:ComponentManager
Activate and start all resolved components. If components were already started do nothing.- Specified by:
start
in interfaceComponentManager
- Returns:
- false if components were already started, true otherwise
-
stop
public boolean stop()Description copied from interface:ComponentManager
Stop and deactivate all resolved components. If components were not yet started do nothing- Specified by:
stop
in interfaceComponentManager
- Returns:
- false if components were not yet started, true otherwise
-
stop
public void stop(int timeoutInSeconds) Description copied from interface:ComponentManager
Same asComponentManager.stop()
but log a warning if the timeout is reached while stopping components- Specified by:
stop
in interfaceComponentManager
-
standby
public void standby()Description copied from interface:ComponentManager
Stop all started components but don't deactivate them. After calling this method you can safely contribute new extensions (i.e. modify extension registries).If any components were previously started do nothing
- Specified by:
standby
in interfaceComponentManager
-
standby
public void standby(int timeoutInSeconds) Description copied from interface:ComponentManager
Same asComponentManager.standby()
but log a warning if the timeout is reached while stopping components- Specified by:
standby
in interfaceComponentManager
-
resume
public void resume()Description copied from interface:ComponentManager
Start standby components. If components are not in standby mode the it does nothing.- Specified by:
resume
in interfaceComponentManager
-
isStarted
public boolean isStarted()Description copied from interface:ComponentManager
Tests whether the components were already started.- Specified by:
isStarted
in interfaceComponentManager
- Returns:
- true if components are started, false
-
isStandby
public boolean isStandby()Description copied from interface:ComponentManager
Tests whether the components are in standby mode. That means they were started and then stopped - waiting to be started again.When putting components in standby they are stopped but not deactivated. You start back the standby components by calling #resume
While in standby mode the component manager remains in running state.
- Specified by:
isStandby
in interfaceComponentManager
-
isRunning
public boolean isRunning()Description copied from interface:ComponentManager
Tests whether the components are running. That means they are either started either in standby mode.- Specified by:
isRunning
in interfaceComponentManager
-
hasSnapshot
public boolean hasSnapshot()Description copied from interface:ComponentManager
Check if a snapshot was done- Specified by:
hasSnapshot
in interfaceComponentManager
- Returns:
- true if a snapshot already exists, false otherwise
-
hasChanged
public boolean hasChanged()Description copied from interface:ComponentManager
Tests whether components were deployed over the initial snapshot (i.e. the actual registry differs from the snapshot) If no snapshot was done returns false.- Specified by:
hasChanged
in interfaceComponentManager
-
snapshot
public void snapshot()Description copied from interface:ComponentManager
Make a snapshot of the component registry. When calling restart- Specified by:
snapshot
in interfaceComponentManager
-
isStashEmpty
public boolean isStashEmpty()Description copied from interface:ComponentManager
Tests if the stash is empty- Specified by:
isStashEmpty
in interfaceComponentManager
-
restart
public void restart(boolean reset) Description copied from interface:ComponentManager
Optionally reset the registry to the last snapshot and restart the components.When restarting components all components will be stopped, deactivated and re-instantiated. It means that all references to components before a restart will become invalid after the restart.
If no snapshot was created then the components will be restarted without changing the registry.
If the
reset
argument is true then the registry will be reverted to the last snapshot before starting the components.- Specified by:
restart
in interfaceComponentManager
- Parameters:
reset
- whether or not to revert to the last snapshot
-
reset
public boolean reset()Description copied from interface:ComponentManager
Reset the registry to the last snapshot if any and stop the components (if they are currently started). After a reset all the components are stopped so we can contribute new components if needed. You must callComponentManager.start()
to start again the components- Specified by:
reset
in interfaceComponentManager
- Returns:
- true if the components were stopped, false otherwise
-
refresh
public boolean refresh()Description copied from interface:ComponentManager
Shortcut for refresh(false).- Specified by:
refresh
in interfaceComponentManager
- See Also:
-
refresh
public boolean refresh(boolean reset) Description copied from interface:ComponentManager
Refresh the registry using stashed registrations if any. If thereset
argument is true then the registry will be reverted to the last snapshot before applying the stash.If the stash is empty it does nothing and return true, otherwise it will:
- stop the components (if they are started)
- revert to the last snapshot (if reset flag is true)
- apply the stash (the stash will remain empty after this operation)
- start the components (if they was started)
- Specified by:
refresh
in interfaceComponentManager
- Parameters:
reset
- whether or not to revert to the last snapshot- Returns:
- false if stash is empty and nothing was done, true otherwise
-
restoreSnapshot
protected void restoreSnapshot() -
shouldStash
protected boolean shouldStash()Tests whether new registrations should be stashed at registration time. If the component manager was started then new components should be stashed otherwise they can be registered.TODO: current implementation is stashing after the start completion. Should we also stashing while start is in progress?
-
applyStash
-
unstash
public void unstash()Description copied from interface:ComponentManager
Apply the stash if not empty. This is a low level operation and may not be safe to call when the component manager is runningComponentManager.isRunning()
.For compatibility reasons (to be able to emulate the old hot deploy mechanism or to speed up tests) this method will force a registry refresh in all 3 component manager states: stopped, standby, started.
Usually you should apply the stash by calling
ComponentManager.refresh()
which is similar tostop(); [restoreSnapshot();] unstash(); start();
- Specified by:
unstash
in interfaceComponentManager
-
writeDevMetrics
-
runWihtinTimeout
protected static void runWihtinTimeout(long timeout, TimeUnit unit, String warn, Runnable runnable) throws InterruptedException Log a warning message if the timeout is reached while executing the given runnable.- Throws:
InterruptedException
-