Interface ComponentManager
-
- All Known Implementing Classes:
ComponentManagerImpl
public interface ComponentManager
- Author:
- Bogdan Stefanescu, Florent Guillaume
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ComponentManager.Listener
Listener interface for component manager events
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description 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.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.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.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 notificationboolean
hasChanged()
Tests whether components were deployed over the initial snapshot (i.e.boolean
hasComponentFromLocation(String sourceId)
Deprecated.since 9.2boolean
hasSnapshot()
Check if a snapshot was doneboolean
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 emptydefault 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
removeComponentListener(ComponentListener listener)
Removes a component listener.void
removeListener(ComponentManager.Listener listener)
Remove the component manager listener previously added byaddListener(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.void
resume()
Start standby components.void
setBlacklist(Set<String> blacklist)
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 timeout)
Same asstandby()
but log a warning if the timeout is reached while stopping componentsboolean
start()
Activate and start all resolved components.boolean
stop()
Stop and deactivate all resolved components.void
stop(int timeout)
Same asstop()
but log a warning if the timeout is reached while stopping componentsvoid
unregister(ComponentName name)
Unregisters a component given its name.void
unregister(RegistrationInfo ri)
Handles the unregistration of the given registration info.boolean
unregisterByLocation(String sourceId)
Deprecated.since 9.2void
unstash()
Apply the stash if not empty.
-
-
-
Method Detail
-
addComponentListener
void addComponentListener(ComponentListener listener)
Adds a component listener.Does nothing if the given listener is already registered.
- Parameters:
listener
- the component listener to add
-
removeComponentListener
void removeComponentListener(ComponentListener listener)
Removes a component listener.Does nothing if the given listener is not registered.
- Parameters:
listener
- the component listener to remove
-
register
void register(RegistrationInfo ri)
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.
- Parameters:
ri
- the registration info
-
unregister
void unregister(RegistrationInfo ri)
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.
- Parameters:
ri
- the registration info
-
unregister
void unregister(ComponentName name)
Unregisters a component given its name.- Parameters:
name
- the component name
-
unregisterByLocation
@Deprecated boolean unregisterByLocation(String sourceId)
Deprecated.since 9.2This 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- Parameters:
sourceId
- the location from where the component was deployed- Returns:
- false if no component was registered from that location, true otherwise
- Since:
- 9.2
- See Also:
for more on this
-
hasComponentFromLocation
@Deprecated boolean hasComponentFromLocation(String sourceId)
Deprecated.since 9.2Given 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
-
getRegistrationInfo
RegistrationInfo getRegistrationInfo(ComponentName name)
Gets the component if there is one having the given name.- Parameters:
name
- the component name- Returns:
- the component if any was registered with that name, null otherwise
-
getComponent
ComponentInstance getComponent(ComponentName name)
Gets object instance managed by the named component.- Parameters:
name
- the object name- Returns:
- the object instance if any. may be null
-
isRegistered
boolean isRegistered(ComponentName name)
Checks whether or not a component with the given name was registered.- Parameters:
name
- the object name- Returns:
- true if an object with the given name was registered, false otherwise
-
getRegistrations
Collection<RegistrationInfo> getRegistrations()
Gets the registered components.- Returns:
- a read-only collection of components
-
getPendingRegistrations
Map<ComponentName,Set<ComponentName>> getPendingRegistrations()
Gets the pending registrations and their dependencies.- Returns:
- the pending registrations
-
getMissingRegistrations
Map<ComponentName,Set<Extension>> getMissingRegistrations()
Returns the missing registrations, linked to missing target extension points.- Since:
- 8.10
-
getActivatingRegistrations
Collection<ComponentName> getActivatingRegistrations()
Gets the pending extensions by component.- Returns:
- the pending extensions
-
getResolvedRegistrations
Collection<ComponentName> getResolvedRegistrations()
Gets the resolved component names in the order they were resolved- Since:
- 9.2
-
getStartFailureRegistrations
Collection<ComponentName> getStartFailureRegistrations()
Gets the components that fail on applicationStarted notification- Since:
- 7.4
-
size
int size()
Gets the number of registered objects in this registry.- Returns:
- the number of registered objects
-
shutdown
void shutdown()
Shuts down the component registry.This unregisters all objects registered in this registry.
-
getService
<T> T getService(Class<T> serviceClass)
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.
- Type Parameters:
T
- the service type- Parameters:
serviceClass
- the service class- Returns:
- the service object
-
getServices
String[] getServices()
Get the list of all registered service names An empty array is returned if no registered services are found.- Returns:
- an array of registered service.
-
getComponentProvidingService
ComponentInstance getComponentProvidingService(Class<?> serviceClass)
Gets the component that provides the given service.- Parameters:
serviceClass
- the service class- Returns:
- the component or null if none
-
start
boolean start()
Activate and start all resolved components. If components were already started do nothing.- Returns:
- false if components were already started, true otherwise
- Since:
- 9.2
-
stop
boolean stop()
Stop and deactivate all resolved components. If components were not yet started do nothing- Returns:
- false if components were not yet started, true otherwise
- Since:
- 9.2
-
stop
void stop(int timeout)
Same asstop()
but log a warning if the timeout is reached while stopping components- Since:
- 9.2
-
standby
void standby()
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
- Since:
- 9.2
-
standby
void standby(int timeout)
Same asstandby()
but log a warning if the timeout is reached while stopping components- Since:
- 9.2
-
resume
void resume()
Start standby components. If components are not in standby mode the it does nothing.- Since:
- 9.2
-
snapshot
void snapshot()
Make a snapshot of the component registry. When calling restart- Since:
- 9.2
-
restart
void restart(boolean reset)
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.- Parameters:
reset
- whether or not to revert to the last snapshot- Since:
- 9.2
-
reset
boolean reset()
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 callstart()
to start again the components- Returns:
- true if the components were stopped, false otherwise
- Since:
- 9.2
-
refresh
boolean refresh(boolean reset)
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)
- Parameters:
reset
- whether or not to revert to the last snapshot- Returns:
- false if stash is empty and nothing was done, true otherwise
- Since:
- 9.2
-
refresh
default boolean refresh()
Shortcut for refresh(false).- Since:
- 9.2
- See Also:
refresh(boolean)
-
isStarted
boolean isStarted()
Tests whether the components were already started.- Returns:
- true if components are started, false
- Since:
- 9.2
-
isStandby
boolean isStandby()
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.
- Since:
- 9.2
-
isRunning
boolean isRunning()
Tests whether the components are running. That means they are either started either in standby mode.- Since:
- 9.2
-
hasChanged
boolean hasChanged()
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.- Since:
- 9.2
-
hasSnapshot
boolean hasSnapshot()
Check if a snapshot was done- Returns:
- true if a snapshot already exists, false otherwise
- Since:
- 9.2
-
isStashEmpty
boolean isStashEmpty()
Tests if the stash is empty- Since:
- 9.2
-
unstash
void unstash()
Apply the stash if not empty. This is a low level operation and may not be safe to call when the component manager is runningisRunning()
.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
refresh()
which is similar tostop(); [restoreSnapshot();] unstash(); start();
- Since:
- 9.2
-
addListener
void addListener(ComponentManager.Listener listener)
Add a listener to be notified on manager actions like start / stop components.- Since:
- 9.2
-
removeListener
void removeListener(ComponentManager.Listener listener)
Remove the component manager listener previously added byaddListener(Listener)
. If the listener were not added then nothing is done.- Since:
- 9.2
-
-