Package com.digitalpetri.strictmachine
Class StrictMachine<S,E>
- java.lang.Object
-
- com.digitalpetri.strictmachine.StrictMachine<S,E>
-
-
Constructor Summary
Constructors Constructor Description StrictMachine(org.slf4j.Logger logger, java.util.concurrent.Executor executor, ActionProxy<S,E> actionProxy, S initialState, java.util.List<Transition<S,E>> transitions, java.util.List<TransitionAction<S,E>> transitionActions)StrictMachine(org.slf4j.Logger logger, java.util.Map<java.lang.String,java.lang.String> mdc, java.util.concurrent.Executor executor, ActionProxy<S,E> actionProxy, S initialState, java.util.List<Transition<S,E>> transitions, java.util.List<TransitionAction<S,E>> transitionActions)
-
Method Summary
All Methods Instance Methods Concrete 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.
-
-
-
Constructor Detail
-
StrictMachine
public StrictMachine(org.slf4j.Logger logger, java.util.concurrent.Executor executor, ActionProxy<S,E> actionProxy, S initialState, java.util.List<Transition<S,E>> transitions, java.util.List<TransitionAction<S,E>> transitionActions)
-
StrictMachine
public StrictMachine(org.slf4j.Logger logger, java.util.Map<java.lang.String,java.lang.String> mdc, java.util.concurrent.Executor executor, ActionProxy<S,E> actionProxy, S initialState, java.util.List<Transition<S,E>> transitions, java.util.List<TransitionAction<S,E>> transitionActions)
-
-
Method Detail
-
getState
public S getState()
Description copied from interface:FsmGet the current state of the FSM.
-
fireEvent
public void fireEvent(E event)
Description copied from interface:FsmFire an event for the FSM to evaluate.The subsequent state transition may occur asynchronously. There is no guarantee that a subsequent call to
Fsm.getState()reflects a state arrived at via evaluation of this event.- Specified by:
fireEventin interfaceFsm<S,E>- Parameters:
event- the event to evaluate.- See Also:
Fsm.fireEvent(Object, Consumer)
-
fireEvent
public void fireEvent(E event, java.util.function.Consumer<S> stateConsumer)
Description copied from interface:FsmFire an event for the FSM to evaluate, providing a callback that will be invoked when the event is evaluated. This callback may occur asynchronously.
-
fireEventBlocking
public S fireEventBlocking(E event) throws java.lang.InterruptedException
Description copied from interface:FsmFire an event for the FSM to evaluate and block waiting until the state transitioned to as a result of evaluatingeventis available.- Specified by:
fireEventBlockingin interfaceFsm<S,E>- 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
public <T> T getFromContext(java.util.function.Function<FsmContext<S,E>,T> get)
Description copied from interface:FsmProvides safe access to theFsmContextin order to retrieve a value from it.- Specified by:
getFromContextin interfaceFsm<S,E>- 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
public void withContext(java.util.function.Consumer<FsmContext<S,E>> contextConsumer)
Description copied from interface:FsmProvides safe access to theFsmContext.- Specified by:
withContextin interfaceFsm<S,E>- Parameters:
contextConsumer- the callback that will receive theFsmContext.
-
-