首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在spring-statemachine项目中使用2种不同的Papyrus UMLstatemachines

在spring-statemachine项目中使用2种不同的Papyrus UMLstatemachines
EN

Stack Overflow用户
提问于 2017-09-14 16:37:47
回答 1查看 1.2K关注 0票数 1

链接到 github 进行测试的项目

Payprus文件是 这里

我正试着用纸莎草制作一台国家机器.状态机应该将两个单一状态机组合成一个状态机,如您在第一个映像中所看到的:

状态机1在第二图片中定义,状态机2在第三图片中定义。

我正在使用我的spring应用程序的UML (向下滚动以获得代码)

我尝试用一个真正简单的单状态机(所以只有类似于状态机1的东西,但有初始和最后一点),而且它工作得很好,System.out.println()正在编写整个代码。

但是对于这2台状态机,机器从top_inital点的顶部开始,然后转到top_s1。这是意料之中的,也是可行的

比我想象的要通过topExitPoint1到sm1EntryPoint ->,进入StateMachine1 ->,而不是StateMachine2 ->,回到顶端等等。

但不幸的是,我的机器中唯一使用的状态是顶层->中的状态,top_s1状态。控制台日志只显示以下内容:

代码语言:javascript
复制
2017-09-14 17:41:42.002  INFO 25414 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-09-14 17:41:42.008  INFO 25414 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
State change to top_s1
2017-09-14 17:41:42.070  INFO 25414 --- [           main] o.s.s.support.LifecycleObjectSupport     : started org.springframework.statemachine.support.DefaultStateMachineExecutor@4afd21c6
2017-09-14 17:41:42.070  INFO 25414 --- [           main] o.s.s.support.LifecycleObjectSupport     : started top_s1 topFinalState top_r2_s1 top_s2 top_FinalState1 sm2_s1 sm2_s2 sm1_s2 sm1_s1  / top_s1 / uuid=e3a76fb9-5d3f-46b2-9c01-17d23eabedea / id=null
2017-09-14 17:41:42.071  INFO 25414 --- [           main] d.j.u.UmlSpringStateMachineApplication   : Started UmlSpringStateMachineApplication in 2.584 seconds (JVM running for 2.85)
2017-09-14 17:41:42.073  INFO 25414 --- [       Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@1e4a7dd4: startup date [Thu Sep 14 17:41:39 CEST 2017]; root of context hierarchy
2017-09-14 17:41:42.076  INFO 25414 --- [       Thread-3] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 0
2017-09-14 17:41:42.077  INFO 25414 --- [       Thread-3] o.s.s.support.LifecycleObjectSupport     : stopped org.springframework.statemachine.support.DefaultStateMachineExecutor@4afd21c6
2017-09-14 17:41:42.078  INFO 25414 --- [       Thread-3] o.s.s.support.LifecycleObjectSupport     : stopped top_s1 topFinalState top_r2_s1 top_s2 top_FinalState1 sm2_s1 sm2_s2 sm1_s2 sm1_s1  /  / uuid=e3a76fb9-5d3f-46b2-9c01-17d23eabedea / id=null
2017-09-14 17:41:42.078  INFO 25414 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2017-09-14 17:41:42.079  INFO 25414 --- [       Thread-3] o.s.s.support.LifecycleObjectSupport     : destroy called

我在Papyrus尝试了很多东西来改变这种行为,但是没有什么改变。如果有人能看一看,也许知道怎么帮忙的话,那就好了。

以下是Java代码:我的UmlSpringStateMachineApplication

代码语言:javascript
复制
package de.joergi.umlspringstatemachine;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.statemachine.StateMachine;

@SpringBootApplication
public class UmlSpringStateMachineApplication implements CommandLineRunner {

    @Autowired
    private StateMachine<String, String> stateMachine;

    public static void main(String[] args) {
        SpringApplication.run(UmlSpringStateMachineApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        stateMachine.start();
    }   
}

我的StateMachineConfig看起来是这样的:

代码语言:javascript
复制
package de.joergi.umlspringstatemachine;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
import org.springframework.statemachine.config.builders.StateMachineModelConfigurer;
import org.springframework.statemachine.config.model.StateMachineModelFactory;
import org.springframework.statemachine.listener.StateMachineListener;
import org.springframework.statemachine.listener.StateMachineListenerAdapter;
import org.springframework.statemachine.state.State;
import org.springframework.statemachine.uml.UmlStateMachineModelFactory;

@Configuration
@EnableStateMachine
public class StateMachineConfig extends StateMachineConfigurerAdapter<String, String> {

    @Override
    public void configure(StateMachineConfigurationConfigurer<String, String> config) throws Exception {
        config.withConfiguration().autoStartup(false).listener(listener());
    }

    @Override
    public void configure(StateMachineModelConfigurer<String, String> model) throws Exception {
        model.
            withModel().factory(modelFactoryStateMachine());
    }

    @Bean
    public StateMachineModelFactory<String, String> modelFactoryStateMachine() {
        return new UmlStateMachineModelFactory("classpath:papyrus/new_test.uml");
    }

    @Bean
    public StateMachineListener<String, String> listener() {
        return new StateMachineListenerAdapter<String, String>() {
            @Override
            public void stateChanged(State<String, String> from, State<String, String> to) {
                System.out.println("State change to " + to.getId());
            }
        };
    }
}

如果要查看模型资源管理器的外观:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-27 16:47:46

因此,我修复了这个问题,在一个项目中构建了两个独立的状态机,并将它们连接在一起( https://github.com/joergi/uml-spring-state-machine/ )--请参阅对master的新推送。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46224339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档