Package org.jboss.msc.service
Class ServiceContainerImpl
- java.lang.Object
-
- org.jboss.msc.service.ServiceTargetImpl
-
- org.jboss.msc.service.ServiceContainerImpl
-
- All Implemented Interfaces:
ServiceContainer
,ServiceRegistry
,ServiceTarget
final class ServiceContainerImpl extends ServiceTargetImpl implements ServiceContainer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
ServiceContainerImpl.ContainerExecutor
(package private) static class
ServiceContainerImpl.LatchListener
(package private) static class
ServiceContainerImpl.ServiceThread
private static class
ServiceContainerImpl.ShutdownHookHolder
(package private) class
ServiceContainerImpl.ThreadAction
-
Nested classes/interfaces inherited from interface org.jboss.msc.service.ServiceContainer
ServiceContainer.Factory, ServiceContainer.TerminateListener
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
autoShutdown
private ServiceContainerMXBean
containerMXBean
private boolean
down
private ServiceContainerImpl.ContainerExecutor
executor
private static java.util.concurrent.atomic.AtomicInteger
executorSeq
private java.util.Set<ServiceController<?>>
failed
private static java.lang.Thread.UncaughtExceptionHandler
HANDLER
private java.lang.Object
lock
private javax.management.MBeanServer
mBeanServer
private java.lang.String
name
private javax.management.ObjectName
objectName
private static java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy
POLICY
private java.util.Set<ServiceController<?>>
problems
(package private) static java.lang.String
PROFILE_OUTPUT
private java.io.Writer
profileOutput
private java.util.concurrent.ConcurrentMap<ServiceName,ServiceRegistrationImpl>
registry
private static java.util.concurrent.atomic.AtomicInteger
SERIAL
private long
shutdownInitiated
private long
start
private ServiceContainer.TerminateListener.Info
terminateInfo
private java.util.List<ServiceContainer.TerminateListener>
terminateListeners
private int
unstableServices
-
Constructor Summary
Constructors Constructor Description ServiceContainerImpl(java.lang.String name, int coreSize, long timeOut, java.util.concurrent.TimeUnit timeOutUnit, boolean autoShutdown)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addFailed(ServiceController<?> controller)
(package private) void
addProblem(ServiceController<?> controller)
void
addTerminateListener(ServiceContainer.TerminateListener listener)
Add a terminate listener to this container.(package private) void
apply(ServiceBuilderImpl<?> builder)
Apply listeners and dependencies toserviceBuilder
.(package private) void
apply(ServiceBuilderImpl<?> builder, ServiceControllerImpl<?> parent)
void
awaitStability()
Causes the current thread to wait until the container is stable.boolean
awaitStability(long timeout, java.util.concurrent.TimeUnit unit)
Causes the current thread to wait until the container is stable.boolean
awaitStability(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.void
awaitStability(java.util.Set<? super ServiceController<?>> failed, java.util.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, java.util.concurrent.TimeUnit unit)
Causes the current thread to wait until the container is shutdown.(package private) void
decrementUnstableServices()
private void
detectCircularity(IdentityHashSet<? extends Dependent> dependents, ServiceControllerImpl<?> instance, java.util.Set<ServiceControllerImpl<?>> visited, java.util.Deque<ServiceName> visitStack)
private <T> void
detectCircularity(ServiceControllerImpl<T> instance)
Detects if installation ofinstance
results in dependency cycles.void
dumpServices()
Dump a complete list of services toSystem.out
.void
dumpServices(java.io.PrintStream out)
Dump a complete list of services to the given stream.protected void
finalize()
(package private) java.util.concurrent.Executor
getExecutor()
java.lang.String
getName()
Get the name of this service container.private ServiceRegistrationImpl
getOrCreateRegistration(ServiceName name)
Atomically get or create a registration.(package private) java.io.Writer
getProfileOutput()
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.java.util.List<ServiceName>
getServiceNames()
Get a list of service names installed in this registry.ServiceRegistry
getServiceRegistry()
Returns the serviceRegistry that contains all services installed by this target.(package private) long
getStart()
(package private) void
incrementUnstableServices()
(package private) <T> ServiceController<T>
install(ServiceBuilderImpl<T> serviceBuilder)
InstallserviceBuilder
in this target.(package private) boolean
isAutoShutdown()
boolean
isShutdown()
Whether container have been shut down.boolean
isShutdownComplete()
Determine whether the container is completely shut down.(package private) void
removeFailed(ServiceController<?> controller)
(package private) void
removeProblem(ServiceController<?> controller)
void
shutdown()
Stop all services within this container.private void
shutdownComplete(long started)
-
Methods inherited from class org.jboss.msc.service.ServiceTargetImpl
addDependency, addDependency, addDependency, addListener, addListener, addListener, addMonitor, addMonitors, addService, addServiceValue, batchTarget, createServiceBuilder, getDependencies, getListeners, getMonitors, removeDependency, removeListener, removeMonitor, subTarget
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jboss.msc.service.ServiceTarget
addDependency, addDependency, addDependency, addListener, addListener, addListener, addMonitor, addMonitors, addService, addServiceValue, batchTarget, getDependencies, getListeners, getMonitors, removeDependency, removeListener, removeMonitor, subTarget
-
-
-
-
Field Detail
-
SERIAL
private static final java.util.concurrent.atomic.AtomicInteger SERIAL
-
PROFILE_OUTPUT
static final java.lang.String PROFILE_OUTPUT
-
registry
private final java.util.concurrent.ConcurrentMap<ServiceName,ServiceRegistrationImpl> registry
-
start
private final long start
-
problems
private final java.util.Set<ServiceController<?>> problems
-
failed
private final java.util.Set<ServiceController<?>> failed
-
lock
private final java.lang.Object lock
-
unstableServices
private int unstableServices
-
shutdownInitiated
private long shutdownInitiated
-
terminateListeners
private final java.util.List<ServiceContainer.TerminateListener> terminateListeners
-
autoShutdown
private final boolean autoShutdown
-
profileOutput
private final java.io.Writer profileOutput
-
terminateInfo
private ServiceContainer.TerminateListener.Info terminateInfo
-
down
private volatile boolean down
-
executor
private final ServiceContainerImpl.ContainerExecutor executor
-
name
private final java.lang.String name
-
mBeanServer
private final javax.management.MBeanServer mBeanServer
-
objectName
private final javax.management.ObjectName objectName
-
containerMXBean
private final ServiceContainerMXBean containerMXBean
-
executorSeq
private static final java.util.concurrent.atomic.AtomicInteger executorSeq
-
HANDLER
private static final java.lang.Thread.UncaughtExceptionHandler HANDLER
-
POLICY
private static final java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy POLICY
-
-
Method Detail
-
removeProblem
void removeProblem(ServiceController<?> controller)
-
removeFailed
void removeFailed(ServiceController<?> controller)
-
incrementUnstableServices
void incrementUnstableServices()
-
addProblem
void addProblem(ServiceController<?> controller)
-
addFailed
void addFailed(ServiceController<?> controller)
-
decrementUnstableServices
void decrementUnstableServices()
-
isAutoShutdown
boolean isAutoShutdown()
-
getName
public java.lang.String getName()
Description copied from interface:ServiceContainer
Get the name of this service container.- Specified by:
getName
in interfaceServiceContainer
- Returns:
- the container name
-
getProfileOutput
java.io.Writer getProfileOutput()
-
getStart
long getStart()
-
addTerminateListener
public void addTerminateListener(ServiceContainer.TerminateListener listener)
Description copied from interface:ServiceContainer
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() throws java.lang.InterruptedException
Description copied from interface:ServiceContainer
Causes the current thread to wait until the container is shutdown.- Specified by:
awaitTermination
in interfaceServiceContainer
- Throws:
java.lang.InterruptedException
- if the current thread is interrupted while waiting
-
awaitTermination
public void awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Description copied from interface:ServiceContainer
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:
java.lang.InterruptedException
- if the current thread is interrupted while waiting
-
awaitStability
public void awaitStability() throws java.lang.InterruptedException
Description copied from interface:ServiceContainer
Causes the current thread to wait until the container is stable.- Specified by:
awaitStability
in 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.InterruptedException
Description copied from interface:ServiceContainer
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:
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
Description copied from interface:ServiceContainer
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:
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.InterruptedException
Description copied from interface:ServiceContainer
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:
java.lang.InterruptedException
- if the current thread is interrupted while waiting
-
getServiceRegistry
public ServiceRegistry getServiceRegistry()
Description copied from class:ServiceTargetImpl
Returns the serviceRegistry that contains all services installed by this target.- Overrides:
getServiceRegistry
in classServiceTargetImpl
- Returns:
- the serviceRegistry containing services installed by this target
-
isShutdown
public boolean isShutdown()
Description copied from interface:ServiceContainer
Whether container have been shut down.- Specified by:
isShutdown
in interfaceServiceContainer
- Returns:
true
if container is shutting down
-
shutdown
public void shutdown()
Description copied from interface:ServiceContainer
Stop all services within this container.- Specified by:
shutdown
in interfaceServiceContainer
-
isShutdownComplete
public boolean isShutdownComplete()
Description copied from interface:ServiceContainer
Determine whether the container is completely shut down.- Specified by:
isShutdownComplete
in interfaceServiceContainer
- Returns:
true
if shutdown is complete
-
dumpServices
public void dumpServices()
Description copied from interface:ServiceContainer
Dump a complete list of services toSystem.out
.- Specified by:
dumpServices
in interfaceServiceContainer
-
dumpServices
public void dumpServices(java.io.PrintStream out)
Description copied from interface:ServiceContainer
Dump a complete list of services to the given stream.- Specified by:
dumpServices
in interfaceServiceContainer
- Parameters:
out
- the stream to which the service list should be written
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
shutdownComplete
private void shutdownComplete(long started)
-
getExecutor
java.util.concurrent.Executor getExecutor()
-
getOrCreateRegistration
private ServiceRegistrationImpl getOrCreateRegistration(ServiceName name)
Atomically get or create a registration.- Parameters:
name
- the service name- Returns:
- the registration
-
getRequiredService
public ServiceController<?> getRequiredService(ServiceName serviceName) throws ServiceNotFoundException
Description copied from interface:ServiceRegistry
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)
Description copied from interface:ServiceRegistry
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 java.util.List<ServiceName> getServiceNames()
Description copied from interface:ServiceRegistry
Get a list of service names installed in this registry.- Specified by:
getServiceNames
in interfaceServiceRegistry
- Returns:
- the list
-
apply
void apply(ServiceBuilderImpl<?> builder, ServiceControllerImpl<?> parent)
-
apply
void apply(ServiceBuilderImpl<?> builder)
Description copied from class:ServiceTargetImpl
Apply listeners and dependencies toserviceBuilder
.- Overrides:
apply
in classServiceTargetImpl
- Parameters:
builder
- serviceBuilder which listeners and dependencies will be added to.
-
install
<T> ServiceController<T> install(ServiceBuilderImpl<T> serviceBuilder) throws DuplicateServiceException
Description copied from class:ServiceTargetImpl
InstallserviceBuilder
in this target.- Overrides:
install
in classServiceTargetImpl
- Parameters:
serviceBuilder
- a serviceBuilder created by this ServiceTarget- Returns:
- the installed service controller
- Throws:
DuplicateServiceException
-
detectCircularity
private <T> void detectCircularity(ServiceControllerImpl<T> instance) throws CircularDependencyException
Detects if installation ofinstance
results in dependency cycles.- Parameters:
instance
- the service being installed- Throws:
CircularDependencyException
- if a dependency cycle involvinginstance
is detected
-
detectCircularity
private void detectCircularity(IdentityHashSet<? extends Dependent> dependents, ServiceControllerImpl<?> instance, java.util.Set<ServiceControllerImpl<?>> visited, java.util.Deque<ServiceName> visitStack)
-
-