Package org.glassfish.pfl.basic.fsm
Class StateEngine
java.lang.Object
org.glassfish.pfl.basic.fsm.StateEngine
Encodes the state transition function for a finite state machine.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Action
private static Action
private boolean
private Map
<State.Kind, Set<State>> private Map
<State.Kind, Set<State>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRepeatedly call add( State, Input, Action, State ) for each element of input.Repeatedly calls add( State, Input, Guard, Action, State ) for each element of input.Add a transition with a guard that always evaluates to true.Add a new transition (old,in,guard,act,new) to the state engine.static StateEngine
create()
Create an empty uninitialized state engine.void
Actually perform a state transition on the FSM on the runner.peek() FSM under Input in.void
done()
Called after all transitions have been added to the state engine.private void
private Action
getDefaultAction
(State currentState) private State
getDefaultNextState
(State currentState) getKindSet
(State.Kind kind) getStates
(State.Kind kind) Return the set of final states for this state engine.private void
private void
private void
(package private) void
performStateTransition
(Runner runner, Input in, State nextState, Action action, boolean debug) setDefault
(State oldState) Euaivalent to setDefault( oldState, oldState )setDefault
(State oldState, Action action, State newState) Set the default transition and action for a state.setDefault
(State oldState, State newState) Equivalent to setDefault( oldState, act, newState ) where act is an action that does nothing.void
setDefaultAction
(Action act) Set the default action used in this state engine.private void
updateStateMap
(State oldState, State newState)
-
Field Details
-
emptyAction
-
initializing
private boolean initializing -
defaultAction
-
stateKinds
-
unmodifiableStateKinds
-
-
Constructor Details
-
StateEngine
private StateEngine()
-
-
Method Details
-
create
Create an empty uninitialized state engine. -
dprint
-
getKindSet
-
updateStateMap
-
getStates
Return the set of final states for this state engine. This may be an empty set. -
add
Add a new transition (old,in,guard,act,new) to the state engine. Multiple calls to add with the same old and in are permitted, in which case only a transition in which the guard evaluates to true will be taken. If no such transition is enabled, a default will be taken. If more than one transition is enabled, one will be chosen arbitrarily. This method can only be called before done(). An attempt to call it after done() results in an IllegalStateException. -
add
public StateEngine add(State oldState, Set<Input> input, Guard guard, Action action, State newState) Repeatedly calls add( State, Input, Guard, Action, State ) for each element of input. -
add
Add a transition with a guard that always evaluates to true. -
add
Repeatedly call add( State, Input, Action, State ) for each element of input. -
setDefault
Set the default transition and action for a state. This transition will be used if no more specific transition was defined for the actual input. Repeated calls to this method simply change the default. This method can only be called before done(). An attempt to call it after done() results in an IllegalStateException. -
setDefault
Equivalent to setDefault( oldState, act, newState ) where act is an action that does nothing. -
setDefault
Euaivalent to setDefault( oldState, oldState ) -
done
public void done()Called after all transitions have been added to the state engine. This provides an opportunity for the implementation to optimize its representation before the state engine is used. This method may only be called once. An attempt to call it more than once results in an IllegalStateException.Note that a valid StateEngine must satisfy the following conditions:
- It must contain exactly one state with Kind INITIAL.
- No final state may have an outgoing transition.
-
setDefaultAction
Set the default action used in this state engine. This is the action that is called whenever there is no applicable transition. Normally this would simply flag an error. This method can only be called before done(). An attempt to call it after done() results in an IllegalStateException. -
doIt
Actually perform a state transition on the FSM on the runner.peek() FSM under Input in. -
getDefaultNextState
-
getDefaultAction
-
innerDoIt
-
performStateTransition
-
mustBeInitializing
private void mustBeInitializing() -
mustNotBeInitializing
private void mustNotBeInitializing()
-