public class StateMachine
extends java.lang.Object
State
objects connected by Transitions. Normally you wouldn't create
instances of this class directly but rather use the
State annotation to define
your states and then let StateMachineFactory create a
StateMachine for you.| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
CALL_STACK |
private java.lang.ThreadLocal<java.util.LinkedList<Event>> |
eventQueueThreadLocal |
private static org.slf4j.Logger |
LOGGER |
private java.lang.ThreadLocal<java.lang.Boolean> |
processingThreadLocal |
private State |
startState |
private java.util.Map<java.lang.String,State> |
states |
| Constructor and Description |
|---|
StateMachine(java.util.Collection<State> states,
java.lang.String startStateId)
Creates a new instance using the specified
States and start
state. |
StateMachine(State[] states,
java.lang.String startStateId)
Creates a new instance using the specified
States and start
state. |
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
executeOnEntries(StateContext context,
State state) |
(package private) void |
executeOnExits(StateContext context,
State state) |
private java.util.Stack<State> |
getCallStack(StateContext context) |
State |
getState(java.lang.String id)
Returns the
State with the specified id. |
java.util.Collection<State> |
getStates()
|
void |
handle(Event event)
Processes the specified
Event through this StateMachine. |
private void |
handle(State state,
Event event) |
private void |
processEvents(java.util.LinkedList<Event> eventQueue) |
private void |
setCurrentState(StateContext context,
State newState) |
private static final org.slf4j.Logger LOGGER
private static final java.lang.String CALL_STACK
private final State startState
private final java.util.Map<java.lang.String,State> states
private final java.lang.ThreadLocal<java.lang.Boolean> processingThreadLocal
private final java.lang.ThreadLocal<java.util.LinkedList<Event>> eventQueueThreadLocal
public StateMachine(State[] states, java.lang.String startStateId)
States and start
state.public State getState(java.lang.String id) throws NoSuchStateException
State with the specified id.id - the id of the State to return.StateNoSuchStateException - if no matching State could be found.public void handle(Event event)
Event through this StateMachine.
Normally you wouldn't call this directly but rather use
StateMachineProxyBuilder to create a proxy for an interface of
your choice. Any method calls on the proxy will be translated into
Event objects and then fed to the StateMachine by the
proxy using this method.event - the Event to be handled.private void processEvents(java.util.LinkedList<Event> eventQueue)
private java.util.Stack<State> getCallStack(StateContext context)
private void setCurrentState(StateContext context, State newState)
void executeOnExits(StateContext context, State state)
void executeOnEntries(StateContext context, State state)