Class ServiceManager.ServiceManagerState
java.lang.Object
com.google.common.util.concurrent.ServiceManager.ServiceManagerState
- Enclosing class:
- ServiceManager
An encapsulation of all the mutable state of the
ServiceManager that needs to be
accessed by instances of ServiceManager.ServiceListener.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) final class(package private) final class -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final Monitor.GuardControls 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) final ListenerCallQueue<ServiceManager.Listener>The listeners to notify during a state transition.(package private) final Monitor(package private) final int(package private) booleanThese two booleans are used to mark the state as ready to start.(package private) final SetMultimap<Service.State,Service> (package private) final Multiset<Service.State>(package private) final Monitor.GuardControls how long to wait for all services to reach a terminal state.(package private) boolean -
Constructor Summary
ConstructorsConstructorDescriptionServiceManagerState(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 andmarkReady()is called. -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddListener(ServiceManager.Listener listener, Executor executor) (package private) void(package private) voidawaitHealthy(long timeout, TimeUnit unit) (package private) void(package private) voidawaitStopped(long timeout, TimeUnit unit) (package private) void(package private) voidAttempts to execute all the listeners inlisteners.(package private) voidenqueueFailedEvent(Service service) (package private) void(package private) void(package private) voidMarks theService.Stateas ready to receive transitions.(package private) ImmutableSetMultimap<Service.State,Service> (package private) ImmutableMap<Service,Long> (package private) voidtransitionService(Service service, Service.State from, Service.State to) Updates the state with the given service transition.(package private) voidtryStartTiming(Service service) Attempts to start the timer immediately prior to the service being started viaService.startAsync().
-
Field Details
-
monitor
-
servicesByState
-
states
-
startupTimers
-
ready
boolean readyThese two booleans are used to mark the state as ready to start.ready: is set bymarkReady()to indicate that all listeners have been correctly installedtransitioned: is set bytransitionService(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.
-
transitioned
boolean transitioned -
numberOfServices
final int numberOfServices -
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. -
stoppedGuard
Controls how long to wait for all services to reach a terminal state. -
listeners
The listeners to notify during a state transition.
-
-
Constructor Details
-
ServiceManagerState
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 andmarkReady()is called. It is our caller's responsibility to only callmarkReady()if all services were new at the time this method was called and when all the listeners were installed.
-
-
Method Details
-
tryStartTiming
Attempts to start the timer immediately prior to the service being started viaService.startAsync(). -
markReady
void markReady()Marks theService.Stateas ready to receive transitions. Returns true if no transitions have been observed yet. -
addListener
-
awaitHealthy
void awaitHealthy() -
awaitHealthy
- Throws:
TimeoutException
-
awaitStopped
void awaitStopped() -
awaitStopped
- Throws:
TimeoutException
-
servicesByState
ImmutableSetMultimap<Service.State,Service> servicesByState() -
startupTimes
ImmutableMap<Service,Long> startupTimes() -
transitionService
Updates the state with the given service transition.This method performs the main logic of ServiceManager in the following steps.
- Update the
servicesByState() - Update the
startupTimers - Based on the new state queue listeners to run
- Run the listeners (outside of the lock)
- Update the
-
enqueueStoppedEvent
void enqueueStoppedEvent() -
enqueueHealthyEvent
void enqueueHealthyEvent() -
enqueueFailedEvent
-
dispatchListenerEvents
void dispatchListenerEvents()Attempts to execute all the listeners inlisteners. -
checkHealthy
void checkHealthy()
-