Groovy Documentation

org.linkedin.groovy.util.state
[Groovy] Interface StateMachine


interface StateMachine

Represents the state machine (states, transitions and action to take on each)

Authors:
ypujante@linkedin.com


Property Summary
static java.lang.Object NONE

 
Method Summary
java.lang.Object clearError()

java.lang.Object executeAction(java.lang.Object action, java.lang.Object closure)

Execute the action: sets the state machine in transition state, execute the closure and then move to the final state.

java.lang.Object findEndState(java.lang.Object action)

Returns the end state that the state machine would be if the action were to be executed.

java.lang.Object findPaths(java.lang.Object toState)

Equivalent to findPaths(currentState, toState)

java.lang.Object findPaths(java.lang.Object fromState, java.lang.Object toState)

Returns a list of paths to go from fromState to toState.

java.lang.Object findShortestPath(java.lang.Object toState)

Equivalent to findShortestPath(currentState, toState)

java.lang.Object findShortestPath(java.lang.Object fromState, java.lang.Object toState)

Returns the shortest path (list of transitions) to go from fromState to toState

void forceChangeState(java.lang.Object currentState, java.lang.Object error)

This method is used to change the state and should be used carefully.

java.lang.Object getAvailableActions()

Returns all available actions

java.lang.Object getAvailableStates()

returns all available states

java.lang.Object getAvailableTransitions()

java.lang.Object getCurrentState()

java.lang.Object getEndState(java.lang.Object action)

Returns the end state associated to a specific action in the state machine.

java.lang.Object getError()

java.lang.Object getState()

Return a coherent view of the state (like calling each individual methods, but guaranteed to be atomic).

java.lang.Object getTransitionAction()

java.lang.Object getTransitionState()

java.lang.Object getTransitions()

void setStateChangeListener(StateChangeListener stateChangeListener)

Sets a listener to know when the state changes

java.lang.Object waitForState(java.lang.Object state, java.lang.Object timeout)

Wait for the state machine to be in the provided state.

 

Property Detail

NONE

static java.lang.Object NONE


 
Method Detail

clearError

java.lang.Object clearError()


executeAction

java.lang.Object executeAction(java.lang.Object action, java.lang.Object closure)
Execute the action: sets the state machine in transition state, execute the closure and then move to the final state. All this provided that the state transition and current state is authorizing the action. This call is a blocking call!


findEndState

java.lang.Object findEndState(java.lang.Object action)
Returns the end state that the state machine would be if the action were to be executed.
throws:
IllegalStateException if it is not possible to execute the action because the state does not allow it


findPaths

java.lang.Object findPaths(java.lang.Object toState)
Equivalent to findPaths(currentState, toState)
See Also:
findPaths(Object, Object)


findPaths

java.lang.Object findPaths(java.lang.Object fromState, java.lang.Object toState)
Returns a list of paths to go from fromState to toState. If there is no paths, then an empty list is returned. There can be mulitple paths, this is why it returns a list. Each path is a list of transitions (same as what is returned in getTransitions()).
 Example of result:
 [[[to: 'NONE', action: 'uninstall']],
  [[to: 'stopped', action: 'configure'], [to: 'NONE', action: 'uninstall']],
  ...]
 


findShortestPath

java.lang.Object findShortestPath(java.lang.Object toState)
Equivalent to findShortestPath(currentState, toState)
See Also:
findShortestPath(Object, Object)


findShortestPath

java.lang.Object findShortestPath(java.lang.Object fromState, java.lang.Object toState)
Returns the shortest path (list of transitions) to go from fromState to toState This call returns the shortest path (if there is more than one shortest path, one of them will be returned. Although no guarantee is made on which one would be returned, the same one would be returned if you call the method mutliple times)
See Also:
findPaths(Object, Object)


forceChangeState

void forceChangeState(java.lang.Object currentState, java.lang.Object error)
This method is used to change the state and should be used carefully. This method cannot be used when in transition state
Parameters:
currentState - the new current state (can be null in which case we keep the current one)
error - the new error state


getAvailableActions

java.lang.Object getAvailableActions()
Returns all available actions


getAvailableStates

java.lang.Object getAvailableStates()
returns all available states


getAvailableTransitions

java.lang.Object getAvailableTransitions()


getCurrentState

java.lang.Object getCurrentState()


getEndState

java.lang.Object getEndState(java.lang.Object action)
Returns the end state associated to a specific action in the state machine. No action is actually performed. It returns null if the given action was not found.


getError

java.lang.Object getError()


getState

java.lang.Object getState()
Return a coherent view of the state (like calling each individual methods, but guaranteed to be atomic).
Returns:
a map [currentState: x, transitionState: x, transitionAction: x, error: x] (transition* and error are optional)


getTransitionAction

java.lang.Object getTransitionAction()


getTransitionState

java.lang.Object getTransitionState()


getTransitions

java.lang.Object getTransitions()


setStateChangeListener

void setStateChangeListener(StateChangeListener stateChangeListener)
Sets a listener to know when the state changes


waitForState

java.lang.Object waitForState(java.lang.Object state, java.lang.Object timeout)
Wait for the state machine to be in the provided state. Does not wait longer than the timeout.
Parameters:
timeout - may be null for unlimited waiting
Returns:
true if the state was reached during the timeout, false otherwise


 

Groovy Documentation