【问题标题】:Fork and Join in spring state machine (Parallel execution)Spring 状态机中的 Fork 和 Join(并行执行)
【发布时间】:2021-06-14 12:39:04
【问题描述】:

我有一个如下的 UML 图:

如何在状态机中根据事件配置状态和转换从 SI 到 END....

 public class Config14
            extends EnumStateMachineConfigurerAdapter<States, Events> {
    
        @Override
        public void configure(StateMachineStateConfigurer<States, Events> states)
                throws Exception {
                                  .....

}



    @Override
            public void configure(StateMachineTransitionConfigurer<States, Events> transitions)
                    throws Exception {
                                   .....
    }
}

【问题讨论】:

  • 你能弄明白吗?

标签: spring state-machine spring-statemachine


【解决方案1】:

虽然回答晚了,但无论如何我都会提出我的发现。 要实现显示状态转换,您需要有一个 fork/join 伪状态。正如在here (https://www.uml-diagrams.org/state-machine-diagrams.html) 中提到的那样,伪状态通常用于将多个转换连接到更复杂的状态转换路径。它们各自的定义如下:

分叉伪状态顶点用于将传入的转换拆分为两个或多个终止于正交目标顶点(即复合状态不同区域中的顶点)的转换。

Join 伪状态合并了源自不同正交区域中源顶点的多个转换。

应该注意,从分叉顶点传出的段不能有守卫或触发器(同样适用于连接)。

您的配置应该或多或少类似于以下内容:

@Override
public void configure(StateMachineStateConfigurer<String, String> states) throws Exception {
    states
        .withStates()
        .initial("SI")
        .fork("S1")
        .join("JOIN")
        .state("S11")
        .state("S12")
        .state("S2")
        .end("END")
        .and()
        .withStates()
            .parent("S1")
            .initial("S11")
            .end("S11") //not very sure about this
        .and()
        .withStates()
            .parent("S1")
            .initial("S12")
            .end("S12");
}

@Override
public void configure(StateMachineTransitionConfigurer<String, String> transitions) throws Exception {
    transitions.withExternal()
                .source("SI").target("S1").event("YOUR_EVENT")
             .and()
             .withExternal()
                .source("S2").target("END").event("YOUR_EVENT")
            .and()
            .withFork()
                .source("S1")
                .target("S11")
                .target("S12")
            .and()
            .withJoin()
                .source("S11")
                .source("S12")
                .target("JOIN");
}

如需样本,请查看https://github.com/amenski/statemachine

【讨论】:

    猜你喜欢
    • 2019-08-12
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    相关资源
    最近更新 更多