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()
ComponentManager
getRegistrations
in interface ComponentManager
public Collection<ComponentName> getResolvedRegistrations()
ComponentManager
getResolvedRegistrations
in interface ComponentManager
public Map<ComponentName,Set<ComponentName>> getPendingRegistrations()
ComponentManager
getPendingRegistrations
in interface ComponentManager
public Map<ComponentName,Set<Extension>> getMissingRegistrations()
ComponentManager
getMissingRegistrations
in interface ComponentManager
public Set<ComponentName> getNeededRegistrations()
public Set<Extension> getPendingExtensions(ComponentName name)
public RegistrationInfo getRegistrationInfo(ComponentName name)
ComponentManager
getRegistrationInfo
in interface ComponentManager
name
- the component namepublic boolean isRegistered(ComponentName name)
ComponentManager
isRegistered
in interface ComponentManager
name
- the object namepublic int size()
ComponentManager
size
in interface ComponentManager
public ComponentInstance getComponent(ComponentName name)
ComponentManager
getComponent
in interface ComponentManager
name
- the object namepublic void shutdown()
ComponentManager
This unregisters all objects registered in this registry.
shutdown
in interface ComponentManager
public Set<String> getBlacklist()
getBlacklist
in interface ComponentManager
public void setBlacklist(Set<String> blacklist)
setBlacklist
in interface ComponentManager
public void register(RegistrationInfo ri)
ComponentManager
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.
register
in interface ComponentManager
ri
- the registration infopublic void unregister(RegistrationInfo regInfo)
ComponentManager
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.
unregister
in interface ComponentManager
regInfo
- the registration infopublic void unregister(ComponentName name)
ComponentManager
unregister
in interface ComponentManager
name
- the component namepublic boolean unregisterByLocation(String sourceId)
ComponentManager
unregisterByLocation
in interface ComponentManager
sourceId
- the location from where the component was deployedfor more on this
public boolean hasComponentFromLocation(String sourceId)
ComponentManager
hasComponentFromLocation
in interface ComponentManager
public void addComponentListener(ComponentListener listener)
ComponentManager
Does nothing if the given listener is already registered.
addComponentListener
in interface ComponentManager
listener
- the component listener to addpublic void removeComponentListener(ComponentListener listener)
ComponentManager
Does nothing if the given listener is not registered.
removeComponentListener
in interface ComponentManager
listener
- the component listener to removepublic void addListener(ComponentManager.Listener listener)
ComponentManager
addListener
in interface ComponentManager
public void removeListener(ComponentManager.Listener listener)
ComponentManager
ComponentManager.addListener(Listener)
. If the listener were
not added then nothing is done.removeListener
in interface ComponentManager
public ComponentInstance getComponentProvidingService(Class<?> serviceClass)
ComponentManager
getComponentProvidingService
in interface ComponentManager
serviceClass
- the service classpublic <T> T getService(Class<T> serviceClass)
ComponentManager
If the component is not yet activated it will be prior to return the service.
getService
in interface ComponentManager
T
- the service typeserviceClass
- the service classpublic Collection<ComponentName> getActivatingRegistrations()
ComponentManager
getActivatingRegistrations
in interface ComponentManager
public Collection<ComponentName> getStartFailureRegistrations()
ComponentManager
getStartFailureRegistrations
in interface ComponentManager
protected 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()
ComponentManager
getServices
in interface ComponentManager
protected 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.InterruptedException
public boolean start()
ComponentManager
start
in interface ComponentManager
public boolean stop()
ComponentManager
stop
in interface ComponentManager
public void stop(int timeoutInSeconds)
ComponentManager
ComponentManager.stop()
but log a warning if the timeout is reached while stopping componentsstop
in interface ComponentManager
public void standby()
ComponentManager
If any components were previously started do nothing
standby
in interface ComponentManager
public void standby(int timeoutInSeconds)
ComponentManager
ComponentManager.standby()
but log a warning if the timeout is reached while stopping componentsstandby
in interface ComponentManager
public void resume()
ComponentManager
resume
in interface ComponentManager
public boolean isStarted()
ComponentManager
isStarted
in interface ComponentManager
public boolean isStandby()
ComponentManager
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.
isStandby
in interface ComponentManager
public boolean isRunning()
ComponentManager
isRunning
in interface ComponentManager
public boolean hasSnapshot()
ComponentManager
hasSnapshot
in interface ComponentManager
public boolean hasChanged()
ComponentManager
hasChanged
in interface ComponentManager
public void snapshot()
ComponentManager
snapshot
in interface ComponentManager
public boolean isStashEmpty()
ComponentManager
isStashEmpty
in interface ComponentManager
public void restart(boolean reset)
ComponentManager
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.
restart
in interface ComponentManager
reset
- whether or not to revert to the last snapshotpublic boolean reset()
ComponentManager
ComponentManager.start()
to start again the componentsreset
in interface ComponentManager
public boolean refresh()
ComponentManager
refresh
in interface ComponentManager
ComponentManager.refresh(boolean)
public boolean refresh(boolean reset)
ComponentManager
reset
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 ComponentManager
reset
- whether or not to revert to the last snapshotprotected void restoreSnapshot()
protected boolean shouldStash()
protected void applyStash(ComponentManagerImpl.Stash stash)
public void unstash()
ComponentManager
ComponentManager.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 ComponentManager
protected void writeDevMetrics(Watch watch, String type)
protected static void runWihtinTimeout(long timeout, TimeUnit unit, String warn, Runnable runnable) throws InterruptedException
InterruptedException
Copyright © 2018 Nuxeo. All rights reserved.