1

我有一个配置了伪终端状态的状态配置。我预计状态机会在达到该状态时完成,但我错过了一种获得通知的方式。

我已经注册了一个 StateMachineListener,但它没有收到关于状态机完成的通知。

4

1 回答 1

0

好的 - 我终于发现了。

要使状态机停止,必须定义具有伪状态 END 的状态。当达到此状态时,将通知 StateMachineListener 机器已停止。

下面是我使用的弹簧配置的轮廓。为了简洁起见,一些细节被省略了。

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

    ;
}

在过渡配置中,您可以这样做:

@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
    transitions
            .withExternal().source("FAILED").target("COMPLETED")
            .and().withExternal().source("SUCCESS").target("COMPLETED")
    ;
}
于 2017-01-05T08:08:32.610 回答