public interface StateMachine
A state machine consists of a set of states and transition rules between
those states. Transitions are triggered by events. Events can be issued
event(String) A transition always has a target state (i.e.
the state the state machine should switch to during the transition) and a set
of side effects. These can be further events to be triggered or commands that
should be issued. Events (both external and internal) are collected in an
event queue and processed asynchronously by the state machine. Commands
triggered by transitions are collected in a command queue that is accessible
from outside the state machine. This allows user code to collect these
commands and to process them. A cluster of state machines is handled
similarly to a single state machine but with multiple active states at once
(i.e. one active state per state machine) and all events are applied to all
internal state machines. Commands issued by any of the internal state
machines are all collected in a common command queue.
State machines must be started to be able to process events. Use
stop() to start or stop the state machine. A
stopped state machine can be restarted at any time. Restarting a state
machine simply resumes operation. A state machine can also be reset to the
initial state by calling
reset(). A reset will clear the event queue
and revert and reinitialise the state machine to its initial state. The
command queue remains unaffected as it is not considered as integral a part
to the state machine as the event queue is.
State machines have built in logging support using
java.util.logging.Logger. All logging is done using the logger
ch.awae.utils.statemachine.StateMachine. For the logging the
following levels are used:
SEVERE- a machine core failed to instantiate
WARNING- a machine core that allows terminal states has a terminal state (which is discouraged)
CONFIG- machine configuration summary on state machine creation
FINE- major events in the lifecycle of the state machine (e.g. worker thread started/stopped, a state change in a core)
FINER/FINEST- detailed data for every action taken on a state machine or core
|Modifier and Type||Interface and Description|
root interface for saved state of state machines.
|Modifier and Type||Method and Description|
Adds a new event to the internal event queue
Creates a graphviz (dot) compatible graph from the state machine.
Provides the command queue associated with the state machine.
Creates a SavedState instance representing the current state of the state machine.
provides the UUID of the state machine
Loads the state represented by a given SavedState instance and sets the state machine to that state.
Resets the state machine to its initial state and clears the event queue.
Starts processing of the state machine event queue.
Stops processing of the state machine event queue.
void event(java.lang.String event)
event- the event to issue. may not be
BlockingQueue.take()on the queue to access the commands.
java.lang.IllegalStateException- the state machine is already running
java.lang.IllegalStateException- the state machine is not running
event(String)while the reset is in progress.
void loadState(StateMachine.SavedState state, boolean clear)
state- the saved state
trueif the event queue should be cleared.
stateis not compatible with this state machine instance.
Copyright © 2017. All Rights Reserved.