【发布时间】:2016-12-16 14:42:02
【问题描述】:
我正在尝试使用 Papyrus 从您遵循 UML 模型构建一个状态机。 每个阶段的 entryAction 都使用 DefaultStateMachineComponentResolver 重新注册,以解析到我的 spring 应用程序中的各个 EntryAction 类。 我的要求是
1) 从 CS 阶段开始,在获得触发事件 SUCCESS 后,执行应该分叉到两个线程。
2) 在一个线程中 DE1 和 TE1 应该顺序执行,而在另一个线程中 DE2 和 TE2 应该顺序执行
3) 仅当两个线程都成功执行时才会转换到 END 状态, 即,从 TE1 开始,应该发生一个转换到由事件 SUCCESS 发出信号的加入状态,从 TE2 开始,应该发生一个转换到由事件 SUCCESS 发出信号的加入状态
4) 即。成功执行 2 个线程后应该会转换到 END 状态。
5) 在执行每个阶段时,如果任何任务失败(任务写在 EntryAction 类中), 状态机应该导航到 END 状态,使用的信号是 FAILURE、TERMINATED(基于发生错误的严重性)
这是我用来构建状态机并触发执行的代码
Builder<String, String> builder = StateMachineBuilder
.<String, String> builder();
builder.configureConfiguration()
.withConfiguration()
.autoStartup(false)
.listener(listener())
.beanFactory(
this.applicationContext.getAutowireCapableBeanFactory());//.taskExecutor(taskExecutor());
DefaultStateMachineComponentResolver<String, String> resolver = new DefaultStateMachineComponentResolver<>();
resolver.registerAction("startEntryAction", this.startEntryAction);
resolver.registerAction("apEntryAction", this.apEntryAction);
resolver.registerAction("psEntryAction", this.psEntryAction);
//all entry action classed are registered
...
...
UmlStateMachineModelFactory umlStateMachineModelFactory = new UmlStateMachineModelFactory("classpath:model.uml");
umlStateMachineModelFactory.setStateMachineComponentResolver(resolver);
builder.configureModel().withModel().factory(umlStateMachineModelFactory);
StateMachine<String, String> stateMachine = builder.build();
stateMachine.start()
我遇到的问题
1) 在使用 taskExecutor 时,状态机执行没有开始。
2)注释掉 taskExecutor 后,触发了执行,在控制台中我从 entryAction 类中获取了日志。
3)在每个入口动作类中,我只是添加了以下代码以转换到下一个状态,并用于记录目的
@Override
public void execute(StateContext<String, String> paramStateContext) {
LOGGER.debug("Start State entered! ");
paramStateContext.getStateMachine().sendEvent("SUCCESS");
}
4) 但问题是在分析日志后从未进入状态 TE1。 我的要求是在执行TE1EntryAction和TE2EntryAction中的任务后进入END状态
请在日志下方查找
[![enter image description here][1]][1]19:03:54.963 DEBUG o.i.r.p.a.StartEntryAction - Start State entered!
19:03:55.007 DEBUG o.i.r.p.a.APEntryAction - AP State entered!
19:03:55.007 DEBUG o.i.r.p.a.PSEntryAction - PS State entered!
19:03:55.007 DEBUG o.i.r.p.a.PBEntryAction - PB State entered!
19:03:55.007 DEBUG o.i.r.p.a.CSEntryAction - CS State entered!
19:03:55.007 DEBUG o.i.r.p.a.DE1EntryAction - DE1 State entered!
19:03:55.007 DEBUG o.i.r.p.a.DE2EntryAction - DE2 State entered!
19:03:55.007 DEBUG o.i.r.p.a.TE2EntryAction - TE2 State entered!
19:03:55.023 DEBUG o.i.r.p.a.EndStateEntryAction - END State entered!
我创建的 UML 模型中是否存在问题。 如果是的话,状态图应该是什么样子的
非常感谢您的帮助。
【问题讨论】:
-
编译'org.springframework.statemachine:spring-statemachine-core:1.1.0.RELEASE' 编译'org.springframework.statemachine:spring-statemachine-uml:1.1.0.RELEASE'跨度>