S
- type can be of any class which is an immediate subclass
of FiniteStateMachine.State
E
- type can be of any class which is an immediate subclass
of FiniteStateMachine.Event
A
- type of args for action callbackspublic class FiniteStateMachine<S extends FiniteStateMachine.State,E extends FiniteStateMachine.Event,A>
extends java.lang.Object
FiniteStateMachine.EventTable
that trigger these state changes.Modifier and Type | Class and Description |
---|---|
static interface |
FiniteStateMachine.ActionCallback<A>
A callback defining an action for an event.
|
static interface |
FiniteStateMachine.EntryActionCallback<E,A>
A callback defining an action upon entry to state.
|
static interface |
FiniteStateMachine.Event
A marker interface that defines a class that implements it
to be an event that can cause a state change.
|
static class |
FiniteStateMachine.EventTable<S extends FiniteStateMachine.State,E extends FiniteStateMachine.Event,A>
An Event table encapsulates complete information about event such as
previous state, next state and action callback etc.
|
static interface |
FiniteStateMachine.ExitActionCallback<A>
A callback defining an action upon exit from a state.
|
static interface |
FiniteStateMachine.FetchTimeout
An interface defining timeout for an event.
|
static interface |
FiniteStateMachine.State
A marker interface that defines a class that implements it
to be a state of an object.
|
static class |
FiniteStateMachine.StateTable<S extends FiniteStateMachine.State,E extends FiniteStateMachine.Event,A>
State table encapsulates complete information about the state such as timeout,
entry and exit callback actions etc.
|
static interface |
FiniteStateMachine.TimerCallback<A>
A callback defining an action upon timeout reached.
|
Constructor and Description |
---|
FiniteStateMachine(S initialState,
FiniteStateMachine.TimerCallback<A> timerCallback,
java.util.List<FiniteStateMachine.EventTable<S,E,A>> eventTables,
java.util.List<FiniteStateMachine.StateTable<S,E,A>> stateTables)
Constructor for current class.
|
Modifier and Type | Method and Description |
---|---|
S |
getCurrentState() |
void |
handleEvent(E event,
A args)
This function handles an event using information encapsulated in event table to change states
of a finite state machine as defined.
|
void |
unsafeSetState(S state)
To forcefully set the state of this machine.
|
public FiniteStateMachine(S initialState, FiniteStateMachine.TimerCallback<A> timerCallback, java.util.List<FiniteStateMachine.EventTable<S,E,A>> eventTables, java.util.List<FiniteStateMachine.StateTable<S,E,A>> stateTables)
initialState
- primary state from which event triggers initiallytimerCallback
- essential in triggering timer and set timeout conditions for
the finite state machineeventTables
- List of all FiniteStateMachine.EventTable
possible for the machinestateTables
- List of all FiniteStateMachine.StateTable
possible for the machinepublic void handleEvent(E event, A args)
event
- Event under interest to be handledargs
- args to trigger action callback for eventpublic void unsafeSetState(S state)
state
- desired statepublic S getCurrentState()