final class ServiceContainerImpl extends ServiceTargetImpl implements ServiceContainer
| Modifier and Type | Class and 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 |
ServiceContainer.Factory, ServiceContainer.TerminateListener| Modifier and Type | Field and 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 and Description |
|---|
ServiceContainerImpl(java.lang.String name,
int coreSize,
long timeOut,
java.util.concurrent.TimeUnit timeOutUnit,
boolean autoShutdown) |
| Modifier and Type | Method and 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 to
serviceBuilder. |
(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 of
instance results in dependency cycles. |
void |
dumpServices()
Dump a complete list of services to
System.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, returning
null 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)
Install
serviceBuilder 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) |
addDependency, addDependency, addDependency, addListener, addListener, addListener, addMonitor, addMonitors, addService, addServiceValue, batchTarget, createServiceBuilder, getDependencies, getListeners, getMonitors, removeDependency, removeListener, removeMonitor, subTargetclone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddDependency, addDependency, addDependency, addListener, addListener, addListener, addMonitor, addMonitors, addService, addServiceValue, batchTarget, getDependencies, getListeners, getMonitors, removeDependency, removeListener, removeMonitor, subTargetprivate static final java.util.concurrent.atomic.AtomicInteger SERIAL
static final java.lang.String PROFILE_OUTPUT
private final java.util.concurrent.ConcurrentMap<ServiceName,ServiceRegistrationImpl> registry
private final long start
private final java.util.Set<ServiceController<?>> problems
private final java.util.Set<ServiceController<?>> failed
private final java.lang.Object lock
private int unstableServices
private long shutdownInitiated
private final java.util.List<ServiceContainer.TerminateListener> terminateListeners
private final boolean autoShutdown
private final java.io.Writer profileOutput
private ServiceContainer.TerminateListener.Info terminateInfo
private volatile boolean down
private final ServiceContainerImpl.ContainerExecutor executor
private final java.lang.String name
private final javax.management.MBeanServer mBeanServer
private final javax.management.ObjectName objectName
private final ServiceContainerMXBean containerMXBean
private static final java.util.concurrent.atomic.AtomicInteger executorSeq
private static final java.lang.Thread.UncaughtExceptionHandler HANDLER
private static final java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy POLICY
ServiceContainerImpl(java.lang.String name,
int coreSize,
long timeOut,
java.util.concurrent.TimeUnit timeOutUnit,
boolean autoShutdown)
void removeProblem(ServiceController<?> controller)
void removeFailed(ServiceController<?> controller)
void incrementUnstableServices()
void addProblem(ServiceController<?> controller)
void addFailed(ServiceController<?> controller)
void decrementUnstableServices()
boolean isAutoShutdown()
public java.lang.String getName()
ServiceContainergetName in interface ServiceContainerjava.io.Writer getProfileOutput()
long getStart()
public void addTerminateListener(ServiceContainer.TerminateListener listener)
ServiceContainerlistener will be invoked when this container shutdown process is complete.addTerminateListener in interface ServiceContainerlistener - the listenerpublic void awaitTermination()
throws java.lang.InterruptedException
ServiceContainerawaitTermination in interface ServiceContainerjava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic void awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
ServiceContainerawaitTermination in interface ServiceContainertimeout - the maximum time to waitunit - the time unit of the timeout argumentjava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic void awaitStability()
throws java.lang.InterruptedException
ServiceContainerawaitStability in interface ServiceContainerjava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic boolean awaitStability(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
ServiceContainerawaitStability in interface ServiceContainertimeout - the maximum time to waitunit - the time unit of the timeout argumentjava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic void awaitStability(java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problem) throws java.lang.InterruptedException
ServiceContainerawaitStability in interface ServiceContainerfailed - a set into which failed services should be copiedproblem - a set into which problem services should be copiedjava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic 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
ServiceContainerawaitStability in interface ServiceContainertimeout - the maximum time to waitunit - the time unit of the timeout argumentfailed - a set into which failed services should be copiedproblem - a set into which problem services should be copiedjava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic ServiceRegistry getServiceRegistry()
ServiceTargetImplgetServiceRegistry in class ServiceTargetImplpublic boolean isShutdown()
ServiceContainerisShutdown in interface ServiceContainertrue if container is shutting downpublic void shutdown()
ServiceContainershutdown in interface ServiceContainerpublic boolean isShutdownComplete()
ServiceContainerisShutdownComplete in interface ServiceContainertrue if shutdown is completepublic void dumpServices()
ServiceContainerSystem.out.dumpServices in interface ServiceContainerpublic void dumpServices(java.io.PrintStream out)
ServiceContainerdumpServices in interface ServiceContainerout - the stream to which the service list should be writtenprotected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwableprivate void shutdownComplete(long started)
java.util.concurrent.Executor getExecutor()
private ServiceRegistrationImpl getOrCreateRegistration(ServiceName name)
name - the service namepublic ServiceController<?> getRequiredService(ServiceName serviceName) throws ServiceNotFoundException
ServiceRegistrygetRequiredService in interface ServiceRegistryserviceName - the service nameServiceNotFoundException - if the service is not present in the registrypublic ServiceController<?> getService(ServiceName serviceName)
ServiceRegistrynull if it is not found.getService in interface ServiceRegistryserviceName - the service namenull if it is not foundpublic java.util.List<ServiceName> getServiceNames()
ServiceRegistrygetServiceNames in interface ServiceRegistryvoid apply(ServiceBuilderImpl<?> builder, ServiceControllerImpl<?> parent)
void apply(ServiceBuilderImpl<?> builder)
ServiceTargetImplserviceBuilder.apply in class ServiceTargetImplbuilder - serviceBuilder which listeners and dependencies will be added to.<T> ServiceController<T> install(ServiceBuilderImpl<T> serviceBuilder) throws DuplicateServiceException
ServiceTargetImplserviceBuilder in this target.install in class ServiceTargetImplserviceBuilder - a serviceBuilder created by this ServiceTargetDuplicateServiceExceptionprivate <T> void detectCircularity(ServiceControllerImpl<T> instance) throws CircularDependencyException
instance results in dependency cycles.instance - the service being installedCircularDependencyException - if a dependency cycle involving instance is detectedprivate void detectCircularity(IdentityHashSet<? extends Dependent> dependents, ServiceControllerImpl<?> instance, java.util.Set<ServiceControllerImpl<?>> visited, java.util.Deque<ServiceName> visitStack)