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) classServiceContainerImpl.ContainerExecutor(package private) static classServiceContainerImpl.LatchListener(package private) static classServiceContainerImpl.ServiceThreadprivate static classServiceContainerImpl.ShutdownHookHolder(package private) classServiceContainerImpl.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 booleanautoShutdownprivate ServiceContainerMXBeancontainerMXBeanprivate booleandownprivate ServiceContainerImpl.ContainerExecutorexecutorprivate static java.util.concurrent.atomic.AtomicIntegerexecutorSeqprivate java.util.Set<ServiceController<?>>failedprivate static java.lang.Thread.UncaughtExceptionHandlerHANDLERprivate java.lang.Objectlockprivate javax.management.MBeanServermBeanServerprivate java.lang.Stringnameprivate javax.management.ObjectNameobjectNameprivate static java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicyPOLICYprivate java.util.Set<ServiceController<?>>problems(package private) static java.lang.StringPROFILE_OUTPUTprivate java.io.WriterprofileOutputprivate java.util.concurrent.ConcurrentMap<ServiceName,ServiceRegistrationImpl>registryprivate static java.util.concurrent.atomic.AtomicIntegerSERIALprivate longshutdownInitiatedprivate longstartprivate ServiceContainer.TerminateListener.InfoterminateInfoprivate java.util.List<ServiceContainer.TerminateListener>terminateListenersprivate intunstableServices
-
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) voidaddFailed(ServiceController<?> controller)(package private) voidaddProblem(ServiceController<?> controller)voidaddTerminateListener(ServiceContainer.TerminateListener listener)Add a terminate listener to this container.(package private) voidapply(ServiceBuilderImpl<?> builder)Apply listeners and dependencies toserviceBuilder.(package private) voidapply(ServiceBuilderImpl<?> builder, ServiceControllerImpl<?> parent)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.(package private) voiddecrementUnstableServices()private voiddetectCircularity(IdentityHashSet<? extends Dependent> dependents, ServiceControllerImpl<?> instance, java.util.Set<ServiceControllerImpl<?>> visited, java.util.Deque<ServiceName> visitStack)private <T> voiddetectCircularity(ServiceControllerImpl<T> instance)Detects if installation ofinstanceresults in dependency cycles.voiddumpServices()Dump a complete list of services toSystem.out.voiddumpServices(java.io.PrintStream out)Dump a complete list of services to the given stream.protected voidfinalize()(package private) java.util.concurrent.ExecutorgetExecutor()java.lang.StringgetName()Get the name of this service container.private ServiceRegistrationImplgetOrCreateRegistration(ServiceName name)Atomically get or create a registration.(package private) java.io.WritergetProfileOutput()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.ServiceRegistrygetServiceRegistry()Returns the serviceRegistry that contains all services installed by this target.(package private) longgetStart()(package private) voidincrementUnstableServices()(package private) <T> ServiceController<T>install(ServiceBuilderImpl<T> serviceBuilder)InstallserviceBuilderin this target.(package private) booleanisAutoShutdown()booleanisShutdown()Whether container have been shut down.booleanisShutdownComplete()Determine whether the container is completely shut down.(package private) voidremoveFailed(ServiceController<?> controller)(package private) voidremoveProblem(ServiceController<?> controller)voidshutdown()Stop all services within this container.private voidshutdownComplete(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:ServiceContainerGet the name of this service container.- Specified by:
getNamein interfaceServiceContainer- Returns:
- the container name
-
getProfileOutput
java.io.Writer getProfileOutput()
-
getStart
long getStart()
-
addTerminateListener
public void addTerminateListener(ServiceContainer.TerminateListener listener)
Description copied from interface:ServiceContainerAdd 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() throws java.lang.InterruptedExceptionDescription copied from interface:ServiceContainerCauses the current thread to wait until the container is shutdown.- Specified by:
awaitTerminationin 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.InterruptedExceptionDescription copied from interface:ServiceContainerCauses 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.InterruptedExceptionDescription copied from interface:ServiceContainerCauses 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.InterruptedExceptionDescription copied from interface:ServiceContainerCauses 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
Description copied from interface:ServiceContainerCauses 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.InterruptedExceptionDescription copied from interface:ServiceContainerCauses 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
-
getServiceRegistry
public ServiceRegistry getServiceRegistry()
Description copied from class:ServiceTargetImplReturns the serviceRegistry that contains all services installed by this target.- Overrides:
getServiceRegistryin classServiceTargetImpl- Returns:
- the serviceRegistry containing services installed by this target
-
isShutdown
public boolean isShutdown()
Description copied from interface:ServiceContainerWhether container have been shut down.- Specified by:
isShutdownin interfaceServiceContainer- Returns:
trueif container is shutting down
-
shutdown
public void shutdown()
Description copied from interface:ServiceContainerStop all services within this container.- Specified by:
shutdownin interfaceServiceContainer
-
isShutdownComplete
public boolean isShutdownComplete()
Description copied from interface:ServiceContainerDetermine whether the container is completely shut down.- Specified by:
isShutdownCompletein interfaceServiceContainer- Returns:
trueif shutdown is complete
-
dumpServices
public void dumpServices()
Description copied from interface:ServiceContainerDump a complete list of services toSystem.out.- Specified by:
dumpServicesin interfaceServiceContainer
-
dumpServices
public void dumpServices(java.io.PrintStream out)
Description copied from interface:ServiceContainerDump a complete list of services to the given stream.- Specified by:
dumpServicesin interfaceServiceContainer- Parameters:
out- the stream to which the service list should be written
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein 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:ServiceRegistryGet 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)
Description copied from interface:ServiceRegistryGet 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()
Description copied from interface:ServiceRegistryGet a list of service names installed in this registry.- Specified by:
getServiceNamesin interfaceServiceRegistry- Returns:
- the list
-
apply
void apply(ServiceBuilderImpl<?> builder, ServiceControllerImpl<?> parent)
-
apply
void apply(ServiceBuilderImpl<?> builder)
Description copied from class:ServiceTargetImplApply listeners and dependencies toserviceBuilder.- Overrides:
applyin 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:ServiceTargetImplInstallserviceBuilderin this target.- Overrides:
installin 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 ofinstanceresults in dependency cycles.- Parameters:
instance- the service being installed- Throws:
CircularDependencyException- if a dependency cycle involvinginstanceis detected
-
detectCircularity
private void detectCircularity(IdentityHashSet<? extends Dependent> dependents, ServiceControllerImpl<?> instance, java.util.Set<ServiceControllerImpl<?>> visited, java.util.Deque<ServiceName> visitStack)
-
-