public abstract class StateMachine extends java.lang.Object implements StateEngineObserver
StateMachine
provides an abstract base class for implementing a Finite State Machine
(FMS). An instance of concrete StateMachine
uses a code generated concrete implementation
of StateEngine
to implement and execute the state machine.Modifier | Constructor and Description |
---|---|
protected |
StateMachine() |
Modifier and Type | Method and Description |
---|---|
protected StateEngine<?> |
createStateEngine()
Creates the
StateEngine . |
<T extends StateEngine<?>> |
getCurrentState()
Gets the current state
StateEngine that is an instance of code generated class. |
<T extends StateEngine<?>> |
getStateEngine()
Gets the
StateEngine that is an instance of concrete implementation of
a StateEngine code generated by Fuusio FSM Annotation Processor. |
boolean |
isCurrentState(java.lang.Class<? extends StateEngine<?>> stateClass)
Tests if the current state is the specified one.
|
boolean |
isCurrentSuperState(java.lang.Class<? extends StateEngine<?>> superStateClass)
Tests if the current state has the specified super state.
|
boolean |
isStarted()
Tests if this
StateMachine has been started. |
void |
onDispose(StateEngine<?> stateEngine)
Invoked when the observed
StateEngine is being disposed. |
void |
onError(StateEngine<?> stateEngine,
StateEngine.Error error,
java.lang.String message)
Invoked when the specified error is deteceted in the observed
StateEngine . |
void |
onReset(StateEngine<?> stateEngine)
Invoked when the observed
StateEngine is resetted. |
void |
onStart(StateEngine<?> stateEngine)
Invoked when the observed
StateEngine is started. |
protected void |
onStateEngineCreated(StateEngine<?> stateEngine) |
void |
onStop(StateEngine<?> stateEngine)
Invoked when the observed
StateEngine is stopped. |
void |
reset()
Reset this
StateMachine . |
abstract void |
start()
Starts this
StateMachine by starting the concrete implementation of StateEngine . |
protected <T extends StateEngine<?>> |
start(java.lang.Class<T> initialStateClass)
Starts the concrete implementation of
StateMachine . |
void |
stop()
Stops this
StateMachine . |
public final <T extends StateEngine<?>> T getStateEngine()
StateEngine
that is an instance of concrete implementation of
a StateEngine
code generated by Fuusio FSM Annotation Processor.StateEngine
.public final <T extends StateEngine<?>> T getCurrentState()
StateEngine
that is an instance of code generated class.StateEngine
. May not return null
for started
state machine.public boolean isStarted()
StateMachine
has been started.boolean
value.public boolean isCurrentSuperState(java.lang.Class<? extends StateEngine<?>> superStateClass)
superStateClass
- A Class
specifying the super state.boolean value
.public boolean isCurrentState(java.lang.Class<? extends StateEngine<?>> stateClass)
stateClass
- A Class
specifying the state.boolean value
.protected void onStateEngineCreated(StateEngine<?> stateEngine)
protected StateEngine<?> createStateEngine()
StateEngine
. This method can be overridden in concrete implementations,
but if not overridden, the default instantiation method will be used.StateEngine
. The default implementation returns null
.protected final <T extends StateEngine<?>> T start(java.lang.Class<T> initialStateClass)
StateMachine
.initialStateClass
- A Class
that implements an initial state for the state machine.StateEngine
.public abstract void start()
StateMachine
by starting the concrete implementation of StateEngine
.
The concrete implementation has to override this method and invoke
start(Class)
method.public final void stop()
StateMachine
. A stopped StateMachine
can be restarted after resetting
it.public final void reset()
StateMachine
. A StateMachine
can be restarted after resetting.public void onDispose(StateEngine<?> stateEngine)
StateEngineObserver
StateEngine
is being disposed.onDispose
in interface StateEngineObserver
stateEngine
- The observed StateEngine
.public void onError(StateEngine<?> stateEngine, StateEngine.Error error, java.lang.String message)
StateEngineObserver
StateEngine
.onError
in interface StateEngineObserver
stateEngine
- The observed StateEngine
.error
- An Error
.message
- A error message.public void onReset(StateEngine<?> stateEngine)
StateEngineObserver
StateEngine
is resetted.onReset
in interface StateEngineObserver
stateEngine
- The observed StateEngine
.public void onStart(StateEngine<?> stateEngine)
StateEngineObserver
StateEngine
is started.onStart
in interface StateEngineObserver
stateEngine
- The observed StateEngine
.public void onStop(StateEngine<?> stateEngine)
StateEngineObserver
StateEngine
is stopped.onStop
in interface StateEngineObserver
stateEngine
- The observed StateEngine
.