public abstract class FSMContext7
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
protected boolean |
_debugFlag
When this flag is set to
true , this class will
print out debug messages. |
protected java.io.PrintStream |
_debugStream
Write debug output to this stream.
|
protected java.lang.String |
_name
The FSM name.
|
protected State7 |
_previousState
Stores which state a transition left.
|
protected State7 |
_state
The current state.
|
protected java.util.Deque<State7> |
_stateStack
This stack is used to store the current state when a push
transition is taken.
|
protected java.lang.String |
_transition
The current transition name.
|
protected static java.lang.String |
DEFAULT_NAME
Default state and transition name is "Default".
|
protected static int |
DEFAULT_TRANSITION_ID
The default transition identifier is zero.
|
protected static java.lang.String |
ENTRY_NAME
The state entry method name is:
"<map>_<state>__Entry_".
|
protected static java.lang.String |
EXIT_NAME
The state exit method name is:
"<map>_<state>__Exit_".
|
protected static java.lang.invoke.MethodType |
NO_ARGS_TYPE
The method signature for state entry, exit actions is:
void method() . |
protected static java.lang.String |
STATE_NAME_FORMAT
The state entry method name is:
"<map>_<state>".
|
static java.lang.String |
STATE_PROPERTY
The state change property name.
|
protected static java.lang.String |
SYSTEM_DEFAULT
The ultimate system default transition method is
"defaultTransition".
|
protected static java.lang.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(java.beans.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(java.lang.invoke.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. |
java.io.PrintStream |
getDebugStream()
Writes the debug output to this stream.
|
java.lang.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.
|
java.lang.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 java.lang.invoke.MethodHandle |
lookupMethod(java.lang.invoke.MethodHandles.Lookup lookup,
java.lang.Class<?> clazz,
java.lang.String name,
java.lang.invoke.MethodType mt)
Returns the virtual method handle found by
lookup
using the given parameters. |
protected static TransitionHandle |
lookupTransition(java.lang.invoke.MethodHandles.Lookup lookup,
java.lang.Class<?> clazz,
java.lang.String mapName,
java.lang.String stateName,
java.lang.String transName,
java.lang.invoke.MethodType mt)
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(java.beans.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(java.io.PrintStream stream)
Sets the debug output stream to the given value.
|
void |
setName(java.lang.String name)
Sets the FSM name.
|
void |
setState(State7 state)
Sets the current state to the given value.
|
protected java.lang.String |
stateName()
Returns the name of the current state or previous state
if in transition.
|
protected transient java.lang.String _name
protected transient State7 _state
null
while in
transition.protected transient java.lang.String _transition
protected transient State7 _previousState
null
.protected transient java.util.Deque<State7> _stateStack
protected transient boolean _debugFlag
true
, this class will
print out debug messages.protected transient java.io.PrintStream _debugStream
public static final java.lang.String STATE_PROPERTY
protected static final int DEFAULT_TRANSITION_ID
protected static final java.lang.String DEFAULT_NAME
protected static final java.lang.String SYSTEM_DEFAULT
protected static final java.lang.String STATE_NAME_FORMAT
protected static final java.lang.String ENTRY_NAME
protected static final java.lang.String EXIT_NAME
protected static final java.lang.String TRANSITION_NAME_FORMAT
protected static final java.lang.invoke.MethodType NO_ARGS_TYPE
void method()
.protected FSMContext7(State7 initState)
initState
- the finite state machine's start state.protected abstract void executeAction(java.lang.invoke.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 java.lang.String getName()
public boolean getDebugFlag()
true
, the state machine
will print messages to the console.true
if debug output is generated.public java.io.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 java.lang.NullPointerException
null
.java.lang.NullPointerException
public java.lang.String getTransition()
public void setName(java.lang.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(java.io.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.java.lang.NullPointerException
- if state
is null
.public void popState() throws java.util.EmptyStackException
java.util.EmptyStackException
- if the state stack is empty.public void emptyStateStack()
public void enterStartState()
enterState()
and is provided for
backward compatibility.enterState()
public void addStateChangeListener(java.beans.PropertyChangeListener listener)
listener
is null
,
no exception is thrown and no action is taken.listener
- The PropertyChangeListener to be added.public void removeStateChangeListener(java.beans.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 java.lang.String stateName()
protected void enterState()
protected void exitState()
protected static java.lang.invoke.MethodHandle lookupMethod(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<?> clazz, java.lang.String name, java.lang.invoke.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(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<?> clazz, java.lang.String mapName, java.lang.String stateName, java.lang.String transName, java.lang.invoke.MethodType mt)
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.mt
- the transition method signature.Copyright © 2015. Charles W. Rapp. All Rights Reserved. Use is subject to license terms.