Interface FiniteStateMachine<S extends Enum<S>>
-
- Type Parameters:
S
- the type of state of the FiniteStateMachine
- All Known Implementing Classes:
NonBlockingFiniteStateMachine
public interface FiniteStateMachine<S extends Enum<S>>
AFiniteStateMachine
implements a general purpose finite-state-machine.- Since:
- Coherence 12.2.1
- Author:
- Brian Oliver
- See Also:
Model
,Transition
,TransitionAction
,StateEntryAction
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addListener(FiniteStateMachineListener<S> listener)
Add aFiniteStateMachineListener
to theFiniteStateMachine
.String
getName()
Obtains the name of theFiniteStateMachine
.S
getState()
Obtains the current state of theFiniteStateMachine
.long
getTransitionCount()
Obtains the number of transitions that have occurred in theFiniteStateMachine
.void
process(Event<S> event)
Request theFiniteStateMachine
to process the specifiedEvent
.void
removeListener(FiniteStateMachineListener<S> listener)
Remove aFiniteStateMachineListener
from theFiniteStateMachine
.boolean
start()
Start theFiniteStateMachine
and enter the initial state.boolean
stop()
Stops theFiniteStateMachine
as soon as possible.
-
-
-
Method Detail
-
getName
String getName()
Obtains the name of theFiniteStateMachine
. This is primarily used for display/logging/monitoring purposes.- Returns:
- the name of the
FiniteStateMachine
-
process
void process(Event<S> event)
Request theFiniteStateMachine
to process the specifiedEvent
.Note: There's no guarantee that the
Event
will be processed because:- the
Transition
to be performed for theEvent
is invalid as theFiniteStateMachine
is not in the required starting state. - the
FiniteStateMachine
may have been stopped.
- Parameters:
event
- theEvent
for theFiniteStateMachine
to process
- the
-
getState
S getState()
Obtains the current state of theFiniteStateMachine
.Note: After returning the current state there's no guarantee that the state will be the same because a
Transition
may be executing asynchronously in the background on another thread.- Returns:
- the current state of the
FiniteStateMachine
-
getTransitionCount
long getTransitionCount()
Obtains the number of transitions that have occurred in theFiniteStateMachine
.Note: After returning the count there's no guarantee that the count will be the same on the next request because a
Transition
may be executing asynchronously in the background on another thread.- Returns:
- the number of transitions that have occurred in the
FiniteStateMachine
-
start
boolean start()
Start theFiniteStateMachine
and enter the initial state.Note: Once stopped a
FiniteStateMachine
can't be restarted; instead a newFiniteStateMachine
should be created.- Returns:
true
if the start was successful or the FiniteStateMachine is already stated,false
if it has been stopped- Throws:
IllegalStateException
- if the FiniteStateMachine was already stopped
-
stop
boolean stop()
Stops theFiniteStateMachine
as soon as possible.Note: Once stopped a
FiniteStateMachine
can't be restarted; instead a newFiniteStateMachine
should be created.- Returns:
true
if the stop was successful,false
if it's already stopped- Throws:
IllegalStateException
- if the FiniteStateMachine was never started
-
addListener
void addListener(FiniteStateMachineListener<S> listener)
Add aFiniteStateMachineListener
to theFiniteStateMachine
.Note that unique instances of FiniteStateMachineListener are identified via their
equals
andhashCode
implementations.- Parameters:
listener
- the listener to be added
-
removeListener
void removeListener(FiniteStateMachineListener<S> listener)
Remove aFiniteStateMachineListener
from theFiniteStateMachine
.Note that unique instances of FiniteStateMachineListener are identified via their
equals
andhashCode
implementations.- Parameters:
listener
- the listener to be removed
-
-