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 Summary
Modifier and TypeMethodDescriptionstatic StateMachineListenerlogging()Creates a simple logging listener.default voidonCompleted(StateMachine stateMachine) Called when the state machine reaches a terminal state.default voidonNoTransition(StateMachine stateMachine, State state, Event event) Called when an event doesn't match any transition.default voidonStateEntered(StateMachine stateMachine, State state, Event event) Called when a state is entered.default voidonStateExited(StateMachine stateMachine, State state, Event event) Called when a state is exited.default voidonTransition(StateMachine stateMachine, State from, State to, Event event) Called when a transition occurs.
-
Method Details
-
onStateEntered
Called when a state is entered.- Parameters:
stateMachine- the state machinestate- the entered stateevent- the triggering event (null for initial or automatic)
-
onStateExited
Called when a state is exited.- Parameters:
stateMachine- the state machinestate- the exited stateevent- the triggering event
-
onTransition
Called when a transition occurs.- Parameters:
stateMachine- the state machinefrom- the source stateto- the target stateevent- the triggering event (null for automatic)
-
onNoTransition
Called when an event doesn't match any transition.- Parameters:
stateMachine- the state machinestate- the current stateevent- the unhandled event
-
onCompleted
Called when the state machine reaches a terminal state.- Parameters:
stateMachine- the state machine
-
logging
Creates a simple logging listener.- Returns:
- logging listener
-