2

I would like to get something like an exception or any hint, when I send an event which is not possible in the current state of the machine.

Instead of an exception, nothing happens. The only thing that I noticed is:

stateMachine.sendEvent(myMessage)

returns false. But the following method does not return true:

stateMachine.hasStateMachineError()

so I guess there is no exception...!?

Does anybody know how I could get an error like "This event can not be applied in the current state of the state machine"?

Thanks a lot in advance!

sergej
  • 193
  • 1
  • 11

1 Answers1

2

If you have an unknown event, the state machine will not fail with error, it will ignore it. The only way to have more information regarding the invalid event is to add a state machine listener:

public class InvalidEventListener extends StateMachineListenerAdapter {

    @Override
    public void eventNotAccepted(Message event) {
        // it is useless to throw an exception here, it is handled at a higher level
        // here you can add custom logic, but limited.
        super.eventNotAccepted(event);
    }
}

You must add this listener to your state machine:

stateMachine.addStateListener(new InvalidEventListener());
Adina Rolea
  • 2,031
  • 1
  • 7
  • 16