Package com.digitalpetri.strictmachine
Interface Fsm<S,E>
-
- All Known Implementing Classes:
StrictMachine
public interface Fsm<S,E>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidfireEvent(E event)Fire an event for the FSM to evaluate.voidfireEvent(E event, java.util.function.Consumer<S> stateConsumer)Fire an event for the FSM to evaluate, providing a callback that will be invoked when the event is evaluated.SfireEventBlocking(E event)Fire an event for the FSM to evaluate and block waiting until the state transitioned to as a result of evaluatingeventis available.<T> TgetFromContext(java.util.function.Function<FsmContext<S,E>,T> get)Provides safe access to theFsmContextin order to retrieve a value from it.SgetState()Get the current state of the FSM.voidwithContext(java.util.function.Consumer<FsmContext<S,E>> contextConsumer)Provides safe access to theFsmContext.
-
-
-
Method Detail
-
getState
S getState()
Get the current state of the FSM.- Returns:
- the current state of the FSM.
-
fireEvent
void fireEvent(E event)
Fire an event for the FSM to evaluate.The subsequent state transition may occur asynchronously. There is no guarantee that a subsequent call to
getState()reflects a state arrived at via evaluation of this event.- Parameters:
event- the event to evaluate.- See Also:
fireEvent(Object, Consumer)
-
fireEvent
void fireEvent(E event, java.util.function.Consumer<S> stateConsumer)
Fire an event for the FSM to evaluate, providing a callback that will be invoked when the event is evaluated. This callback may occur asynchronously.- Parameters:
event- the event to evaluate.stateConsumer- the callback that will receive the state transitioned to via evaluation ofevent.
-
fireEventBlocking
S fireEventBlocking(E event) throws java.lang.InterruptedException
Fire an event for the FSM to evaluate and block waiting until the state transitioned to as a result of evaluatingeventis available.- Parameters:
event- the event to evaluate.- Returns:
- the state transitioned to as a result of evaluating
event. - Throws:
java.lang.InterruptedException- if interrupted while blocking.
-
getFromContext
<T> T getFromContext(java.util.function.Function<FsmContext<S,E>,T> get)
Provides safe access to theFsmContextin order to retrieve a value from it.- Type Parameters:
T- the type of the value being retrieved.- Parameters:
get- the Function provided access to the context.- Returns:
- a value from
context.
-
withContext
void withContext(java.util.function.Consumer<FsmContext<S,E>> contextConsumer)
Provides safe access to theFsmContext.- Parameters:
contextConsumer- the callback that will receive theFsmContext.
-
-