Package org.jboss.msc.service
Class DelegatingServiceContainer
- java.lang.Object
-
- org.jboss.msc.service.DelegatingServiceContainer
-
- All Implemented Interfaces:
ServiceContainer
,ServiceRegistry
,ServiceTarget
public class DelegatingServiceContainer extends Object implements ServiceContainer
A delegating container for things which depend on a service container rather than a specific target or registry instance.- Author:
- David M. Lloyd, Richard Opalka
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.msc.service.ServiceContainer
ServiceContainer.Factory, ServiceContainer.TerminateListener
-
-
Constructor Summary
Constructors Constructor Description DelegatingServiceContainer(ServiceTarget serviceTargetDelegate, ServiceRegistry serviceRegistryDelegate)
Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ServiceContainer
addDependency(Collection<ServiceName> dependencies)
Deprecated.ServiceContainer
addDependency(ServiceName dependency)
Deprecated.ServiceContainer
addDependency(ServiceName... dependencies)
Deprecated.ServiceContainer
addListener(Collection<ServiceListener<Object>> listeners)
Deprecated.ServiceContainer
addListener(LifecycleListener listener)
Add a service lifecycle listener that will be added to this service.ServiceContainer
addListener(ServiceListener<Object> listener)
Deprecated.ServiceContainer
addListener(ServiceListener<Object>... listeners)
Deprecated.ServiceTarget
addMonitor(StabilityMonitor monitor)
Deprecated.ServiceTarget
addMonitors(StabilityMonitor... monitors)
Deprecated.ServiceBuilder<?>
addService(ServiceName name)
Get a builder which can be used to add a service to this target.<T> ServiceBuilder<T>
addService(ServiceName name, Service<T> service)
Deprecated.<T> ServiceBuilder<T>
addServiceValue(ServiceName name, Value<? extends Service<T>> value)
Deprecated.void
addTerminateListener(ServiceContainer.TerminateListener listener)
Add a terminate listener to this container.void
awaitStability()
Causes the current thread to wait until the container is stable.boolean
awaitStability(long timeout, TimeUnit unit)
Causes the current thread to wait until the container is stable.boolean
awaitStability(long timeout, TimeUnit unit, Set<? super ServiceController<?>> failed, Set<? super ServiceController<?>> problem)
Causes the current thread to wait until the container is stable.void
awaitStability(Set<? super ServiceController<?>> failed, Set<? super ServiceController<?>> problem)
Causes the current thread to wait until the container is stable.void
awaitTermination()
Causes the current thread to wait until the container is shutdown.void
awaitTermination(long timeout, TimeUnit unit)
Causes the current thread to wait until the container is shutdown.BatchServiceTarget
batchTarget()
Deprecated.void
dumpServices()
Dump a complete list of services toSystem.out
.void
dumpServices(PrintStream stream)
Dump a complete list of services to the given stream.Set<ServiceName>
getDependencies()
Deprecated.Set<ServiceListener<Object>>
getListeners()
Deprecated.Set<StabilityMonitor>
getMonitors()
Deprecated.String
getName()
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, returningnull
if it is not found.List<ServiceName>
getServiceNames()
Get a list of service names installed in this registry.protected ServiceRegistry
getServiceRegistryDelegate()
Get the ServiceRegistry delegate.protected ServiceTarget
getServiceTargetDelegate()
Get the ServiceTarget delegate.boolean
isShutdown()
Whether container have been shut down.boolean
isShutdownComplete()
Determine whether the container is completely shut down.ServiceContainer
removeDependency(ServiceName dependency)
Deprecated.ServiceContainer
removeListener(LifecycleListener listener)
Remove a lifecycle listener from this target, if it exists.ServiceContainer
removeListener(ServiceListener<Object> listener)
Deprecated.ServiceTarget
removeMonitor(StabilityMonitor monitor)
Deprecated.void
shutdown()
Stop all services within this container.ServiceTarget
subTarget()
Create a sub-target using this as the parent target.
-
-
-
Constructor Detail
-
DelegatingServiceContainer
public DelegatingServiceContainer(ServiceTarget serviceTargetDelegate, ServiceRegistry serviceRegistryDelegate)
Construct a new instance.- Parameters:
serviceTargetDelegate
- the delegate to forward service target requests toserviceRegistryDelegate
- the delegate to forward registry requests to
-
-
Method Detail
-
getServiceTargetDelegate
protected ServiceTarget getServiceTargetDelegate()
Get the ServiceTarget delegate.- Returns:
- ServiceTarget delegate
-
getServiceRegistryDelegate
protected ServiceRegistry getServiceRegistryDelegate()
Get the ServiceRegistry delegate.- Returns:
- ServiceRegistry delegate
-
addService
public ServiceBuilder<?> addService(ServiceName name) throws IllegalArgumentException
Get a builder which can be used to add a service to this target.- Specified by:
addService
in interfaceServiceTarget
- Parameters:
name
- the service name- Returns:
- new service configurator
- Throws:
IllegalArgumentException
-
addListener
public ServiceContainer addListener(LifecycleListener listener)
Add a service lifecycle listener that will be added to this service.- Specified by:
addListener
in interfaceServiceTarget
- Parameters:
listener
- the lifecycle listener to add to the service- Returns:
- this target
-
removeListener
public ServiceContainer removeListener(LifecycleListener listener)
Remove a lifecycle listener from this target, if it exists.- Specified by:
removeListener
in interfaceServiceTarget
- Parameters:
listener
- the lifecycle listener to remove- Returns:
- this target
-
subTarget
public ServiceTarget subTarget()
Create a sub-target using this as the parent target.- Specified by:
subTarget
in interfaceServiceTarget
- Returns:
- the new service target
-
getRequiredService
public ServiceController<?> getRequiredService(ServiceName serviceName) throws ServiceNotFoundException
Get a service, throwing an exception if it is not found.- Specified by:
getRequiredService
in 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, returningnull
if it is not found.- Specified by:
getService
in interfaceServiceRegistry
- Parameters:
serviceName
- the service name- Returns:
- the service controller for the corresponding service, or
null
if it is not found
-
getServiceNames
public List<ServiceName> getServiceNames()
Get a list of service names installed in this registry.- Specified by:
getServiceNames
in interfaceServiceRegistry
- Returns:
- the list
-
getName
public String getName()
Get the name of this service container.- Specified by:
getName
in interfaceServiceContainer
- Returns:
- the container name
-
shutdown
public void shutdown()
Stop all services within this container.- Specified by:
shutdown
in interfaceServiceContainer
-
isShutdown
public boolean isShutdown()
Whether container have been shut down.- Specified by:
isShutdown
in interfaceServiceContainer
- Returns:
true
if container is shutting down
-
isShutdownComplete
public boolean isShutdownComplete()
Determine whether the container is completely shut down.- Specified by:
isShutdownComplete
in interfaceServiceContainer
- Returns:
true
if shutdown is complete
-
dumpServices
public void dumpServices()
Dump a complete list of services toSystem.out
.- Specified by:
dumpServices
in interfaceServiceContainer
-
dumpServices
public void dumpServices(PrintStream stream)
Dump a complete list of services to the given stream.- Specified by:
dumpServices
in 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 addedlistener
will be invoked when this container shutdown process is complete.- Specified by:
addTerminateListener
in interfaceServiceContainer
- Parameters:
listener
- the listener
-
awaitTermination
public void awaitTermination()
Causes the current thread to wait until the container is shutdown.- Specified by:
awaitTermination
in interfaceServiceContainer
-
awaitTermination
public void awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
Causes the current thread to wait until the container is shutdown.- Specified by:
awaitTermination
in interfaceServiceContainer
- Parameters:
timeout
- the maximum time to waitunit
- the time unit of thetimeout
argument- Throws:
InterruptedException
- if the current thread is interrupted while waiting
-
awaitStability
public void awaitStability() throws InterruptedException
Causes the current thread to wait until the container is stable.- Specified by:
awaitStability
in interfaceServiceContainer
- Throws:
InterruptedException
- if the current thread is interrupted while waiting
-
awaitStability
public boolean awaitStability(long timeout, TimeUnit unit) throws InterruptedException
Causes the current thread to wait until the container is stable.- Specified by:
awaitStability
in interfaceServiceContainer
- Parameters:
timeout
- the maximum time to waitunit
- the time unit of thetimeout
argument- Returns:
- true if this container achieved stability, false if the timeout elapsed before stability
- Throws:
InterruptedException
- if the current thread is interrupted while waiting
-
awaitStability
public void awaitStability(Set<? super ServiceController<?>> failed, Set<? super ServiceController<?>> problem) throws InterruptedException
Causes the current thread to wait until the container is stable.- Specified by:
awaitStability
in interfaceServiceContainer
- Parameters:
failed
- a set into which failed services should be copiedproblem
- a set into which problem services should be copied- Throws:
InterruptedException
- if the current thread is interrupted while waiting
-
awaitStability
public boolean awaitStability(long timeout, TimeUnit unit, Set<? super ServiceController<?>> failed, Set<? super ServiceController<?>> problem) throws InterruptedException
Causes the current thread to wait until the container is stable.- Specified by:
awaitStability
in interfaceServiceContainer
- Parameters:
timeout
- the maximum time to waitunit
- the time unit of thetimeout
argumentfailed
- 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:
InterruptedException
- if the current thread is interrupted while waiting
-
addServiceValue
@Deprecated public <T> ServiceBuilder<T> addServiceValue(ServiceName name, Value<? extends Service<T>> value) throws IllegalArgumentException
Deprecated.Get a builder which can be used to add a service to this target.- Specified by:
addServiceValue
in interfaceServiceTarget
- Parameters:
name
- the service namevalue
- the service value- Returns:
- the builder for the service
- Throws:
IllegalArgumentException
-
addService
@Deprecated public <T> ServiceBuilder<T> addService(ServiceName name, Service<T> service) throws IllegalArgumentException
Deprecated.Get a builder which can be used to add a service to this target.- Specified by:
addService
in interfaceServiceTarget
- Parameters:
name
- the service nameservice
- the service- Returns:
- the builder for the service
- Throws:
IllegalArgumentException
-
addListener
@Deprecated public ServiceContainer addListener(ServiceListener<Object> listener)
Deprecated.Add a service listener that will be added to all the ServiceBuilders installed in this target.- Specified by:
addListener
in interfaceServiceTarget
- Parameters:
listener
- the listener to add to the target- Returns:
- this target
-
addListener
@Deprecated public ServiceContainer addListener(ServiceListener<Object>... listeners)
Deprecated.Add a list of service listener that will be added to all ServiceBuilders installed in this target.- Specified by:
addListener
in interfaceServiceTarget
- Parameters:
listeners
- a list of listeners to add to the target- Returns:
- this target
-
addListener
@Deprecated public ServiceContainer addListener(Collection<ServiceListener<Object>> listeners)
Deprecated.Add a collection of service listener that will be added to all ServiceBuilders installed in this target.- Specified by:
addListener
in interfaceServiceTarget
- Parameters:
listeners
- a collection of listeners to add to the target- Returns:
- this target
-
removeListener
@Deprecated public ServiceContainer removeListener(ServiceListener<Object> listener)
Deprecated.Remove a listener from this target, if it exists.- Specified by:
removeListener
in interfaceServiceTarget
- Parameters:
listener
- the listener to remove- Returns:
- this target
-
getListeners
@Deprecated public Set<ServiceListener<Object>> getListeners()
Deprecated.Returns a set of the listeners added to this target.- Specified by:
getListeners
in interfaceServiceTarget
- Returns:
- the listeners added to this target
-
addMonitor
@Deprecated public ServiceTarget addMonitor(StabilityMonitor monitor)
Deprecated.Add a stability monitor that will be added to all the ServiceBuilders installed in this target.- Specified by:
addMonitor
in interfaceServiceTarget
- Parameters:
monitor
- the monitor to add to the target- Returns:
- this target
-
addMonitors
@Deprecated public ServiceTarget addMonitors(StabilityMonitor... monitors)
Deprecated.Add a stability monitors that will be added to all the ServiceBuilders installed in this target.- Specified by:
addMonitors
in interfaceServiceTarget
- Parameters:
monitors
- the monitors to add to the target- Returns:
- this target
-
removeMonitor
@Deprecated public ServiceTarget removeMonitor(StabilityMonitor monitor)
Deprecated.Remove a monitor from this target, if it exists.- Specified by:
removeMonitor
in interfaceServiceTarget
- Parameters:
monitor
- the monitor to remove- Returns:
- this target
-
getMonitors
@Deprecated public Set<StabilityMonitor> getMonitors()
Deprecated.Returns a set of the monitors added to this target.- Specified by:
getMonitors
in interfaceServiceTarget
- Returns:
- the monitors added to this target
-
addDependency
@Deprecated public ServiceContainer addDependency(ServiceName dependency)
Deprecated.Add a dependency that will be added to the all ServiceBuilders installed in this target.- Specified by:
addDependency
in interfaceServiceTarget
- Parameters:
dependency
- the dependency to add to the target- Returns:
- this target
-
addDependency
@Deprecated public ServiceContainer addDependency(ServiceName... dependencies)
Deprecated.Add a list of dependencies that will be added to the all ServiceBuilders installed in this target.- Specified by:
addDependency
in interfaceServiceTarget
- Parameters:
dependencies
- a list of dependencies to add to the target- Returns:
- this target
-
addDependency
@Deprecated public ServiceContainer addDependency(Collection<ServiceName> dependencies)
Deprecated.Add a collection of dependencies that will be added to the all ServiceBuilders installed in this target- Specified by:
addDependency
in interfaceServiceTarget
- Parameters:
dependencies
- a collection of dependencies to add to this target- Returns:
- this target
-
removeDependency
@Deprecated public ServiceContainer removeDependency(ServiceName dependency)
Deprecated.Remove a dependency from this target. Subsequently defined services will not have this dependency.- Specified by:
removeDependency
in interfaceServiceTarget
- Parameters:
dependency
- the dependency- Returns:
- this target
-
getDependencies
@Deprecated public Set<ServiceName> getDependencies()
Deprecated.Returns a set of all dependencies added to this target.- Specified by:
getDependencies
in interfaceServiceTarget
- Returns:
- all dependencies of this target
-
batchTarget
@Deprecated public BatchServiceTarget batchTarget()
Deprecated.Create a new batch service target, which is used to install described services in this target.- Specified by:
batchTarget
in interfaceServiceTarget
- Returns:
- the new batch service target
-
-