How can I be notified about State Machine Completion?

725 views Asked by At

I have a State Configuration with a pseudo-endstate configured. I expected that the state machine would be completed when reaching that state, but I'm missing a way of getting notified about it.

I've registered a StateMachineListener, but it doesn't get notified about completion of a state machine.

1

There are 1 answers

3
Christian von Wendt-Jensen On

Ok - I finally found out.

For a State Machine to stop, a state with pseudostate END must be defined. When this state is reached, a StateMachineListener will be notified that the machine is stopped.

Beneath is the outline of the spring configuration, I use. Some of the details have been left out for brievity.

@Override
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
    states
            .withStates()
            .initial("WAITING")
            .state("FAILED", fail(), null)
            .state("SUCCESS", success(), null)
            .end("COMPLETED")

    ;
}

In the transition configuration, you do like this:

@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
    transitions
            .withExternal().source("FAILED").target("COMPLETED")
            .and().withExternal().source("SUCCESS").target("COMPLETED")
    ;
}