我如何知道一名警卫是否拒绝过境

时间:2016-12-23 17:22:31

标签: spring-statemachine

我在reference documentation:

中配置了转场
public void configure(StateMachineTransitionConfigurer<States, Events> transitions)
        throws Exception {
    transitions
        .withExternal()
            .source(States.SI).target(States.S1)
            .event(Events.E1)
            .guard(guard1())
            .and()
        .withExternal()
            .source(States.S1).target(States.S2)
            .event(Events.E1)
            .guard(guard2())
            .and()
        .withExternal()
            .source(States.S2).target(States.S3)
            .event(Events.E2)
            .guardExpression("extendedState.variables.get('myvar')");
}

如果状态机处于状态States.S1并且我发送了事件Events.E1,我怎么知道guard2()是否拒绝过渡?

我正在检查状态机的状态:如果它仍然在States.S1,那么我知道事件被拒绝了。这是处理警卫拒绝的“正确”方式吗?

编辑:

在阅读Janne的评论之后,我意识到我正在尝试做的事情可能是错误地使用了警卫。似乎只应该使用防护装置来确定机器应该转换到哪种状态,而不是应该输入状态。如果是后者,即转换完全被拒绝,则状态机将处于无状态。我应该被代码允许我做的事情以及编码工作流程时以状态机为中心的思维方式所吸引。这就是我在假期前赶来的原因!

0 个答案:

没有答案