Interface FsmHook<StateT,ContextT>

Type Parameters:
StateT - The enum type representing the states of the machine this hook belongs to.
ContextT - The type of the payload carried by the FsmContext.
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface FsmHook<StateT,ContextT>
A hook that a FiniteStateMachine runs immediately before or immediately after the current state's FsmState.execute(FsmContext, FsmTransition) on every cycle, regardless of which state is active. Useful for machine-wide concerns like preemptive fault handling (as a "before" hook, since it can transition out of any state before that state gets a chance to run) or publishing shared telemetry/outputs (as an "after" hook).
  • Method Summary

    Modifier and Type
    Method
    Description
    static <StateT,ContextT>
    FsmHook<StateT,ContextT>
     
    void
    run(FsmContext<ContextT> context, FsmTransition<StateT> transition)
    Runs the hook.
  • Method Details

    • run

      void run(FsmContext<ContextT> context, FsmTransition<StateT> transition)
      Runs the hook.
      Parameters:
      context - The context for the current execution cycle.
      transition - Callback to request a transition to a different state.
    • noop

      static <StateT,ContextT> FsmHook<StateT,ContextT> noop()
      Type Parameters:
      StateT - The enum type representing the states of the machine this hook belongs to.
      ContextT - The type of the payload carried by the FsmContext.
      Returns:
      A hook that does nothing, for use when only one of the before/after hooks is needed.