@Beta public abstract static class Service.Listener extends Object
A listener for the various state changes that a Service goes through in its lifecycle.
All methods are no-ops by default, implementors should override the ones they care about.
| Constructor and Description |
|---|
Listener() |
| Modifier and Type | Method and Description |
|---|---|
void |
failed(Service.State from,
Throwable failure)
Called when the service transitions to the FAILED state.
|
void |
running()
|
void |
starting()
|
void |
stopping(Service.State from)
Called when the service transitions to the STOPPING state.
|
void |
terminated(Service.State from)
Called when the service transitions to the TERMINATED state.
|
public void starting()
Called when the service transitions from NEW to STARTING. This occurs when Service.startAsync() is called the first time.
public void running()
public void stopping(Service.State from)
Called when the service transitions to the STOPPING state. The only valid values for from are STARTING or RUNNING. This occurs when Service.stopAsync() is called.
from - The previous state that is being transitioned from.public void terminated(Service.State from)
Called when the service transitions to the TERMINATED state. The TERMINATED state is a terminal state in the transition diagram. Therefore, if this method is called, no other methods will be called on the Service.Listener.
public void failed(Service.State from, Throwable failure)
Called when the service transitions to the FAILED state. The FAILED state is a terminal state in the transition diagram.
Therefore, if this method is called, no other methods will be called on the Service.Listener.
from - The previous state that is being transitioned from. Failure can occur in any state with the exception of NEW or TERMINATED.failure - The exception that caused the failure.