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 theFsmContext.
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
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 TypeMethodDescriptionstatic <StateT,ContextT>
FsmHook<StateT, ContextT> noop()voidrun(FsmContext<ContextT> context, FsmTransition<StateT> transition) Runs the hook.
-
Method Details
-
run
Runs the hook.- Parameters:
context- The context for the current execution cycle.transition- Callback to request a transition to a different state.
-
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 theFsmContext.- Returns:
- A hook that does nothing, for use when only one of the before/after hooks is needed.
-