3

I'm new to Spring State Machine. I have used a StateMachineListener for my state machine. How can i access to StateContext in eventNotAccepted method.

@Override
        public void eventNotAccepted(Message<String> event) {

        }
Amir
  • 652
  • 9
  • 19

1 Answers1

10

You need to use StateMachineListener.stateContext(StateContext<S, E>) and listen all StateContext changes. From there check StateContext.getStage() when it matches Stage.EVENT_NOT_ACCEPTED.

Originally when that listener interface were added we didn't have context and later when people wanted access to it we didn't want to break backward compatibility, thus that new method were added.

Janne Valkealahti
  • 2,552
  • 1
  • 14
  • 12
  • And I'd recommend using `StateMachineListenerAdapter` as it guards you against compile errors if we need to modify `StateMachineListener` again. – Janne Valkealahti Nov 22 '16 at 10:58