【发布时间】:2022-01-02 06:29:08
【问题描述】:
你能帮我解决这个问题吗?
我有员工{ Start, S1 , S1_1_start, S1_1_end , S1_2_start, S1_2_end, S2, End } 的状态。
public void configure(StateMachineStateConfigurer<EmployeeStates, EmployeeEvents> states) throws Exception {
states
.withStates()
.initial(EmployeeStates.Start)
.fork(EmployeeStates.FORK)
.state(EmployeeStates.S1)
.join(EmployeeStates.JOIN)
.state(EmployeeStates.S2)
.end(EmployeeStates.End)
.and()
.withStates()
.parent(EmployeeStates.S1)
.initial(EmployeeStates.S1_1_start)
.end(EmployeeStates.S1_1_end)
.and()
.withStates()
.parent(EmployeeStates.S1)
.initial(EmployeeStates.S1_2_start)
.end(EmployeeStates.S1_2_end);
}
我需要将机器状态重置为从 [S1, , S1_1_start, S1_2_end] 开始,并将我的事件添加到 S2
这是重置我的机器的正确方法吗?
StateMachine<EmployeeStates, EmployeeEvents> sm = this.factory.getStateMachine();
sm.stopReactively().subscribe();
sm.getStateMachineAccessor().doWithAllRegions(sma -> {
sma.addStateMachineInterceptor(employeeStateChangeInterceptor);
StateMachineContext<EmployeeStates,EmployeeEvents> ctx1 = new DefaultStateMachineContext(EmployeeStates.S1_1_start,null,null,null,null);
StateMachineContext<EmployeeStates,EmployeeEvents> ctx2 = new DefaultStateMachineContext(EmployeeStates.S1_2_end,null,null,null,null);
List<StateMachineContext<EmployeeStates,EmployeeEvents>> list = List.of(ctx1,ctx2);
sma.resetStateMachineReactively(new DefaultStateMachineContext<EmployeeStates, EmployeeEvents>(list,EmployeeStates.S1, null,null, null,null)).subscribe();
});
在日志中我看到它是错误的,它首先将状态更改为预期状态,但随后又为子状态再次执行此操作:(
state changed from [S1, , S1_1_start ,S1_2_end ] to ObjectState [S2]
state changed from [ S1_1_start ] to ObjectState [S1_1_end]
【问题讨论】:
-
只是一个提示...这里很多可以帮助您解决问题的人都是专业人士。 “Can u”和“Wanna”不是专业用语。它们会损害您获得答案的机会。也许英语不是你的主要语言。如果是这样,不完美的单词选择是可以理解的。但仍然值得学习正确的形式。
-
对不起,我的英语不好,这不是我的母语
-
不需要道歉。我不能像你那样用英语以外的任何语言发帖。正如我所说,这只是一个小费......
-
我只知道我在过去 15 分钟内读到的有关 Spring 状态机的内容,所以这是一个猜测。看起来您的逻辑正在将您设置的 both 上下文应用到 each 区域。您可能想尝试向区域添加名称(使用
.region()方法)。然后使用这些来确定在每种情况下应用哪个上下文。无论如何,builder API 不是最好的,文档也不清楚。我希望你能得到答案。
标签: java spring spring-statemachine