Package com.tnsai.fsm

Interface StateMachineListener


public interface StateMachineListener
Listener interface for state machine events.

Usage


 StateMachineListener listener = new StateMachineListener() {
     @Override
     public void onStateEntered(StateMachine sm, State state, Event event) {
         log.info("Entered state: {}", state.getName());
     }

     @Override
     public void onTransition(StateMachine sm, State from, State to, Event event) {
         log.info("Transition: {} -> {} via {}",
             from.getName(), to.getName(),
             event != null ? event.getName() : "auto");
     }
 };

 stateMachine.addListener(listener);
 
  • Method Details

    • onStateEntered

      default void onStateEntered(StateMachine stateMachine, State state, Event event)
      Called when a state is entered.
      Parameters:
      stateMachine - the state machine
      state - the entered state
      event - the triggering event (null for initial or automatic)
    • onStateExited

      default void onStateExited(StateMachine stateMachine, State state, Event event)
      Called when a state is exited.
      Parameters:
      stateMachine - the state machine
      state - the exited state
      event - the triggering event
    • onTransition

      default void onTransition(StateMachine stateMachine, State from, State to, Event event)
      Called when a transition occurs.
      Parameters:
      stateMachine - the state machine
      from - the source state
      to - the target state
      event - the triggering event (null for automatic)
    • onNoTransition

      default void onNoTransition(StateMachine stateMachine, State state, Event event)
      Called when an event doesn't match any transition.
      Parameters:
      stateMachine - the state machine
      state - the current state
      event - the unhandled event
    • onCompleted

      default void onCompleted(StateMachine stateMachine)
      Called when the state machine reaches a terminal state.
      Parameters:
      stateMachine - the state machine
    • logging

      static StateMachineListener logging()
      Creates a simple logging listener.
      Returns:
      logging listener