Class ServiceStateModel

java.lang.Object
org.apache.hadoop.service.ServiceStateModel

@Public @Evolving public class ServiceStateModel extends Object
Implements the service state model.
  • Constructor Details

    • ServiceStateModel

      public ServiceStateModel(String name)
      Create the service state model in the Service.STATE.NOTINITED state.
      Parameters:
      name - input name.
    • ServiceStateModel

      public ServiceStateModel(String name, Service.STATE state)
      Create a service state model instance in the chosen state
      Parameters:
      state - the starting state
      name - input name.
  • Method Details

    • getState

      public Service.STATE getState()
      Query the service state. This is a non-blocking operation.
      Returns:
      the state
    • isInState

      public boolean isInState(Service.STATE proposed)
      Query that the state is in a specific state
      Parameters:
      proposed - proposed new state
      Returns:
      the state
    • ensureCurrentState

      public void ensureCurrentState(Service.STATE expectedState)
      Verify that that a service is in a given state.
      Parameters:
      expectedState - the desired state
      Throws:
      ServiceStateException - if the service state is different from the desired state
    • enterState

      public Service.STATE enterState(Service.STATE proposed)
      Enter a state -thread safe.
      Parameters:
      proposed - proposed new state
      Returns:
      the original state
      Throws:
      ServiceStateException - if the transition is not permitted
    • checkStateTransition

      public static void checkStateTransition(String name, Service.STATE state, Service.STATE proposed)
      Check that a state tansition is valid and throw an exception if not
      Parameters:
      name - name of the service (can be null)
      state - current state
      proposed - proposed new state
    • isValidStateTransition

      public static boolean isValidStateTransition(Service.STATE current, Service.STATE proposed)
      Is a state transition valid? There are no checks for current==proposed as that is considered a non-transition. using an array kills off all branch misprediction costs, at the expense of cache line misses.
      Parameters:
      current - current state
      proposed - proposed new state
      Returns:
      true if the transition to a new state is valid
    • toString

      public String toString()
      return the state text as the toString() value
      Overrides:
      toString in class Object
      Returns:
      the current state's description