ServiceStateModel (Apache Hadoop Main 3.5.0 API)
Description: declaration: package: org.apache.hadoop.service, class: ServiceStateModel

Package org.apache.hadoop.service

# Class ServiceStateModel

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

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

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ServiceStateModel(String name)`
  Create the service state model in the `Service.STATE.NOTINITED` state.
  `ServiceStateModel(String name, Service.STATE state)`
  Create a service state model instance in the chosen state

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `checkStateTransition(String name, Service.STATE state, Service.STATE proposed)`
  Check that a state tansition is valid and throw an exception if not
  `void`
  `ensureCurrentState(Service.STATE expectedState)`
  Verify that that a service is in a given state.
  `Service.STATE`
  `enterState(Service.STATE proposed)`
  Enter a state -thread safe.
  `Service.STATE`
  `getState()`
  Query the service state.
  `boolean`
  `isInState(Service.STATE proposed)`
  Query that the state is in a specific state
  `static boolean`
  `isValidStateTransition(Service.STATE current, Service.STATE proposed)`
  Is a state transition valid?
  `String`
  `toString()`
  return the state text as the toString() value

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

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

- ## 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