在 spring 状态机项目中使用 2 个不同的 Papyrus UML 状态机
Using 2 different Papyrus UMLstatemachines with the spring-statemachine project
Link 到 github 上的项目进行测试
Payprus 文件是 here
我正在尝试用 Papyrus 制作一个状态机。状态机应该将两个单一的状态机合并为一个,如您在第一张图片中所见:
状态机1定义在第2张图,状态机2定义在第3张图
我在 spring 应用程序中使用 UML(向下滚动代码)
我用一个真正简单的单状态机尝试了这个(所以只有状态机 1,但有初始点和最终点)并且它工作得很好,System.out.println()
正在编写整个代码。
但是对于这 2 个状态机,机器从 TOP 处的 top_inital 点开始,然后转到top_s1。这是预期的并且有效
比我预期的要越过 topExitPoint1 到 sm1EntryPoint -> 进入 StateMachine1 -> 比 StateMachine2 -> 回到 top 等等。
但不幸的是,我机器中唯一使用的状态是 top -> top_s1状态。
控制台日志只显示了这个:
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
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
看起来像这样:
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());
}
};
}
}
如果您想查看模型浏览器的外观:
所以,我解决了这个问题,在一个项目中构建了两个独立的状态机并将它们连接起来
https://github.com/joergi/uml-spring-state-machine/看到新推送到master
Link 到 github 上的项目进行测试
Payprus 文件是 here
我正在尝试用 Papyrus 制作一个状态机。状态机应该将两个单一的状态机合并为一个,如您在第一张图片中所见:
状态机1定义在第2张图,状态机2定义在第3张图
我在 spring 应用程序中使用 UML(向下滚动代码)
我用一个真正简单的单状态机尝试了这个(所以只有状态机 1,但有初始点和最终点)并且它工作得很好,System.out.println()
正在编写整个代码。
但是对于这 2 个状态机,机器从 TOP 处的 top_inital 点开始,然后转到top_s1。这是预期的并且有效
比我预期的要越过 topExitPoint1 到 sm1EntryPoint -> 进入 StateMachine1 -> 比 StateMachine2 -> 回到 top 等等。
但不幸的是,我机器中唯一使用的状态是 top -> top_s1状态。 控制台日志只显示了这个:
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
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
看起来像这样:
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());
}
};
}
}
如果您想查看模型浏览器的外观:
所以,我解决了这个问题,在一个项目中构建了两个独立的状态机并将它们连接起来 https://github.com/joergi/uml-spring-state-machine/看到新推送到master