Package org.apache.hadoop.service
Class ServiceStateModel
java.lang.Object
org.apache.hadoop.service.ServiceStateModel
Implements the service state model.
-
Constructor Summary
ConstructorsConstructorDescriptionServiceStateModel(String name) Create the service state model in theService.STATE.NOTINITEDstate.ServiceStateModel(String name, Service.STATE state) Create a service state model instance in the chosen state -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckStateTransition(String name, Service.STATE state, Service.STATE proposed) Check that a state tansition is valid and throw an exception if notvoidensureCurrentState(Service.STATE expectedState) Verify that that a service is in a given state.enterState(Service.STATE proposed) Enter a state -thread safe.getState()Query the service state.booleanisInState(Service.STATE proposed) Query that the state is in a specific statestatic booleanisValidStateTransition(Service.STATE current, Service.STATE proposed) Is a state transition valid?toString()return the state text as the toString() value
-
Constructor Details
-
ServiceStateModel
Create the service state model in theService.STATE.NOTINITEDstate.- Parameters:
name- input name.
-
ServiceStateModel
Create a service state model instance in the chosen state- Parameters:
state- the starting statename- input name.
-
-
Method Details
-
getState
Query the service state. This is a non-blocking operation.- Returns:
- the state
-
isInState
Query that the state is in a specific state- Parameters:
proposed- proposed new state- Returns:
- the state
-
ensureCurrentState
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
Enter a state -thread safe.- Parameters:
proposed- proposed new state- Returns:
- the original state
- Throws:
ServiceStateException- if the transition is not permitted
-
checkStateTransition
Check that a state tansition is valid and throw an exception if not- Parameters:
name- name of the service (can be null)state- current stateproposed- proposed new state
-
isValidStateTransition
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 stateproposed- proposed new state- Returns:
- true if the transition to a new state is valid
-
toString
return the state text as the toString() value
-