Package org.apache.mina.statemachine
Class StateMachine
- java.lang.Object
-
- org.apache.mina.statemachine.StateMachine
-
public class StateMachine extends java.lang.ObjectRepresents a complete state machine. Contains a collection ofStateobjects connected byTransitions. Normally you wouldn't create instances of this class directly but rather use theStateannotation to define your states and then letStateMachineFactorycreate aStateMachinefor you.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCALL_STACKprivate java.lang.ThreadLocal<java.util.LinkedList<Event>>eventQueueThreadLocalprivate static org.slf4j.LoggerLOGGERprivate java.lang.ThreadLocal<java.lang.Boolean>processingThreadLocalprivate StatestartStateprivate java.util.Map<java.lang.String,State>states
-
Constructor Summary
Constructors Constructor Description StateMachine(java.util.Collection<State> states, java.lang.String startStateId)Creates a new instance using the specifiedStates and start state.StateMachine(State[] states, java.lang.String startStateId)Creates a new instance using the specifiedStates and start state.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidexecuteOnEntries(StateContext context, State state)(package private) voidexecuteOnExits(StateContext context, State state)private java.util.Deque<State>getCallStack(StateContext context)StategetState(java.lang.String id)Returns theStatewith the specified id.java.util.Collection<State>getStates()voidhandle(Event event)Processes the specifiedEventthrough thisStateMachine.private voidhandle(State state, Event event)private voidprocessEvents(java.util.LinkedList<Event> eventQueue)private voidsetCurrentState(StateContext context, State newState)
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
CALL_STACK
private static final java.lang.String CALL_STACK
-
startState
private final State startState
-
states
private final java.util.Map<java.lang.String,State> states
-
processingThreadLocal
private final java.lang.ThreadLocal<java.lang.Boolean> processingThreadLocal
-
eventQueueThreadLocal
private final java.lang.ThreadLocal<java.util.LinkedList<Event>> eventQueueThreadLocal
-
-
Method Detail
-
getState
public State getState(java.lang.String id)
Returns theStatewith the specified id.- Parameters:
id- the id of theStateto return.- Returns:
- the
State - Throws:
NoSuchStateException- if no matchingStatecould be found.
-
getStates
public java.util.Collection<State> getStates()
- Returns:
- an unmodifiable
Collectionof allStates used by thisStateMachine.
-
handle
public void handle(Event event)
Processes the specifiedEventthrough thisStateMachine. Normally you wouldn't call this directly but rather useStateMachineProxyBuilderto create a proxy for an interface of your choice. Any method calls on the proxy will be translated intoEventobjects and then fed to theStateMachineby the proxy using this method.- Parameters:
event- theEventto be handled.
-
processEvents
private void processEvents(java.util.LinkedList<Event> eventQueue)
-
getCallStack
private java.util.Deque<State> getCallStack(StateContext context)
-
setCurrentState
private void setCurrentState(StateContext context, State newState)
-
executeOnExits
void executeOnExits(StateContext context, State state)
-
executeOnEntries
void executeOnEntries(StateContext context, State state)
-
-