Class ComponentManagerImpl
- java.lang.Object
-
- org.nuxeo.runtime.model.impl.ComponentManagerImpl
-
- All Implemented Interfaces:
ComponentManager
public class ComponentManagerImpl extends Object implements ComponentManager
- Author:
- Bogdan Stefanescu, Florent Guillaume
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classComponentManagerImpl.Listenersprotected static classComponentManagerImpl.RIApplicationStartedComparatorTODO we use for now the same sorter as OSGIRuntimeService - should be improved later.protected static classComponentManagerImpl.Stash-
Nested classes/interfaces inherited from interface org.nuxeo.runtime.model.ComponentManager
ComponentManager.Listener
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<String>blacklistprotected booleanchangedprotected DescriptorRegistrydescriptorsprotected booleanisFlushingStashprotected ConcurrentMap<ComponentName,Set<Extension>>pendingExtensionsprotected ComponentRegistryregistryprotected ComponentRegistrysnapshotprotected List<RegistrationInfo>standbyThe 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 thestartedlist is assigned tostandbylist then thestartedfield is nullified.protected List<RegistrationInfo>startedThe list of started components (sorted according to the start order).protected ComponentManagerImpl.StashstashA list of registrations that were deployed while the manager was started.
-
Constructor Summary
Constructors Constructor Description ComponentManagerImpl(RuntimeService runtime)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidactivateComponent(RegistrationInfo ri)Activates the givenRegistrationInfo.protected List<RegistrationInfo>activateComponents()Activate all the resolved components and return the list of activated components in the activation ordervoidaddComponentListener(ComponentListener listener)Adds a component listener.voidaddListener(ComponentManager.Listener listener)Add a listener to be notified on manager actions like start / stop components.protected voidapplyStash(ComponentManagerImpl.Stash stash)protected voiddeactivateComponent(RegistrationInfo ri, boolean isShutdown)Deactivates the givenRegistrationInfo.protected voiddeactivateComponents(boolean isShutdown)Deactivate all active components in the reverse resolve orderCollection<ComponentName>getActivatingRegistrations()Gets the pending extensions by component.Set<String>getBlacklist()ComponentInstancegetComponent(ComponentName name)Gets object instance managed by the named component.ComponentInstancegetComponentProvidingService(Class<?> serviceClass)Gets the component that provides the given service.DescriptorRegistrygetDescriptors()Map<ComponentName,Set<Extension>>getMissingRegistrations()Returns the missing registrations, linked to missing target extension points.Set<ComponentName>getNeededRegistrations()Get the needed component names.Set<Extension>getPendingExtensions(ComponentName name)Get the pending extensions.Map<ComponentName,Set<ComponentName>>getPendingRegistrations()Gets the pending registrations and their dependencies.RegistrationInfogetRegistrationInfo(ComponentName name)Gets the component if there is one having the given name.Collection<RegistrationInfo>getRegistrations()Gets the registered components.protected Collection<ComponentName>getRegistrations(int state)ComponentRegistrygetRegistry()Collection<ComponentName>getResolvedRegistrations()Gets the resolved component names in the order they were resolved<T> TgetService(Class<T> serviceClass)Gets the service of type serviceClass if such a service was declared by a resolved runtime component.String[]getServices()Get the list of all registered service names An empty array is returned if no registered services are found.Collection<ComponentName>getStartFailureRegistrations()Gets the components that fail on applicationStarted notificationprotected static voidhandleError(String message, String componentName, Exception e)booleanhasChanged()Tests whether components were deployed over the initial snapshot (i.e.booleanhasComponentFromLocation(String sourceId)Given a source location tests if a component was deployed from that location
This method was added to support undeploying by location needed by tests.booleanhasSnapshot()Check if a snapshot was doneprotected booleaninstantiateComponent(RegistrationInfo ri)Instantiates the givenRegistrationInfo.booleanisRegistered(ComponentName name)Checks whether or not a component with the given name was registered.booleanisRunning()Tests whether the components are running.booleanisStandby()Tests whether the components are in standby mode.booleanisStarted()Tests whether the components were already started.booleanisStashEmpty()Tests if the stash is emptystatic voidloadContributions(RegistrationInfo ri, Extension xt)booleanrefresh()Shortcut for refresh(false).booleanrefresh(boolean reset)Refresh the registry using stashed registrations if any.voidregister(RegistrationInfo ri)Handles the registration of the given registration info.voidregisterExtension(Extension extension)voidregisterServices(RegistrationInfo ri)voidremoveComponentListener(ComponentListener listener)Removes a component listener.voidremoveListener(ComponentManager.Listener listener)Remove the component manager listener previously added byComponentManager.addListener(Listener).booleanreset()Reset the registry to the last snapshot if any and stop the components (if they are currently started).voidrestart(boolean reset)Optionally reset the registry to the last snapshot and restart the components.protected voidrestoreSnapshot()voidresume()Start standby components.protected static voidrunWihtinTimeout(long timeout, TimeUnit unit, String warn, Runnable runnable)Log a warning message if the timeout is reached while executing the given runnable.voidsetBlacklist(Set<String> blacklist)protected booleanshouldStash()Tests whether new registrations should be stashed at registration time.voidshutdown()Shuts down the component registry.intsize()Gets the number of registered objects in this registry.voidsnapshot()Make a snapshot of the component registry.voidstandby()Stop all started components but don't deactivate them.voidstandby(int timeoutInSeconds)Same asComponentManager.standby()but log a warning if the timeout is reached while stopping componentsbooleanstart()Activate and start all resolved components.protected voidstartComponent(RegistrationInfo ri)Starts the givenRegistrationInfo.protected voidstartComponents(List<RegistrationInfo> ris, boolean isResume)Start all given componentsbooleanstop()Stop and deactivate all resolved components.voidstop(int timeoutInSeconds)Same asComponentManager.stop()but log a warning if the timeout is reached while stopping componentsprotected voidstopComponent(RegistrationInfo ri)Stops the givenRegistrationInfo.protected voidstopComponents(boolean isStandby)Stop all started components.voidunregister(ComponentName name)Unregisters a component given its name.voidunregister(RegistrationInfo regInfo)Handles the unregistration of the given registration info.booleanunregisterByLocation(String sourceId)This method was added only to support unregistering by location which is used by some tests.voidunregisterExtension(Extension extension)voidunregisterServices(RegistrationInfo ri)voidunstash()Apply the stash if not empty.protected voidwriteDevMetrics(Watch watch, String type)
-
-
-
Field Detail
-
pendingExtensions
protected final ConcurrentMap<ComponentName,Set<Extension>> pendingExtensions
-
started
protected volatile List<RegistrationInfo> 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
protected volatile List<RegistrationInfo> 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 thestartedlist is assigned tostandbylist then thestartedfield 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
protected volatile ComponentManagerImpl.Stash stash
A list of registrations that were deployed while the manager was started.- Since:
- 9.2
-
registry
protected volatile ComponentRegistry registry
- Since:
- 9.2
-
snapshot
protected volatile ComponentRegistry snapshot
- Since:
- 9.2
-
descriptors
protected volatile DescriptorRegistry descriptors
- Since:
- 10.3
-
isFlushingStash
protected volatile boolean isFlushingStash
- Since:
- 9.2
-
changed
protected volatile boolean changed
- Since:
- 9.2
-
-
Constructor Detail
-
ComponentManagerImpl
public ComponentManagerImpl(RuntimeService runtime)
-
-
Method Detail
-
getDescriptors
public DescriptorRegistry getDescriptors()
- Since:
- 10.3
-
getRegistry
public final ComponentRegistry getRegistry()
- Since:
- 9.2
-
getRegistrations
public Collection<RegistrationInfo> getRegistrations()
Description copied from interface:ComponentManagerGets the registered components.- Specified by:
getRegistrationsin interfaceComponentManager- Returns:
- a read-only collection of components
-
getResolvedRegistrations
public Collection<ComponentName> getResolvedRegistrations()
Description copied from interface:ComponentManagerGets the resolved component names in the order they were resolved- Specified by:
getResolvedRegistrationsin interfaceComponentManager- Since:
- 9.2
-
getPendingRegistrations
public Map<ComponentName,Set<ComponentName>> getPendingRegistrations()
Description copied from interface:ComponentManagerGets the pending registrations and their dependencies.- Specified by:
getPendingRegistrationsin interfaceComponentManager- Returns:
- the pending registrations
-
getMissingRegistrations
public Map<ComponentName,Set<Extension>> getMissingRegistrations()
Description copied from interface:ComponentManagerReturns the missing registrations, linked to missing target extension points.- Specified by:
getMissingRegistrationsin interfaceComponentManager
-
getNeededRegistrations
public Set<ComponentName> getNeededRegistrations()
Get the needed component names. The returned set is not a copy
-
getPendingExtensions
public Set<Extension> getPendingExtensions(ComponentName name)
Get the pending extensions. The returned set is not a copy
-
getRegistrationInfo
public RegistrationInfo getRegistrationInfo(ComponentName name)
Description copied from interface:ComponentManagerGets the component if there is one having the given name.- Specified by:
getRegistrationInfoin interfaceComponentManager- Parameters:
name- the component name- Returns:
- the component if any was registered with that name, null otherwise
-
isRegistered
public boolean isRegistered(ComponentName name)
Description copied from interface:ComponentManagerChecks whether or not a component with the given name was registered.- Specified by:
isRegisteredin 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:ComponentManagerGets the number of registered objects in this registry.- Specified by:
sizein interfaceComponentManager- Returns:
- the number of registered objects
-
getComponent
public ComponentInstance getComponent(ComponentName name)
Description copied from interface:ComponentManagerGets object instance managed by the named component.- Specified by:
getComponentin interfaceComponentManager- Parameters:
name- the object name- Returns:
- the object instance if any. may be null
-
shutdown
public void shutdown()
Description copied from interface:ComponentManagerShuts down the component registry.This unregisters all objects registered in this registry.
- Specified by:
shutdownin interfaceComponentManager
-
getBlacklist
public Set<String> getBlacklist()
- Specified by:
getBlacklistin interfaceComponentManager
-
setBlacklist
public void setBlacklist(Set<String> blacklist)
- Specified by:
setBlacklistin interfaceComponentManager
-
register
public void register(RegistrationInfo ri)
Description copied from interface:ComponentManagerHandles 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:
registerin interfaceComponentManager- Parameters:
ri- the registration info
-
unregister
public void unregister(RegistrationInfo regInfo)
Description copied from interface:ComponentManagerHandles 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:
unregisterin interfaceComponentManager- Parameters:
regInfo- the registration info
-
unregister
public void unregister(ComponentName name)
Description copied from interface:ComponentManagerUnregisters a component given its name.- Specified by:
unregisterin interfaceComponentManager- Parameters:
name- the component name
-
unregisterByLocation
public boolean unregisterByLocation(String sourceId)
Description copied from interface:ComponentManagerThis method was added only to support unregistering by location which is used by some tests. Removing by location should be managed at a higher level (it is useful only for tests) and this method should be removed- Specified by:
unregisterByLocationin interfaceComponentManager- Parameters:
sourceId- the location from where the component was deployed- Returns:
- false if no component was registered from that location, true otherwise
- See Also:
for more on this
-
hasComponentFromLocation
public boolean hasComponentFromLocation(String sourceId)
Description copied from interface:ComponentManagerGiven a source location tests if a component was deployed from that location
This method was added to support undeploying by location needed by tests. Should be removed and a test specific helper implemented to support locations- Specified by:
hasComponentFromLocationin interfaceComponentManager
-
addComponentListener
public void addComponentListener(ComponentListener listener)
Description copied from interface:ComponentManagerAdds a component listener.Does nothing if the given listener is already registered.
- Specified by:
addComponentListenerin interfaceComponentManager- Parameters:
listener- the component listener to add
-
removeComponentListener
public void removeComponentListener(ComponentListener listener)
Description copied from interface:ComponentManagerRemoves a component listener.Does nothing if the given listener is not registered.
- Specified by:
removeComponentListenerin interfaceComponentManager- Parameters:
listener- the component listener to remove
-
addListener
public void addListener(ComponentManager.Listener listener)
Description copied from interface:ComponentManagerAdd a listener to be notified on manager actions like start / stop components.- Specified by:
addListenerin interfaceComponentManager
-
removeListener
public void removeListener(ComponentManager.Listener listener)
Description copied from interface:ComponentManagerRemove the component manager listener previously added byComponentManager.addListener(Listener). If the listener were not added then nothing is done.- Specified by:
removeListenerin interfaceComponentManager
-
getComponentProvidingService
public ComponentInstance getComponentProvidingService(Class<?> serviceClass)
Description copied from interface:ComponentManagerGets the component that provides the given service.- Specified by:
getComponentProvidingServicein interfaceComponentManager- Parameters:
serviceClass- the service class- Returns:
- the component or null if none
-
getService
public <T> T getService(Class<T> serviceClass)
Description copied from interface:ComponentManagerGets 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:
getServicein interfaceComponentManager- Type Parameters:
T- the service type- Parameters:
serviceClass- the service class- Returns:
- the service object
-
getActivatingRegistrations
public Collection<ComponentName> getActivatingRegistrations()
Description copied from interface:ComponentManagerGets the pending extensions by component.- Specified by:
getActivatingRegistrationsin interfaceComponentManager- Returns:
- the pending extensions
-
getStartFailureRegistrations
public Collection<ComponentName> getStartFailureRegistrations()
Description copied from interface:ComponentManagerGets the components that fail on applicationStarted notification- Specified by:
getStartFailureRegistrationsin interfaceComponentManager
-
getRegistrations
protected Collection<ComponentName> getRegistrations(int state)
-
registerExtension
public void registerExtension(Extension extension)
-
unregisterExtension
public void unregisterExtension(Extension extension)
-
loadContributions
public static void loadContributions(RegistrationInfo ri, Extension xt)
-
registerServices
public void registerServices(RegistrationInfo ri)
-
unregisterServices
public void unregisterServices(RegistrationInfo ri)
-
getServices
public String[] getServices()
Description copied from interface:ComponentManagerGet the list of all registered service names An empty array is returned if no registered services are found.- Specified by:
getServicesin interfaceComponentManager- Returns:
- an array of registered service.
-
activateComponents
protected List<RegistrationInfo> 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
protected boolean instantiateComponent(RegistrationInfo ri)
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
protected void activateComponent(RegistrationInfo ri)
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
protected void deactivateComponent(RegistrationInfo ri, boolean isShutdown)
Deactivates the givenRegistrationInfo. This step will unregister the services, unregister the extensions and then deactivate the component.- Since:
- 9.3
-
startComponents
protected void startComponents(List<RegistrationInfo> ris, boolean isResume)
Start all given components- Since:
- 9.2
-
startComponent
protected void startComponent(RegistrationInfo ri)
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
protected void stopComponent(RegistrationInfo ri) throws InterruptedException
Stops the givenRegistrationInfo. This step will stop the component.- Throws:
InterruptedException- Since:
- 9.3
-
start
public boolean start()
Description copied from interface:ComponentManagerActivate and start all resolved components. If components were already started do nothing.- Specified by:
startin interfaceComponentManager- Returns:
- false if components were already started, true otherwise
-
stop
public boolean stop()
Description copied from interface:ComponentManagerStop and deactivate all resolved components. If components were not yet started do nothing- Specified by:
stopin interfaceComponentManager- Returns:
- false if components were not yet started, true otherwise
-
stop
public void stop(int timeoutInSeconds)
Description copied from interface:ComponentManagerSame asComponentManager.stop()but log a warning if the timeout is reached while stopping components- Specified by:
stopin interfaceComponentManager
-
standby
public void standby()
Description copied from interface:ComponentManagerStop 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:
standbyin interfaceComponentManager
-
standby
public void standby(int timeoutInSeconds)
Description copied from interface:ComponentManagerSame asComponentManager.standby()but log a warning if the timeout is reached while stopping components- Specified by:
standbyin interfaceComponentManager
-
resume
public void resume()
Description copied from interface:ComponentManagerStart standby components. If components are not in standby mode the it does nothing.- Specified by:
resumein interfaceComponentManager
-
isStarted
public boolean isStarted()
Description copied from interface:ComponentManagerTests whether the components were already started.- Specified by:
isStartedin interfaceComponentManager- Returns:
- true if components are started, false
-
isStandby
public boolean isStandby()
Description copied from interface:ComponentManagerTests 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:
isStandbyin interfaceComponentManager
-
isRunning
public boolean isRunning()
Description copied from interface:ComponentManagerTests whether the components are running. That means they are either started either in standby mode.- Specified by:
isRunningin interfaceComponentManager
-
hasSnapshot
public boolean hasSnapshot()
Description copied from interface:ComponentManagerCheck if a snapshot was done- Specified by:
hasSnapshotin interfaceComponentManager- Returns:
- true if a snapshot already exists, false otherwise
-
hasChanged
public boolean hasChanged()
Description copied from interface:ComponentManagerTests 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:
hasChangedin interfaceComponentManager
-
snapshot
public void snapshot()
Description copied from interface:ComponentManagerMake a snapshot of the component registry. When calling restart- Specified by:
snapshotin interfaceComponentManager
-
isStashEmpty
public boolean isStashEmpty()
Description copied from interface:ComponentManagerTests if the stash is empty- Specified by:
isStashEmptyin interfaceComponentManager
-
restart
public void restart(boolean reset)
Description copied from interface:ComponentManagerOptionally 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
resetargument is true then the registry will be reverted to the last snapshot before starting the components.- Specified by:
restartin interfaceComponentManager- Parameters:
reset- whether or not to revert to the last snapshot
-
reset
public boolean reset()
Description copied from interface:ComponentManagerReset 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:
resetin interfaceComponentManager- Returns:
- true if the components were stopped, false otherwise
-
refresh
public boolean refresh()
Description copied from interface:ComponentManagerShortcut for refresh(false).- Specified by:
refreshin interfaceComponentManager- See Also:
ComponentManager.refresh(boolean)
-
refresh
public boolean refresh(boolean reset)
Description copied from interface:ComponentManagerRefresh the registry using stashed registrations if any. If theresetargument 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:
refreshin 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
protected void applyStash(ComponentManagerImpl.Stash stash)
-
unstash
public void unstash()
Description copied from interface:ComponentManagerApply 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:
unstashin interfaceComponentManager
-
runWihtinTimeout
protected static void runWihtinTimeout(long timeout, TimeUnit unit, String warn, Runnable runnable) throws InterruptedExceptionLog a warning message if the timeout is reached while executing the given runnable.- Throws:
InterruptedException
-
-