private static final class ServiceManager.ServiceManagerState
extends java.lang.Object
ServiceManager
that needs to be
accessed by instances of ServiceManager.ServiceListener
.Modifier and Type | Class and Description |
---|---|
(package private) class |
ServiceManager.ServiceManagerState.AwaitHealthGuard |
(package private) class |
ServiceManager.ServiceManagerState.StoppedGuard |
Modifier and Type | Field and Description |
---|---|
(package private) Monitor.Guard |
awaitHealthGuard
Controls how long to wait for all the services to either become healthy or reach a state from
which it is guaranteed that it can never become healthy.
|
(package private) ListenerCallQueue<ServiceManager.Listener> |
listeners
The listeners to notify during a state transition.
|
(package private) Monitor |
monitor |
(package private) int |
numberOfServices |
(package private) boolean |
ready
These two booleans are used to mark the state as ready to start.
|
(package private) SetMultimap<Service.State,Service> |
servicesByState |
(package private) java.util.Map<Service,Stopwatch> |
startupTimers |
(package private) Multiset<Service.State> |
states |
(package private) Monitor.Guard |
stoppedGuard
Controls how long to wait for all services to reach a terminal state.
|
(package private) boolean |
transitioned |
Constructor and Description |
---|
ServiceManagerState(ImmutableCollection<Service> services)
It is implicitly assumed that all the services are NEW and that they will all remain NEW
until all the Listeners are installed and
markReady() is called. |
Modifier and Type | Method and Description |
---|---|
(package private) void |
addListener(ServiceManager.Listener listener,
java.util.concurrent.Executor executor) |
(package private) void |
awaitHealthy() |
(package private) void |
awaitHealthy(long timeout,
java.util.concurrent.TimeUnit unit) |
(package private) void |
awaitStopped() |
(package private) void |
awaitStopped(long timeout,
java.util.concurrent.TimeUnit unit) |
(package private) void |
checkHealthy() |
(package private) void |
dispatchListenerEvents()
Attempts to execute all the listeners in
listeners . |
(package private) void |
enqueueFailedEvent(Service service) |
(package private) void |
enqueueHealthyEvent() |
(package private) void |
enqueueStoppedEvent() |
(package private) void |
markReady()
Marks the
Service.State as ready to receive transitions. |
(package private) ImmutableSetMultimap<Service.State,Service> |
servicesByState() |
(package private) ImmutableMap<Service,java.lang.Long> |
startupTimes() |
(package private) void |
transitionService(Service service,
Service.State from,
Service.State to)
Updates the state with the given service transition.
|
(package private) void |
tryStartTiming(Service service)
Attempts to start the timer immediately prior to the service being started via
Service.startAsync() . |
final Monitor monitor
final SetMultimap<Service.State,Service> servicesByState
final Multiset<Service.State> states
boolean ready
ready
: is set by markReady()
to indicate that all listeners have been
correctly installed
transitioned
: is set by transitionService(com.google.common.util.concurrent.Service, com.google.common.util.concurrent.Service.State, com.google.common.util.concurrent.Service.State)
to indicate that some
transition has been performed.
Together, they allow us to enforce that all services have their listeners installed prior to any service performing a transition, then we can fail in the ServiceManager constructor rather than in a Service.Listener callback.
boolean transitioned
final int numberOfServices
final Monitor.Guard awaitHealthGuard
final Monitor.Guard stoppedGuard
final ListenerCallQueue<ServiceManager.Listener> listeners
ServiceManagerState(ImmutableCollection<Service> services)
markReady()
is called. It is our caller's
responsibility to only call markReady()
if all services were new at the time this
method was called and when all the listeners were installed.void tryStartTiming(Service service)
Service.startAsync()
.void markReady()
Service.State
as ready to receive transitions. Returns true if no transitions have
been observed yet.void addListener(ServiceManager.Listener listener, java.util.concurrent.Executor executor)
void awaitHealthy()
void awaitHealthy(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException
java.util.concurrent.TimeoutException
void awaitStopped()
void awaitStopped(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException
java.util.concurrent.TimeoutException
ImmutableSetMultimap<Service.State,Service> servicesByState()
ImmutableMap<Service,java.lang.Long> startupTimes()
void transitionService(Service service, Service.State from, Service.State to)
This method performs the main logic of ServiceManager in the following steps.
servicesByState()
startupTimers
void enqueueStoppedEvent()
void enqueueHealthyEvent()
void enqueueFailedEvent(Service service)
void dispatchListenerEvents()
listeners
.void checkHealthy()