JBoss Modular Service Kernel API 1.0.0.CR2

org.jboss.msc.service
Class DelegatingServiceContainer

java.lang.Object
  extended by org.jboss.msc.service.DelegatingServiceContainer
All Implemented Interfaces:
ServiceContainer, ServiceRegistry, ServiceTarget

public final 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

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.msc.service.ServiceContainer
ServiceContainer.Factory, ServiceContainer.TerminateListener
 
Constructor Summary
DelegatingServiceContainer(ServiceTarget delegateTarget, ServiceRegistry delegateRegistry)
          Construct a new instance.
 
Method Summary
 ServiceContainer addDependency(Collection<ServiceName> dependencies)
          Add a collection of dependencies that will be added to the all ServiceBuilders installed in this target
 ServiceContainer addDependency(ServiceName... dependencies)
          Add a list of dependencies that will be added to the all ServiceBuilders installed in this target.
 ServiceContainer addDependency(ServiceName dependency)
          Add a dependency that will be added to the all ServiceBuilders installed in this target.
 ServiceContainer addListener(Collection<ServiceListener<Object>> listeners)
          Add a collection of service listener that will be added to all ServiceBuilders installed in this target.
 ServiceContainer addListener(ServiceListener.Inheritance inheritance, Collection<ServiceListener<Object>> listeners)
          Add a collection of service listener that will be added to all ServiceBuilders installed in this target.
 ServiceContainer addListener(ServiceListener.Inheritance inheritance, ServiceListener<Object>... listeners)
          Add a list of service listener that will be added to all ServiceBuilders installed in this target.
 ServiceContainer addListener(ServiceListener.Inheritance inheritance, ServiceListener<Object> listener)
          Add a service listener that will be added to all the ServiceBuilders installed in this target.
 ServiceContainer addListener(ServiceListener<Object>... listeners)
          Add a list of service listener that will be added to all ServiceBuilders installed in this target.
 ServiceContainer addListener(ServiceListener<Object> listener)
          Add a service listener 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.
 void addTerminateListener(ServiceContainer.TerminateListener listener)
          Add a terminate listener to this container.
 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()
          Create a new batch service target, which is used to install described services in this target.
 void dumpServices()
          Dump a complete list of services to System.out.
 void dumpServices(PrintStream stream)
          Dump a complete list of services to the given stream.
 Set<ServiceName> getDependencies()
          Returns a set of all dependencies added to this target.
 Set<ServiceListener<Object>> getListeners()
          Returns a set of the listeners added to this target.
 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, returning null if it is not found.
 List<ServiceName> getServiceNames()
          Get a list of service names installed in this registry.
 boolean isShutdownComplete()
          Determine whether the container is completely shut down.
 ServiceContainer removeDependency(ServiceName dependency)
          Remove a dependency from this target.
 ServiceContainer removeListener(ServiceListener<Object> listener)
          Remove a listener from this target, if it exists.
 void shutdown()
          Stop all services within this container.
 ServiceTarget subTarget()
          Create a sub-target using this as the parent target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatingServiceContainer

public DelegatingServiceContainer(ServiceTarget delegateTarget,
                                  ServiceRegistry delegateRegistry)
Construct a new instance.

Parameters:
delegateTarget - the delegate to forward service target requests to
delegateRegistry - the delegate to forward registry requests to
Method Detail

addServiceValue

public <T> ServiceBuilder<T> addServiceValue(ServiceName name,
                                             Value<? extends Service<T>> value)
                                  throws IllegalArgumentException
Get a builder which can be used to add a service to this target.

Specified by:
addServiceValue in interface ServiceTarget
Parameters:
name - the service name
value - the service value
Returns:
the builder for the service
Throws:
IllegalArgumentException

addService

public <T> ServiceBuilder<T> addService(ServiceName name,
                                        Service<T> service)
                             throws IllegalArgumentException
Get a builder which can be used to add a service to this target.

Specified by:
addService in interface ServiceTarget
Parameters:
name - the service name
service - the service
Returns:
the builder for the service
Throws:
IllegalArgumentException

addListener

public ServiceContainer addListener(ServiceListener<Object> listener)
Add a service listener that will be added to all the ServiceBuilders installed in this target.

Specified by:
addListener in interface ServiceTarget
Parameters:
listener - the listener to add to the target
Returns:
this target

addListener

public ServiceContainer addListener(ServiceListener<Object>... listeners)
Add a list of service listener that will be added to all ServiceBuilders installed in this target.

Specified by:
addListener in interface ServiceTarget
Parameters:
listeners - a list of listeners to add to the target
Returns:
this target

addListener

public ServiceContainer addListener(Collection<ServiceListener<Object>> listeners)
Add a collection of service listener that will be added to all ServiceBuilders installed in this target.

Specified by:
addListener in interface ServiceTarget
Parameters:
listeners - a collection of listeners to add to the target
Returns:
this target

addListener

public ServiceContainer addListener(ServiceListener.Inheritance inheritance,
                                    ServiceListener<Object> listener)
Add a service listener that will be added to all the ServiceBuilders installed in this target.

Specified by:
addListener in interface ServiceTarget
Parameters:
inheritance - the inheritance type for this listener
listener - the listener to add to the target
Returns:
this target

addListener

public ServiceContainer addListener(ServiceListener.Inheritance inheritance,
                                    ServiceListener<Object>... listeners)
Add a list of service listener that will be added to all ServiceBuilders installed in this target.

Specified by:
addListener in interface ServiceTarget
Parameters:
inheritance - the inheritance type for this listener
listeners - a list of listeners to add to the target
Returns:
this target

addListener

public ServiceContainer addListener(ServiceListener.Inheritance inheritance,
                                    Collection<ServiceListener<Object>> listeners)
Add a collection of service listener that will be added to all ServiceBuilders installed in this target.

Specified by:
addListener in interface ServiceTarget
Parameters:
inheritance - the inheritance type for this listener
listeners - a collection of listeners to add to the target
Returns:
this target

removeListener

public ServiceContainer removeListener(ServiceListener<Object> listener)
Remove a listener from this target, if it exists.

Specified by:
removeListener in interface ServiceTarget
Parameters:
listener - the listener to remove
Returns:
this target

getListeners

public Set<ServiceListener<Object>> getListeners()
Returns a set of the listeners added to this target.

Specified by:
getListeners in interface ServiceTarget
Returns:
the listeners 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:
addDependency in interface ServiceTarget
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:
addDependency in interface ServiceTarget
Parameters:
dependencies - a list of dependencies to add to the target
Returns:
this target

addDependency

public ServiceContainer addDependency(Collection<ServiceName> dependencies)
Add a collection of dependencies that will be added to the all ServiceBuilders installed in this target

Specified by:
addDependency in interface ServiceTarget
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:
removeDependency in interface ServiceTarget
Parameters:
dependency - the dependency
Returns:
this target

getDependencies

public Set<ServiceName> getDependencies()
Returns a set of all dependencies added to this target.

Specified by:
getDependencies in interface ServiceTarget
Returns:
all dependencies of this target

subTarget

public ServiceTarget subTarget()
Create a sub-target using this as the parent target.

Specified by:
subTarget in interface ServiceTarget
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:
batchTarget in interface ServiceTarget
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:
getRequiredService in interface ServiceRegistry
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, returning null if it is not found.

Specified by:
getService in interface ServiceRegistry
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 interface ServiceRegistry
Returns:
the list

getName

public String getName()
Get the name of this service container.

Specified by:
getName in interface ServiceContainer
Returns:
the container name

shutdown

public void shutdown()
Stop all services within this container.

Specified by:
shutdown in interface ServiceContainer

isShutdownComplete

public boolean isShutdownComplete()
Determine whether the container is completely shut down.

Specified by:
isShutdownComplete in interface ServiceContainer
Returns:
true if shutdown is complete

dumpServices

public void dumpServices()
Dump a complete list of services to System.out.

Specified by:
dumpServices in interface ServiceContainer

dumpServices

public void dumpServices(PrintStream stream)
Dump a complete list of services to the given stream.

Specified by:
dumpServices in interface ServiceContainer
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 added listener will be invoked when this container shutdown process is complete.

Specified by:
addTerminateListener in interface ServiceContainer
Parameters:
listener - the listener

awaitTermination

public void awaitTermination()
Causes the current thread to wait until the container is shutdown.

Specified by:
awaitTermination in interface ServiceContainer

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 interface ServiceContainer
Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Throws:
InterruptedException - if the current thread is interrupted while waiting

JBoss Modular Service Kernel API 1.0.0.CR2

Copyright © 2011 JBoss, a division of Red Hat, Inc.