Class StrictMachine<S,​E>

  • All Implemented Interfaces:
    Fsm<S,​E>

    public class StrictMachine<S,​E>
    extends java.lang.Object
    implements Fsm<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
      void fireEvent​(E event)
      Fire an event for the FSM to evaluate.
      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.
      S fireEventBlocking​(E event)
      Fire an event for the FSM to evaluate and block waiting until the state transitioned to as a result of evaluating event is available.
      <T> T getFromContext​(java.util.function.Function<FsmContext<S,​E>,​T> get)
      Provides safe access to the FsmContext in order to retrieve a value from it.
      S getState()
      Get the current state of the FSM.
      void withContext​(java.util.function.Consumer<FsmContext<S,​E>> contextConsumer)
      Provides safe access to the FsmContext.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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: Fsm
        Get the current state of the FSM.
        Specified by:
        getState in interface Fsm<S,​E>
        Returns:
        the current state of the FSM.
      • fireEvent

        public void fireEvent​(E event)
        Description copied from interface: Fsm
        Fire 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:
        fireEvent in interface Fsm<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: Fsm
        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.
        Specified by:
        fireEvent in interface Fsm<S,​E>
        Parameters:
        event - the event to evaluate.
        stateConsumer - the callback that will receive the state transitioned to via evaluation of event.
      • fireEventBlocking

        public S fireEventBlocking​(E event)
                            throws java.lang.InterruptedException
        Description copied from interface: Fsm
        Fire an event for the FSM to evaluate and block waiting until the state transitioned to as a result of evaluating event is available.
        Specified by:
        fireEventBlocking in interface Fsm<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: Fsm
        Provides safe access to the FsmContext in order to retrieve a value from it.
        Specified by:
        getFromContext in interface Fsm<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: Fsm
        Provides safe access to the FsmContext.
        Specified by:
        withContext in interface Fsm<S,​E>
        Parameters:
        contextConsumer - the callback that will receive the FsmContext.