org.apache.hadoop.service
Class ServiceStateModel

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

@InterfaceAudience.Public
@InterfaceStability.Evolving
public class ServiceStateModel
extends Object

Implements the service state model.


Constructor Summary
ServiceStateModel(String name)
          Create the service state model in the Service.STATE.NOTINITED state.
ServiceStateModel(String name, org.apache.hadoop.service.Service.STATE state)
          Create a service state model instance in the chosen state
 
Method Summary
static void checkStateTransition(String name, org.apache.hadoop.service.Service.STATE state, org.apache.hadoop.service.Service.STATE proposed)
          Check that a state tansition is valid and throw an exception if not
 void ensureCurrentState(org.apache.hadoop.service.Service.STATE expectedState)
          Verify that that a service is in a given state.
 org.apache.hadoop.service.Service.STATE enterState(org.apache.hadoop.service.Service.STATE proposed)
          Enter a state -thread safe.
 org.apache.hadoop.service.Service.STATE getState()
          Query the service state.
 boolean isInState(org.apache.hadoop.service.Service.STATE proposed)
          Query that the state is in a specific state
static boolean isValidStateTransition(org.apache.hadoop.service.Service.STATE current, org.apache.hadoop.service.Service.STATE proposed)
          Is a state transition valid? There are no checks for current==proposed as that is considered a non-transition.
 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 Detail

ServiceStateModel

public ServiceStateModel(String name)
Create the service state model in the Service.STATE.NOTINITED state.


ServiceStateModel

public ServiceStateModel(String name,
                         org.apache.hadoop.service.Service.STATE state)
Create a service state model instance in the chosen state

Parameters:
state - the starting state
Method Detail

getState

public org.apache.hadoop.service.Service.STATE getState()
Query the service state. This is a non-blocking operation.

Returns:
the state

isInState

public boolean isInState(org.apache.hadoop.service.Service.STATE proposed)
Query that the state is in a specific state

Parameters:
proposed - proposed new state
Returns:
the state

ensureCurrentState

public void ensureCurrentState(org.apache.hadoop.service.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 org.apache.hadoop.service.Service.STATE enterState(org.apache.hadoop.service.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,
                                        org.apache.hadoop.service.Service.STATE state,
                                        org.apache.hadoop.service.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(org.apache.hadoop.service.Service.STATE current,
                                             org.apache.hadoop.service.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


Copyright © 2013 Apache Software Foundation. All Rights Reserved.