Service.Listener
Date: 2016-05-24

com.google.common.util.concurrent

## Class Service.Listener

- java.lang.Object
- - com.google.common.util.concurrent.Service.Listener

- Enclosing interface:
    Service

      @Beta
      public abstract static class Service.Listener
      extends java.lang.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.

  Since:
    15.0 (present as an interface in 13.0)

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Service.Listener()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `failed(Service.State from, java.lang.Throwable failure)` Called when the service transitions to the FAILED state.
    `void` | `running()` Called when the service transitions from STARTING to RUNNING.
    `void` | `starting()` Called when the service transitions from NEW to 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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Service.Listener

          public Service.Listener()

  - ### Method Detail

    - #### starting

          public void starting()

      Called when the service transitions from NEW to STARTING. This occurs when `Service.startAsync()` is called the first time.

    - #### running

          public void running()

      Called when the service transitions from STARTING to RUNNING. This occurs when a service has successfully started.

    - #### stopping

          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.
      Parameters:
        `from` - The previous state that is being transitioned from.

    - #### terminated

          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`.
      Parameters:
        `from` - The previous state that is being transitioned from. The only valid values for this are NEW, RUNNING or STOPPING.

    - #### failed

          public void failed(Service.State from,
                    java.lang.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`.
      Parameters:
        `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.