Top Description Fields Constructors Methods
org.glassfish.pfl.basic.fsm

public Class StateEngine

extends Object
Class Inheritance
Imports
java.util.Collections, .EnumMap, .HashSet, .Iterator, .Map, .Set

Encodes the state transition function for a finite state machine.
Author
Ken Cavanaugh

Field Summary

Modifier and TypeField and Description
private Action
private static Action
private boolean
private Map<State.Kind, Set<State>>
private Map<State.Kind, Set<State>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public StateEngine
add(State oldState, Input input, Guard guard, Action action, State newState)

Add a new transition (old,in,guard,act,new) to the state engine.

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.

public StateEngine
add(State oldState, Input input, Action action, State newState)

Add a transition with a guard that always evaluates to true.

public StateEngine
add(State oldState, Set<Input> input, Action action, State newState)

Repeatedly call add( State, Input, Action, State ) for each element of input.

public static StateEngine
create()

Create an empty uninitialized state engine.

public void
doIt(Runner runner, Input in, boolean debug)

Actually perform a state transition on the FSM on the runner.peek() FSM under Input in.

public 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)

private Set<State>
public Set<State>
getStates(State.Kind kind)

Return the set of final states for this state engine.

private void
innerDoIt(Runner runner, Input in, boolean debug)

private void
private void
pack-priv void
performStateTransition(Runner runner, Input in, State nextState, Action action, boolean debug)

public StateEngine
setDefault(State oldState, Action action, State newState)

Set the default transition and action for a state.

public StateEngine
setDefault(State oldState, State newState)

Equivalent to setDefault( oldState, act, newState ) where act is an action that does nothing.

public StateEngine
setDefault(State oldState)

Euaivalent to setDefault( oldState, oldState )

public void
setDefaultAction(Action act)

Set the default action used in this state engine.

private void
updateStateMap(State oldState, State newState)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultActionback to summary
private Action defaultAction
emptyActionback to summary
private static Action emptyAction
initializingback to summary
private boolean initializing
stateKindsback to summary
private Map<State.Kind, Set<State>> stateKinds
unmodifiableStateKindsback to summary
private Map<State.Kind, Set<State>> unmodifiableStateKinds

Constructor Detail

StateEngineback to summary
private StateEngine()

Method Detail

addback to summary
public StateEngine add(State oldState, Input input, Guard guard, Action action, State newState)

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.

addback to summary
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.

addback to summary
public StateEngine add(State oldState, Input input, Action action, State newState)

Add a transition with a guard that always evaluates to true.

addback to summary
public StateEngine add(State oldState, Set<Input> input, Action action, State newState)

Repeatedly call add( State, Input, Action, State ) for each element of input.

createback to summary
public static StateEngine create()

Create an empty uninitialized state engine.

doItback to summary
public void doIt(Runner runner, Input in, boolean debug)

Actually perform a state transition on the FSM on the runner.peek() FSM under Input in.

doneback to summary
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:

  1. It must contain exactly one state with Kind INITIAL.
  2. No final state may have an outgoing transition.
If either of these conditions are violated, done() throws an IllegalStateException.
dprintback to summary
private void dprint(String msg)
getDefaultActionback to summary
private Action getDefaultAction(State currentState)
getDefaultNextStateback to summary
private State getDefaultNextState(State currentState)
getKindSetback to summary
private Set<State> getKindSet(State.Kind kind)
getStatesback to summary
public Set<State> getStates(State.Kind kind)

Return the set of final states for this state engine. This may be an empty set.

innerDoItback to summary
private void innerDoIt(Runner runner, Input in, boolean debug)
mustBeInitializingback to summary
private void mustBeInitializing()
mustNotBeInitializingback to summary
private void mustNotBeInitializing()
performStateTransitionback to summary
pack-priv void performStateTransition(Runner runner, Input in, State nextState, Action action, boolean debug)
setDefaultback to summary
public StateEngine setDefault(State oldState, Action action, State newState)

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.

setDefaultback to summary
public StateEngine setDefault(State oldState, State newState)

Equivalent to setDefault( oldState, act, newState ) where act is an action that does nothing.

setDefaultback to summary
public StateEngine setDefault(State oldState)

Euaivalent to setDefault( oldState, oldState )

setDefaultActionback to summary
public void setDefaultAction(Action act)

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.

updateStateMapback to summary
private void updateStateMap(State oldState, State newState)