startUp, run and shutDown
methods. This class uses a single thread to execute the service; consider AbstractService
if you would like to manage any threading manually.
| Modifier and Type | Field and Description |
|---|---|
| private final Service | |
| private static final LazyLogger |
| 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.
|
| protected Executor | |
| 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 abstract void | |
| protected String | |
| protected void | |
| public final Service | startAsync()
Implements com. State#NEW, this initiates service startup and returns
immediately.
|
| protected void | |
| public final Service. | state()
Implements com. |
| public final Service | stopAsync()
Implements com. |
| public String | |
| protected void |
| delegate | back to summary |
|---|---|
| private final Service delegate | |
| logger | back to summary |
|---|---|
| private static final LazyLogger logger | |
| AbstractExecutionThreadService | back to summary |
|---|---|
| protected AbstractExecutionThreadService() 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
| |
| executor | back to summary |
|---|---|
| protected Executor executor() Returns the The default implementation returns a new | |
| 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
| |
| run | back to summary |
|---|---|
| protected abstract void run() throws Exception Run the service. This method is invoked on the execution thread. Implementations must respond to stop requests. You could poll for lifecycle changes in a work loop:
public void run() {
while (
...or you could respond to stop requests by implementing | |
| serviceName | back to summary |
|---|---|
| protected String serviceName() Returns the name of this service. Subclasses may override this method.
| |
| shutDown | back to summary |
|---|---|
| protected void shutDown() throws Exception Stop the service. This method is invoked on the execution thread. By default this method does nothing. | |
| startAsync | back to summary |
|---|---|
| public final Service startAsync() Implements com. Doc from com. If the service state is
| |
| startUp | back to summary |
|---|---|
| protected void startUp() throws Exception Start the service. This method is invoked on the execution thread. By default this method does nothing. | |
| 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.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| triggerShutdown | back to summary |
|---|---|
| protected void triggerShutdown() Invoked to request the service to stop. By default this method does nothing. Currently, this method is invoked while holding a lock. If an implementation of this method
blocks, it can prevent this service from changing state. If you need to performing a blocking
operation in order to trigger shutdown, consider instead registering a listener and
implementing | |