doStart and doStop
requests, responding to them with notifyStarted() and notifyStopped()
callbacks. Its subclasses must manage threads manually; consider AbstractExecutionThreadService if you need only a single execution thread.
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class | |
| private class | |
| private class | |
| private static class | AbstractService.StateSnapshot
An immutable snapshot of the current state of the service. |
| Modifier and Type | Field and Description |
|---|---|
| private final Monitor. | |
| private final Monitor. | |
| private final Monitor. | |
| private final Monitor. | |
| private final ListenerCallQueue | listeners
The listeners to notify during a state transition. |
| private final Monitor | |
| private static final ListenerCallQueue. | |
| private volatile AbstractService. | snapshot
The current state of the service. |
| private static final ListenerCallQueue. | |
| private static final ListenerCallQueue. | |
| private static final ListenerCallQueue. | |
| private static final ListenerCallQueue. | |
| private static final ListenerCallQueue. | |
| private static final ListenerCallQueue. | |
| private static final ListenerCallQueue. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public final void | addListener(Service.
the listener to run when the service changes state is complete listener,the executor in which the listeners callback methods will be run. For fast,
lightweight listeners that would be safe to execute in any thread, consider executor)MoreExecutors#directExecutor.Implements com. Listener to be executed on the given
executor.
|
| public final void | awaitRunning()
Implements com. Service to reach the running state.
|
| public final void | awaitRunning(Duration
the maximum time to wait timeout)Overrides default com. Service to reach the running state for no more
than the given time.
|
| public final void | awaitRunning(long
the maximum time to wait timeout, TimeUnit the time unit of the timeout argument unit)Implements com. Service to reach the running state for no more
than the given time.
|
| public final void | awaitTerminated()
Implements com. Service to reach the terminated state.
|
| public final void | awaitTerminated(Duration
the maximum time to wait timeout)Overrides default com. Service to reach a terminal state (either terminated or failed) for no more than the given time.
|
| public final void | awaitTerminated(long
the maximum time to wait timeout, TimeUnit the time unit of the timeout argument unit)Implements com. Service to reach a terminal state (either terminated or failed) for no more than the given time.
|
| private void | checkCurrentState(Service.
Checks that the current state is equal to the expected state. |
| private void | dispatchListenerEvents()
Attempts to execute all the listeners in |
| protected void | doCancelStart()
This method is called by |
| protected abstract void | |
| protected abstract void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| public final Throwable | failureCause()
Implements com. Throwable that caused this service to fail.
|
| public final boolean | isRunning()
Implements com. true if this service is running.
|
| protected final void | |
| protected final void | |
| protected final void | |
| public final Service | startAsync()
Implements com. State#NEW, this initiates service startup and returns
immediately.
|
| public final Service. | state()
Implements com. |
| public final Service | stopAsync()
Implements com. |
| private static ListenerCallQueue. | |
| private static ListenerCallQueue. | |
| public String |
| hasReachedRunning | back to summary |
|---|---|
| private final Monitor. | |
| isStartable | back to summary |
|---|---|
| private final Monitor. | |
| isStoppable | back to summary |
|---|---|
| private final Monitor. | |
| isStopped | back to summary |
|---|---|
| private final Monitor. | |
| listeners | back to summary |
|---|---|
| private final ListenerCallQueue<Service. The listeners to notify during a state transition. | |
| monitor | back to summary |
|---|---|
| private final Monitor monitor | |
| RUNNING_EVENT | back to summary |
|---|---|
| private static final ListenerCallQueue. | |
| snapshot | back to summary |
|---|---|
| private volatile AbstractService. The current state of the service. This should be written with the lock held but can be read
without it because it is an immutable object in a volatile field. This is desirable so that
methods like To update this field correctly the lock must be held to guarantee that the state is consistent. | |
| STARTING_EVENT | back to summary |
|---|---|
| private static final ListenerCallQueue. | |
| STOPPING_FROM_RUNNING_EVENT | back to summary |
|---|---|
| private static final ListenerCallQueue. | |
| STOPPING_FROM_STARTING_EVENT | back to summary |
|---|---|
| private static final ListenerCallQueue. | |
| TERMINATED_FROM_NEW_EVENT | back to summary |
|---|---|
| private static final ListenerCallQueue. | |
| TERMINATED_FROM_RUNNING_EVENT | back to summary |
|---|---|
| private static final ListenerCallQueue. | |
| TERMINATED_FROM_STARTING_EVENT | back to summary |
|---|---|
| private static final ListenerCallQueue. | |
| TERMINATED_FROM_STOPPING_EVENT | back to summary |
|---|---|
| private static final ListenerCallQueue. | |
| AbstractService | back to summary |
|---|---|
| protected AbstractService() Constructor for use by subclasses. | |
| addListener | back to summary |
|---|---|
| public final void addListener(Service. Implements com. Doc from com. Registers a
RuntimeExceptions thrown by a listener will be caught and logged. Any exception thrown
during
| |
| awaitRunning | back to summary |
|---|---|
| public final void awaitRunning() Implements com. Doc from com. Waits for the
| |
| awaitRunning | back to summary |
|---|---|
| public final void awaitRunning(Duration timeout) throws TimeoutException Overrides default com. Doc from com. Waits for the
| |
| awaitRunning | back to summary |
|---|---|
| public final void awaitRunning(long timeout, TimeUnit unit) throws TimeoutException Implements com. Doc from com. Waits for the
| |
| awaitTerminated | back to summary |
|---|---|
| public final void awaitTerminated() Implements com. Doc from com. Waits for the
| |
| awaitTerminated | back to summary |
|---|---|
| public final void awaitTerminated(Duration timeout) throws TimeoutException Overrides default com. Doc from com. Waits for the
| |
| awaitTerminated | back to summary |
|---|---|
| public final void awaitTerminated(long timeout, TimeUnit unit) throws TimeoutException Implements com. Doc from com. Waits for the
| |
| checkCurrentState | back to summary |
|---|---|
| private void checkCurrentState(Service. Checks that the current state is equal to the expected state.
| |
| dispatchListenerEvents | back to summary |
|---|---|
| private void dispatchListenerEvents() Attempts to execute all the listeners in | |
| doCancelStart | back to summary |
|---|---|
| protected void doCancelStart() This method is called by This method should return promptly; prefer to do work on a different thread where it is
convenient. It is invoked exactly once on service shutdown, even when When this method is called
| |
| doStart | back to summary |
|---|---|
| protected abstract void doStart() This method is called by This method should return promptly; prefer to do work on a different thread where it is
convenient. It is invoked exactly once on service startup, even when
| |
| doStop | back to summary |
|---|---|
| protected abstract void doStop() This method should be used to initiate service shutdown. The invocation of this method should
cause a call to This method should return promptly; prefer to do work on a different thread where it is
convenient. It is invoked exactly once on service shutdown, even when If
| |
| enqueueFailedEvent | back to summary |
|---|---|
| private void enqueueFailedEvent(final Service. | |
| enqueueRunningEvent | back to summary |
|---|---|
| private void enqueueRunningEvent() | |
| enqueueStartingEvent | back to summary |
|---|---|
| private void enqueueStartingEvent() | |
| enqueueStoppingEvent | back to summary |
|---|---|
| private void enqueueStoppingEvent(final Service. | |
| enqueueTerminatedEvent | back to summary |
|---|---|
| private void enqueueTerminatedEvent(final Service. | |
| failureCause | back to summary |
|---|---|
| public final Throwable failureCause() Implements com. Doc from com. Returns the
| |
| isRunning | back to summary |
|---|---|
| public final boolean isRunning() Implements com. Doc from com. Returns
| |
| notifyFailed | back to summary |
|---|---|
| protected final void notifyFailed(Throwable cause) Invoke this method to transition the service to the | |
| notifyStarted | back to summary |
|---|---|
| protected final void notifyStarted() Implementing classes should invoke this method once their service has started. It will cause
the service to transition from
| |
| notifyStopped | back to summary |
|---|---|
| protected final void notifyStopped() Implementing classes should invoke this method once their service has stopped. It will cause
the service to transition from
| |
| startAsync | back to summary |
|---|---|
| public final Service startAsync() Implements com. Doc from com. If the service state is
| |
| state | back to summary |
|---|---|
| public final Service. Implements com. Doc from com. Returns the lifecycle state of the service.
| |
| stopAsync | back to summary |
|---|---|
| public final Service stopAsync() Implements com. Doc from com. If the service is starting or running, this initiates service shutdown and returns immediately. If the service is new, it is terminated without having been started nor stopped. If the service has already been stopped, this method returns immediately without taking action.
| |
| stoppingEvent | back to summary |
|---|---|
| private static ListenerCallQueue. | |
| terminatedEvent | back to summary |
|---|---|
| private static ListenerCallQueue. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | isSatisfied()
Implements abstract com. |
| HasReachedRunningGuard | back to summary |
|---|---|
| pack-priv HasReachedRunningGuard() | |
| isSatisfied | back to summary |
|---|---|
| public boolean isSatisfied() Implements abstract com. Doc from com. Evaluates this guard's boolean condition. This method is always called with the associated monitor already occupied. Implementations of this method must depend only on state protected by the associated monitor, and must not modify that state.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | isSatisfied()
Implements abstract com. |
| IsStartableGuard | back to summary |
|---|---|
| pack-priv IsStartableGuard() | |
| isSatisfied | back to summary |
|---|---|
| public boolean isSatisfied() Implements abstract com. Doc from com. Evaluates this guard's boolean condition. This method is always called with the associated monitor already occupied. Implementations of this method must depend only on state protected by the associated monitor, and must not modify that state.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | isSatisfied()
Implements abstract com. |
| IsStoppableGuard | back to summary |
|---|---|
| pack-priv IsStoppableGuard() | |
| isSatisfied | back to summary |
|---|---|
| public boolean isSatisfied() Implements abstract com. Doc from com. Evaluates this guard's boolean condition. This method is always called with the associated monitor already occupied. Implementations of this method must depend only on state protected by the associated monitor, and must not modify that state.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | isSatisfied()
Implements abstract com. |
| IsStoppedGuard | back to summary |
|---|---|
| pack-priv IsStoppedGuard() | |
| isSatisfied | back to summary |
|---|---|
| public boolean isSatisfied() Implements abstract com. Doc from com. Evaluates this guard's boolean condition. This method is always called with the associated monitor already occupied. Implementations of this method must depend only on state protected by the associated monitor, and must not modify that state.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Throwable | failure
The exception that caused this service to fail. |
| pack-priv final boolean | shutdownWhenStartupFinishes
If true, the user requested a shutdown while the service was still starting up. |
| pack-priv final Service. | state
The internal state, which equals external state unless shutdownWhenStartupFinishes is true. |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv |
| failure | back to summary |
|---|---|
| pack-priv final Throwable failure The exception that caused this service to fail. This will be | |
| shutdownWhenStartupFinishes | back to summary |
|---|---|
| pack-priv final boolean shutdownWhenStartupFinishes If true, the user requested a shutdown while the service was still starting up. | |
| state | back to summary |
|---|---|
| pack-priv final Service. The internal state, which equals external state unless shutdownWhenStartupFinishes is true. | |
| StateSnapshot | back to summary |
|---|---|
| pack-priv StateSnapshot(Service. | |
| StateSnapshot | back to summary |
|---|---|
| pack-priv StateSnapshot(Service. | |
| externalState | back to summary |
|---|---|
pack-priv Service.
| |
| failureCause | back to summary |
|---|---|
pack-priv Throwable failureCause()
| |