Package org.jboss.msc.service
Class DelegatingServiceContainer
- java.lang.Object
-
- org.jboss.msc.service.DelegatingServiceContainer
-
- All Implemented Interfaces:
ServiceContainer,ServiceRegistry,ServiceTarget
public final class DelegatingServiceContainer extends java.lang.Object implements ServiceContainer
A delegating container for things which depend on a service container rather than a specific target or registry instance.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.msc.service.ServiceContainer
ServiceContainer.Factory, ServiceContainer.TerminateListener
-
-
Field Summary
Fields Modifier and Type Field Description private ServiceRegistrydelegateRegistryprivate ServiceTargetdelegateTarget
-
Constructor Summary
Constructors Constructor Description DelegatingServiceContainer(ServiceTarget delegateTarget, ServiceRegistry delegateRegistry)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ServiceContaineraddDependency(java.util.Collection<ServiceName> dependencies)Add a collection of dependencies that will be added to the all ServiceBuilders installed in this targetServiceContaineraddDependency(ServiceName dependency)Add a dependency that will be added to the all ServiceBuilders installed in this target.ServiceContaineraddDependency(ServiceName... dependencies)Add a list of dependencies that will be added to the all ServiceBuilders installed in this target.ServiceContaineraddListener(java.util.Collection<ServiceListener<java.lang.Object>> listeners)Add a collection of service listener that will be added to all ServiceBuilders installed in this target.ServiceContaineraddListener(ServiceListener<java.lang.Object> listener)Add a service listener that will be added to all the ServiceBuilders installed in this target.ServiceContaineraddListener(ServiceListener<java.lang.Object>... listeners)Add a list of service listener that will be added to all ServiceBuilders installed in this target.ServiceTargetaddMonitor(StabilityMonitor monitor)Add a stability monitor that will be added to all the ServiceBuilders installed in this target.ServiceTargetaddMonitors(StabilityMonitor... monitors)Add a stability monitors that will be added to all the ServiceBuilders installed in this target.<T> ServiceBuilder<T>addService(ServiceName name, Service<T> service)Get a builder which can be used to add a service to this target.<T> ServiceBuilder<T>addServiceValue(ServiceName name, Value<? extends Service<T>> value)Get a builder which can be used to add a service to this target.voidaddTerminateListener(ServiceContainer.TerminateListener listener)Add a terminate listener to this container.voidawaitStability()Causes the current thread to wait until the container is stable.booleanawaitStability(long timeout, java.util.concurrent.TimeUnit unit)Causes the current thread to wait until the container is stable.booleanawaitStability(long timeout, java.util.concurrent.TimeUnit unit, java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problem)Causes the current thread to wait until the container is stable.voidawaitStability(java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problem)Causes the current thread to wait until the container is stable.voidawaitTermination()Causes the current thread to wait until the container is shutdown.voidawaitTermination(long timeout, java.util.concurrent.TimeUnit unit)Causes the current thread to wait until the container is shutdown.BatchServiceTargetbatchTarget()Create a new batch service target, which is used to install described services in this target.voiddumpServices()Dump a complete list of services toSystem.out.voiddumpServices(java.io.PrintStream stream)Dump a complete list of services to the given stream.java.util.Set<ServiceName>getDependencies()Returns a set of all dependencies added to this target.java.util.Set<ServiceListener<java.lang.Object>>getListeners()Returns a set of the listeners added to this target.java.util.Set<StabilityMonitor>getMonitors()Returns a set of the monitors added to this target.java.lang.StringgetName()Get the name of this service container.ServiceController<?>getRequiredService(ServiceName serviceName)Get a service, throwing an exception if it is not found.ServiceController<?>getService(ServiceName serviceName)Get a service, returningnullif it is not found.java.util.List<ServiceName>getServiceNames()Get a list of service names installed in this registry.booleanisShutdown()Whether container have been shut down.booleanisShutdownComplete()Determine whether the container is completely shut down.ServiceContainerremoveDependency(ServiceName dependency)Remove a dependency from this target.ServiceContainerremoveListener(ServiceListener<java.lang.Object> listener)Remove a listener from this target, if it exists.ServiceTargetremoveMonitor(StabilityMonitor monitor)Remove a monitor from this target, if it exists.voidshutdown()Stop all services within this container.ServiceTargetsubTarget()Create a sub-target using this as the parent target.
-
-
-
Field Detail
-
delegateTarget
private final ServiceTarget delegateTarget
-
delegateRegistry
private final ServiceRegistry delegateRegistry
-
-
Constructor Detail
-
DelegatingServiceContainer
public DelegatingServiceContainer(ServiceTarget delegateTarget, ServiceRegistry delegateRegistry)
Construct a new instance.- Parameters:
delegateTarget- the delegate to forward service target requests todelegateRegistry- the delegate to forward registry requests to
-
-
Method Detail
-
addServiceValue
public <T> ServiceBuilder<T> addServiceValue(ServiceName name, Value<? extends Service<T>> value) throws java.lang.IllegalArgumentException
Get a builder which can be used to add a service to this target.- Specified by:
addServiceValuein interfaceServiceTarget- Parameters:
name- the service namevalue- the service value- Returns:
- the builder for the service
- Throws:
java.lang.IllegalArgumentException
-
addService
public <T> ServiceBuilder<T> addService(ServiceName name, Service<T> service) throws java.lang.IllegalArgumentException
Get a builder which can be used to add a service to this target.- Specified by:
addServicein interfaceServiceTarget- Parameters:
name- the service nameservice- the service- Returns:
- the builder for the service
- Throws:
java.lang.IllegalArgumentException
-
addListener
public ServiceContainer addListener(ServiceListener<java.lang.Object> listener)
Add a service listener that will be added to all the ServiceBuilders installed in this target.- Specified by:
addListenerin interfaceServiceTarget- Parameters:
listener- the listener to add to the target- Returns:
- this target
-
addListener
public ServiceContainer addListener(ServiceListener<java.lang.Object>... listeners)
Add a list of service listener that will be added to all ServiceBuilders installed in this target.- Specified by:
addListenerin interfaceServiceTarget- Parameters:
listeners- a list of listeners to add to the target- Returns:
- this target
-
addListener
public ServiceContainer addListener(java.util.Collection<ServiceListener<java.lang.Object>> listeners)
Add a collection of service listener that will be added to all ServiceBuilders installed in this target.- Specified by:
addListenerin interfaceServiceTarget- Parameters:
listeners- a collection of listeners to add to the target- Returns:
- this target
-
removeListener
public ServiceContainer removeListener(ServiceListener<java.lang.Object> listener)
Remove a listener from this target, if it exists.- Specified by:
removeListenerin interfaceServiceTarget- Parameters:
listener- the listener to remove- Returns:
- this target
-
getListeners
public java.util.Set<ServiceListener<java.lang.Object>> getListeners()
Returns a set of the listeners added to this target.- Specified by:
getListenersin interfaceServiceTarget- Returns:
- the listeners added to this target
-
addMonitor
public ServiceTarget addMonitor(StabilityMonitor monitor)
Add a stability monitor that will be added to all the ServiceBuilders installed in this target.- Specified by:
addMonitorin interfaceServiceTarget- Parameters:
monitor- the monitor to add to the target- Returns:
- this target
-
addMonitors
public ServiceTarget addMonitors(StabilityMonitor... monitors)
Add a stability monitors that will be added to all the ServiceBuilders installed in this target.- Specified by:
addMonitorsin interfaceServiceTarget- Parameters:
monitors- the monitors to add to the target- Returns:
- this target
-
removeMonitor
public ServiceTarget removeMonitor(StabilityMonitor monitor)
Remove a monitor from this target, if it exists.- Specified by:
removeMonitorin interfaceServiceTarget- Parameters:
monitor- the monitor to remove- Returns:
- this target
-
getMonitors
public java.util.Set<StabilityMonitor> getMonitors()
Returns a set of the monitors added to this target.- Specified by:
getMonitorsin interfaceServiceTarget- Returns:
- the monitors added to this target
-
addDependency
public ServiceContainer addDependency(ServiceName dependency)
Add a dependency that will be added to the all ServiceBuilders installed in this target.- Specified by:
addDependencyin interfaceServiceTarget- Parameters:
dependency- the dependency to add to the target- Returns:
- this target
-
addDependency
public ServiceContainer addDependency(ServiceName... dependencies)
Add a list of dependencies that will be added to the all ServiceBuilders installed in this target.- Specified by:
addDependencyin interfaceServiceTarget- Parameters:
dependencies- a list of dependencies to add to the target- Returns:
- this target
-
addDependency
public ServiceContainer addDependency(java.util.Collection<ServiceName> dependencies)
Add a collection of dependencies that will be added to the all ServiceBuilders installed in this target- Specified by:
addDependencyin interfaceServiceTarget- Parameters:
dependencies- a collection of dependencies to add to this target- Returns:
- this target
-
removeDependency
public ServiceContainer removeDependency(ServiceName dependency)
Remove a dependency from this target. Subsequently defined services will not have this dependency.- Specified by:
removeDependencyin interfaceServiceTarget- Parameters:
dependency- the dependency- Returns:
- this target
-
getDependencies
public java.util.Set<ServiceName> getDependencies()
Returns a set of all dependencies added to this target.- Specified by:
getDependenciesin interfaceServiceTarget- Returns:
- all dependencies of this target
-
subTarget
public ServiceTarget subTarget()
Create a sub-target using this as the parent target.- Specified by:
subTargetin interfaceServiceTarget- Returns:
- the new service target
-
batchTarget
public BatchServiceTarget batchTarget()
Create a new batch service target, which is used to install described services in this target.- Specified by:
batchTargetin interfaceServiceTarget- Returns:
- the new batch service target
-
getRequiredService
public ServiceController<?> getRequiredService(ServiceName serviceName) throws ServiceNotFoundException
Get a service, throwing an exception if it is not found.- Specified by:
getRequiredServicein interfaceServiceRegistry- Parameters:
serviceName- the service name- Returns:
- the service controller for the corresponding service
- Throws:
ServiceNotFoundException- if the service is not present in the registry
-
getService
public ServiceController<?> getService(ServiceName serviceName)
Get a service, returningnullif it is not found.- Specified by:
getServicein interfaceServiceRegistry- Parameters:
serviceName- the service name- Returns:
- the service controller for the corresponding service, or
nullif it is not found
-
getServiceNames
public java.util.List<ServiceName> getServiceNames()
Get a list of service names installed in this registry.- Specified by:
getServiceNamesin interfaceServiceRegistry- Returns:
- the list
-
getName
public java.lang.String getName()
Get the name of this service container.- Specified by:
getNamein interfaceServiceContainer- Returns:
- the container name
-
shutdown
public void shutdown()
Stop all services within this container.- Specified by:
shutdownin interfaceServiceContainer
-
isShutdown
public boolean isShutdown()
Whether container have been shut down.- Specified by:
isShutdownin interfaceServiceContainer- Returns:
trueif container is shutting down
-
isShutdownComplete
public boolean isShutdownComplete()
Determine whether the container is completely shut down.- Specified by:
isShutdownCompletein interfaceServiceContainer- Returns:
trueif shutdown is complete
-
dumpServices
public void dumpServices()
Dump a complete list of services toSystem.out.- Specified by:
dumpServicesin interfaceServiceContainer
-
dumpServices
public void dumpServices(java.io.PrintStream stream)
Dump a complete list of services to the given stream.- Specified by:
dumpServicesin interfaceServiceContainer- Parameters:
stream- the stream to which the service list should be written
-
addTerminateListener
public void addTerminateListener(ServiceContainer.TerminateListener listener)
Add a terminate listener to this container. The addedlistenerwill be invoked when this container shutdown process is complete.- Specified by:
addTerminateListenerin interfaceServiceContainer- Parameters:
listener- the listener
-
awaitTermination
public void awaitTermination()
Causes the current thread to wait until the container is shutdown.- Specified by:
awaitTerminationin interfaceServiceContainer
-
awaitTermination
public void awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedExceptionCauses the current thread to wait until the container is shutdown.- Specified by:
awaitTerminationin interfaceServiceContainer- Parameters:
timeout- the maximum time to waitunit- the time unit of thetimeoutargument- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public void awaitStability() throws java.lang.InterruptedExceptionCauses the current thread to wait until the container is stable.- Specified by:
awaitStabilityin interfaceServiceContainer- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public boolean awaitStability(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedExceptionCauses the current thread to wait until the container is stable.- Specified by:
awaitStabilityin interfaceServiceContainer- Parameters:
timeout- the maximum time to waitunit- the time unit of thetimeoutargument- Returns:
- true if this container achieved stability, false if the timeout elapsed before stability
- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public void awaitStability(java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problem) throws java.lang.InterruptedException
Causes the current thread to wait until the container is stable.- Specified by:
awaitStabilityin interfaceServiceContainer- Parameters:
failed- a set into which failed services should be copiedproblem- a set into which problem services should be copied- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public boolean awaitStability(long timeout, java.util.concurrent.TimeUnit unit, java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problem) throws java.lang.InterruptedExceptionCauses the current thread to wait until the container is stable.- Specified by:
awaitStabilityin interfaceServiceContainer- Parameters:
timeout- the maximum time to waitunit- the time unit of thetimeoutargumentfailed- a set into which failed services should be copiedproblem- a set into which problem services should be copied- Returns:
- true if this container achieved stability, false if the timeout elapsed before stability
- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
-