public abstract class FSMContext7 extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected static String |
DEFAULT_NAME
Default state and transition name is "Default".
|
protected static int |
DEFAULT_TRANSITION_ID
The default transition identifier is zero.
|
protected static String |
ENTRY_NAME
The state entry method name is:
"<map>_<state>__Entry_".
|
protected static String |
EXIT_NAME
The state exit method name is:
"<map>_<state>__Exit_".
|
protected boolean |
mDebugFlag
When this flag is set to
true , this class will
print out debug messages. |
protected PrintStream |
mDebugStream
Write debug output to this stream.
|
protected String |
mName
The FSM name.
|
protected State7 |
mPreviousState
Stores which state a transition left.
|
protected State7 |
mState
The current state.
|
protected Deque<State7> |
mStateStack
This stack is used to store the current state when a push
transition is taken.
|
protected String |
mTransition
The current transition name.
|
protected static MethodType |
NO_ARGS_TYPE
The method signature for state entry, exit actions is:
void <method name>() . |
protected static String |
STATE_NAME_FORMAT
The state entry method name is:
"<map>_<state>".
|
static String |
STATE_PROPERTY
The state change property name.
|
protected static String |
SYSTEM_DEFAULT
The ultimate system default transition method is
"defaultTransition".
|
protected static String |
TRANSITION_NAME_FORMAT
The state exit method name is:
"<map>_<state>_<transition>".
|
Modifier | Constructor and Description |
---|---|
protected |
FSMContext7(State7 initState)
Creates a finite state machine context for the given
initial state.
|
Modifier and Type | Method and Description |
---|---|
void |
addStateChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list.
|
void |
clearState()
Places the current state into the previous state sets
the current state to
null . |
protected void |
defaultTransition()
The default Default state/Default transition definition is
to throw a
TransitionUndefinedException which
contains the current state and current transition in the
detailed message. |
void |
emptyStateStack()
Empties the state stack.
|
void |
enterStartState()
Executes the current state entry action.
|
protected void |
enterState()
Executes the current state entry action, if defined.
|
protected abstract void |
executeAction(MethodHandle mh)
Executes the state entry or exit action.
|
protected void |
exitState()
Executes the current state exit action, if defined.
|
boolean |
getDebugFlag()
When debug is set to
true , the state machine
will print messages to the console. |
PrintStream |
getDebugStream()
Writes the debug output to this stream.
|
String |
getName()
Returns the FSM name.
|
State7 |
getPreviousState()
If this FSM is in transition, then returns the previous
state which the last transition left.
|
State7 |
getState()
Returns the current state.
|
String |
getTransition()
If this FSM is in transition, then returns the transition
name.
|
boolean |
isInTransition()
Returns
true if this FSM is in a transition and
false otherwise. |
protected static MethodHandle |
lookupMethod(MethodHandles.Lookup lookup,
Class<?> clazz,
String name,
MethodType mt)
Returns the virtual method handle found by
lookup
using the given parameters. |
protected static TransitionHandle |
lookupTransition(MethodHandles.Lookup lookup,
Class<?> clazz,
String mapName,
String stateName,
String transName,
MethodType methodType)
Returns the transition method handle for the given map,
state, transition name, and transition method signature.
|
void |
popState()
Sets the previous state to the current state and pops
the top state off the stack and places it into the
current state.
|
void |
pushState(State7 state)
Pushes the current state on top of the state stack and
sets the current state to
state . |
void |
removeStateChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener for the state change
property.
|
void |
setDebugFlag(boolean flag)
Turns debug output on if
flag is true and
off if flag is false . |
void |
setDebugStream(PrintStream stream)
Sets the debug output stream to the given value.
|
void |
setName(String name)
Sets the FSM name.
|
void |
setState(State7 state)
Sets the current state to the given value.
|
protected String |
stateName()
Returns the name of the current state or previous state
if in transition.
|
public static final String STATE_PROPERTY
protected static final int DEFAULT_TRANSITION_ID
protected static final String DEFAULT_NAME
protected static final String SYSTEM_DEFAULT
protected static final String STATE_NAME_FORMAT
protected static final String ENTRY_NAME
protected static final String EXIT_NAME
protected static final String TRANSITION_NAME_FORMAT
protected static final MethodType NO_ARGS_TYPE
void <method name>()
.protected transient String mName
protected transient State7 mState
null
while in
transition.protected transient String mTransition
protected transient State7 mPreviousState
null
.protected transient Deque<State7> mStateStack
protected transient boolean mDebugFlag
true
, this class will
print out debug messages.protected transient PrintStream mDebugStream
protected FSMContext7(State7 initState)
initState
- the finite state machine's start state.protected abstract void executeAction(MethodHandle mh)
MethodHandle.invokeExact(Object[])
requires that
the method be invoked against the subclass instance, the
entry/exit method handle is passed to the subclass for
execution.mh
- execute this method handle.enterStartState()
,
enterState()
,
exitState()
public String getName()
public boolean getDebugFlag()
true
, the state machine
will print messages to the console.true
if debug output is generated.public PrintStream getDebugStream()
public boolean isInTransition()
true
if this FSM is in a transition and
false
otherwise.true
if this FSM is in a transition and
false
otherwise.public State7 getState() throws StateUndefinedException
StateUndefinedException
- if the FSM is in transition.public State7 getPreviousState() throws NullPointerException
null
.NullPointerException
public String getTransition()
public void setName(String name)
name
- The finite state machine name.public void setDebugFlag(boolean flag)
flag
is true
and
off if flag
is false
.flag
- true
to turn debuggin on and
false
to turn debugging off.public void setDebugStream(PrintStream stream)
stream
- The debug output stream.public void setState(State7 state)
state
- The current state.public void clearState()
null
.public void pushState(State7 state)
state
.state
- The new current state.NullPointerException
- if state
is null
.public void popState() throws EmptyStackException
EmptyStackException
- if the state stack is empty.public void emptyStateStack()
public void enterStartState()
enterState()
and is provided for
backward compatibility.enterState()
public void addStateChangeListener(PropertyChangeListener listener)
listener
is null
,
no exception is thrown and no action is taken.listener
- The PropertyChangeListener to be added.public void removeStateChangeListener(PropertyChangeListener listener)
listener
was added more than once
to the same event source, it will be notified one less
time after being removed. If listener
is
null
or was never added, no exception is thrown
and no action is taken.listener
- The PropertyChangeListener to be removed.protected void defaultTransition()
TransitionUndefinedException
which
contains the current state and current transition in the
detailed message.protected String stateName()
protected void enterState()
protected void exitState()
protected static MethodHandle lookupMethod(MethodHandles.Lookup lookup, Class<?> clazz, String name, MethodType mt)
lookup
using the given parameters. If the lookup fails, then
returns null
.lookup
- used to retrieve the virtual method handle.clazz
- the method is implemented in this class.name
- the method name.mt
- the method signature.protected static TransitionHandle lookupTransition(MethodHandles.Lookup lookup, Class<?> clazz, String mapName, String stateName, String transName, MethodType methodType)
defaultTransition()
lookup
- used to retrieve the virtual method handle.clazz
- the method is implemented in this class.mapName
- the map name.stateName
- the state name.transName
- the transition name.methodType
- the transition method signature.Copyright © 2020. All rights reserved.