public class ComponentManagerImpl extends Object implements ComponentManager
| Modifier and Type | Class and Description |
|---|---|
protected class |
ComponentManagerImpl.Listeners |
protected static class |
ComponentManagerImpl.RIApplicationStartedComparator
TODO we use for now the same sorter as OSGIRuntimeService - should be improved later.
|
protected static class |
ComponentManagerImpl.Stash |
ComponentManager.Listener| Modifier and Type | Field and Description |
|---|---|
protected Set<String> |
blacklist |
protected boolean |
changed |
protected boolean |
isFlushingStash |
protected ConcurrentMap<ComponentName,Set<Extension>> |
pendingExtensions |
protected ComponentRegistry |
registry |
protected ComponentRegistry |
snapshot |
protected 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 the
started list is assigned to standby list then the started field is nullified. |
protected List<RegistrationInfo> |
started
The list of started components (sorted according to the start order).
|
protected ComponentManagerImpl.Stash |
stash
A list of registrations that were deployed while the manager was started.
|
| Constructor and Description |
|---|
ComponentManagerImpl(RuntimeService runtime) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
activateComponent(RegistrationInfo ri)
Activates the given
RegistrationInfo. |
protected List<RegistrationInfo> |
activateComponents()
Activate all the resolved components and return the list of activated components in the activation order
|
void |
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 |
applyStash(ComponentManagerImpl.Stash stash) |
protected void |
deactivateComponent(RegistrationInfo ri,
boolean isShutdown)
Deactivates the given
RegistrationInfo. |
protected void |
deactivateComponents(boolean isShutdown)
Deactivate all active components in the reverse resolve order
|
Collection<ComponentName> |
getActivatingRegistrations()
Gets the pending extensions by component.
|
Set<String> |
getBlacklist() |
ComponentInstance |
getComponent(ComponentName name)
Gets object instance managed by the named component.
|
ComponentInstance |
getComponentProvidingService(Class<?> serviceClass)
Gets the component that provides the given service.
|
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.
|
RegistrationInfo |
getRegistrationInfo(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) |
ComponentRegistry |
getRegistry() |
Collection<ComponentName> |
getResolvedRegistrations()
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[] |
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 notification
|
protected static void |
handleError(String message,
Exception e) |
boolean |
hasChanged()
Tests whether components were deployed over the initial snapshot (i.e.
|
boolean |
hasComponentFromLocation(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. |
boolean |
hasSnapshot()
Check if a snapshot was done
|
boolean |
isRegistered(ComponentName name)
Checks whether or not a component with the given name was registered.
|
boolean |
isRunning()
Tests whether the components are running.
|
boolean |
isStandby()
Tests whether the components are in standby mode.
|
boolean |
isStarted()
Tests whether the components were already started.
|
boolean |
isStashEmpty()
Tests if the stash is empty
|
static void |
loadContributions(RegistrationInfo ri,
Extension xt) |
boolean |
refresh()
Shortcut for refresh(false).
|
boolean |
refresh(boolean reset)
Refresh the registry using stashed registrations if any.
|
void |
register(RegistrationInfo ri)
Handles the registration of the given registration info.
|
void |
registerExtension(Extension extension) |
void |
registerServices(RegistrationInfo ri) |
void |
removeComponentListener(ComponentListener listener)
Removes a component listener.
|
void |
removeListener(ComponentManager.Listener listener)
Remove the component manager listener previously added by
ComponentManager.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 |
restoreSnapshot() |
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 |
shouldStash()
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 as
ComponentManager.standby() but log a warning if the timeout is reached while stopping components |
boolean |
start()
Activate and start all resolved components.
|
protected void |
startComponent(RegistrationInfo ri)
Starts the given
RegistrationInfo. |
protected void |
startComponents(List<RegistrationInfo> ris,
boolean isResume)
Start all given components
|
boolean |
stop()
Stop and deactivate all resolved components.
|
void |
stop(int timeoutInSeconds)
Same as
ComponentManager.stop() but log a warning if the timeout is reached while stopping components |
protected void |
stopComponent(RegistrationInfo ri)
Stops the given
RegistrationInfo. |
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.
|
boolean |
unregisterByLocation(String sourceId)
This method was added only to support unregistering by location which is used by some tests.
|
void |
unregisterExtension(Extension extension) |
void |
unregisterServices(RegistrationInfo ri) |
void |
unstash()
Apply the stash if not empty.
|
protected void |
writeDevMetrics(Watch watch,
String type) |
protected final ConcurrentMap<ComponentName,Set<Extension>> pendingExtensions
protected volatile List<RegistrationInfo> started
protected volatile List<RegistrationInfo> standby
started list is assigned to standby list then the started field is nullified. When
resuming standby components the started list is restored from the standby list and the standby field is nullifiedprotected volatile ComponentManagerImpl.Stash stash
protected volatile ComponentRegistry registry
protected volatile ComponentRegistry snapshot
protected volatile boolean isFlushingStash
protected volatile boolean changed
public ComponentManagerImpl(RuntimeService runtime)
public final ComponentRegistry getRegistry()
public Collection<RegistrationInfo> getRegistrations()
ComponentManagergetRegistrations in interface ComponentManagerpublic Collection<ComponentName> getResolvedRegistrations()
ComponentManagergetResolvedRegistrations in interface ComponentManagerpublic Map<ComponentName,Set<ComponentName>> getPendingRegistrations()
ComponentManagergetPendingRegistrations in interface ComponentManagerpublic Map<ComponentName,Set<Extension>> getMissingRegistrations()
ComponentManagergetMissingRegistrations in interface ComponentManagerpublic Set<ComponentName> getNeededRegistrations()
public Set<Extension> getPendingExtensions(ComponentName name)
public RegistrationInfo getRegistrationInfo(ComponentName name)
ComponentManagergetRegistrationInfo in interface ComponentManagername - the component namepublic boolean isRegistered(ComponentName name)
ComponentManagerisRegistered in interface ComponentManagername - the object namepublic int size()
ComponentManagersize in interface ComponentManagerpublic ComponentInstance getComponent(ComponentName name)
ComponentManagergetComponent in interface ComponentManagername - the object namepublic void shutdown()
ComponentManagerThis unregisters all objects registered in this registry.
shutdown in interface ComponentManagerpublic Set<String> getBlacklist()
getBlacklist in interface ComponentManagerpublic void setBlacklist(Set<String> blacklist)
setBlacklist in interface ComponentManagerpublic void register(RegistrationInfo ri)
ComponentManagerThis 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.
register in interface ComponentManagerri - the registration infopublic void unregister(RegistrationInfo regInfo)
ComponentManagerThis is called by the main registry when the object is unregistered.
If true is returned, the object will be removed from the main registry.
unregister in interface ComponentManagerregInfo - the registration infopublic void unregister(ComponentName name)
ComponentManagerunregister in interface ComponentManagername - the component namepublic boolean unregisterByLocation(String sourceId)
ComponentManagerunregisterByLocation in interface ComponentManagersourceId - the location from where the component was deployedfor more on thispublic boolean hasComponentFromLocation(String sourceId)
ComponentManagerhasComponentFromLocation in interface ComponentManagerpublic void addComponentListener(ComponentListener listener)
ComponentManagerDoes nothing if the given listener is already registered.
addComponentListener in interface ComponentManagerlistener - the component listener to addpublic void removeComponentListener(ComponentListener listener)
ComponentManagerDoes nothing if the given listener is not registered.
removeComponentListener in interface ComponentManagerlistener - the component listener to removepublic void addListener(ComponentManager.Listener listener)
ComponentManageraddListener in interface ComponentManagerpublic void removeListener(ComponentManager.Listener listener)
ComponentManagerComponentManager.addListener(Listener). If the listener were
not added then nothing is done.removeListener in interface ComponentManagerpublic ComponentInstance getComponentProvidingService(Class<?> serviceClass)
ComponentManagergetComponentProvidingService in interface ComponentManagerserviceClass - the service classpublic <T> T getService(Class<T> serviceClass)
ComponentManagerIf the component is not yet activated it will be prior to return the service.
getService in interface ComponentManagerT - the service typeserviceClass - the service classpublic Collection<ComponentName> getActivatingRegistrations()
ComponentManagergetActivatingRegistrations in interface ComponentManagerpublic Collection<ComponentName> getStartFailureRegistrations()
ComponentManagergetStartFailureRegistrations in interface ComponentManagerprotected Collection<ComponentName> getRegistrations(int state)
public void registerExtension(Extension extension)
public void unregisterExtension(Extension extension)
public static void loadContributions(RegistrationInfo ri, Extension xt)
public void registerServices(RegistrationInfo ri)
public void unregisterServices(RegistrationInfo ri)
public String[] getServices()
ComponentManagergetServices in interface ComponentManagerprotected static void handleError(String message, Exception e)
protected List<RegistrationInfo> activateComponents()
protected void activateComponent(RegistrationInfo ri)
RegistrationInfo. This step will activate the component, register extensions and then
register services.protected void deactivateComponents(boolean isShutdown)
protected void deactivateComponent(RegistrationInfo ri, boolean isShutdown)
RegistrationInfo. This step will unregister the services, unregister the extensions
and then deactivate the component.protected void startComponents(List<RegistrationInfo> ris, boolean isResume)
protected void startComponent(RegistrationInfo ri)
RegistrationInfo. This step will start the component.protected void stopComponents(boolean isStandby)
protected void stopComponent(RegistrationInfo ri) throws InterruptedException
RegistrationInfo. This step will stop the component.InterruptedExceptionpublic boolean start()
ComponentManagerstart in interface ComponentManagerpublic boolean stop()
ComponentManagerstop in interface ComponentManagerpublic void stop(int timeoutInSeconds)
ComponentManagerComponentManager.stop() but log a warning if the timeout is reached while stopping componentsstop in interface ComponentManagerpublic void standby()
ComponentManagerIf any components were previously started do nothing
standby in interface ComponentManagerpublic void standby(int timeoutInSeconds)
ComponentManagerComponentManager.standby() but log a warning if the timeout is reached while stopping componentsstandby in interface ComponentManagerpublic void resume()
ComponentManagerresume in interface ComponentManagerpublic boolean isStarted()
ComponentManagerisStarted in interface ComponentManagerpublic boolean isStandby()
ComponentManagerWhen 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.
isStandby in interface ComponentManagerpublic boolean isRunning()
ComponentManagerisRunning in interface ComponentManagerpublic boolean hasSnapshot()
ComponentManagerhasSnapshot in interface ComponentManagerpublic boolean hasChanged()
ComponentManagerhasChanged in interface ComponentManagerpublic void snapshot()
ComponentManagersnapshot in interface ComponentManagerpublic boolean isStashEmpty()
ComponentManagerisStashEmpty in interface ComponentManagerpublic void restart(boolean reset)
ComponentManagerWhen 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.
restart in interface ComponentManagerreset - whether or not to revert to the last snapshotpublic boolean reset()
ComponentManagerComponentManager.start() to start again the componentsreset in interface ComponentManagerpublic boolean refresh()
ComponentManagerrefresh in interface ComponentManagerComponentManager.refresh(boolean)public boolean refresh(boolean reset)
ComponentManagerreset 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:
refresh in interface ComponentManagerreset - whether or not to revert to the last snapshotprotected void restoreSnapshot()
protected boolean shouldStash()
protected void applyStash(ComponentManagerImpl.Stash stash)
public void unstash()
ComponentManagerComponentManager.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 to
stop(); [restoreSnapshot();] unstash(); start();
unstash in interface ComponentManagerprotected void writeDevMetrics(Watch watch, String type)
protected static void runWihtinTimeout(long timeout, TimeUnit unit, String warn, Runnable runnable) throws InterruptedException
InterruptedExceptionCopyright © 2018 Nuxeo. All rights reserved.