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>>AFiniteStateMachineimplements 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 voidaddListener(FiniteStateMachineListener<S> listener)Add aFiniteStateMachineListenerto theFiniteStateMachine.StringgetName()Obtains the name of theFiniteStateMachine.SgetState()Obtains the current state of theFiniteStateMachine.longgetTransitionCount()Obtains the number of transitions that have occurred in theFiniteStateMachine.voidprocess(Event<S> event)Request theFiniteStateMachineto process the specifiedEvent.voidremoveListener(FiniteStateMachineListener<S> listener)Remove aFiniteStateMachineListenerfrom theFiniteStateMachine.booleanstart()Start theFiniteStateMachineand enter the initial state.booleanstop()Stops theFiniteStateMachineas 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 theFiniteStateMachineto process the specifiedEvent.Note: There's no guarantee that the
Eventwill be processed because:- the
Transitionto be performed for theEventis invalid as theFiniteStateMachineis not in the required starting state. - the
FiniteStateMachinemay have been stopped.
- Parameters:
event- theEventfor theFiniteStateMachineto 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
Transitionmay 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
Transitionmay be executing asynchronously in the background on another thread.- Returns:
- the number of transitions that have occurred in the
FiniteStateMachine
-
start
boolean start()
Start theFiniteStateMachineand enter the initial state.Note: Once stopped a
FiniteStateMachinecan't be restarted; instead a newFiniteStateMachineshould be created.- Returns:
trueif the start was successful or the FiniteStateMachine is already stated,falseif it has been stopped- Throws:
IllegalStateException- if the FiniteStateMachine was already stopped
-
stop
boolean stop()
Stops theFiniteStateMachineas soon as possible.Note: Once stopped a
FiniteStateMachinecan't be restarted; instead a newFiniteStateMachineshould be created.- Returns:
trueif the stop was successful,falseif it's already stopped- Throws:
IllegalStateException- if the FiniteStateMachine was never started
-
addListener
void addListener(FiniteStateMachineListener<S> listener)
Add aFiniteStateMachineListenerto theFiniteStateMachine.Note that unique instances of FiniteStateMachineListener are identified via their
equalsandhashCodeimplementations.- Parameters:
listener- the listener to be added
-
removeListener
void removeListener(FiniteStateMachineListener<S> listener)
Remove aFiniteStateMachineListenerfrom theFiniteStateMachine.Note that unique instances of FiniteStateMachineListener are identified via their
equalsandhashCodeimplementations.- Parameters:
listener- the listener to be removed
-
-