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
      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.
    • 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 of event.
      • 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 evaluating event is 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 the FsmContext in 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 the FsmContext.
        Parameters:
        contextConsumer - the callback that will receive the FsmContext.