我想用timerOnce来延迟,但它不起作用
我想从状态重复导出到状态到状态再次导出到状态但操作重新导出()尚未执行。我有以下状态机:我想用timerOnce来延迟,但它不起作用,timer,spring-statemachine,Timer,Spring Statemachine,我想从状态重复导出到状态到状态再次导出到状态但操作重新导出()尚未执行。我有以下状态机: public StateMachineBuilder.Builder<StatusId, ActionId> construct(StateMachineBuilder.Builder<StatusId, ActionId> builder) throws Exception { builder.configureStates().withStates() .
public StateMachineBuilder.Builder<StatusId, ActionId> construct(StateMachineBuilder.Builder<StatusId, ActionId> builder) throws Exception {
builder.configureStates().withStates()
.states(ImmutableSet.of(OBTAINED_BY_B, FOR_EXPORT_TO_A, EXPORTING_TO_A,
EXPORT_TO_A_ERROR, EXPORTING_TO_A_TIMEOUT,
RECEIVED_BY_A, NOT_RECEIVED_BY_A, RECEIVED_A_ERROR, REPEATED_EXPORT_TO_A))
.state(FOR_EXPORT_TO_A, checkPassedAction(), null)
.state(EXPORTING_TO_A, exportedAction(), null)
.choice(EXPORTED_TO_A_OR_NOT)
.choice(EXPORT_TO_A_AGAIN);
builder.configureTransitions().withExternal()
.source(OBTAINED_BY_B).target(FOR_EXPORT_TO_A)
.and().withExternal()
.source(FOR_EXPORT_TO_A).target(EXPORTED_TO_A_OR_NOT)
.and().withChoice()
.source(EXPORTED_TO_A_OR_NOT)
.first(EXPORTING_TO_A, exportingToAGuardSsm)
.last(REPEATED_EXPORT_TO_A)
.and().withExternal()
.source(REPEATED_EXPORT_TO_A)
.target(EXPORT_TO_A_AGAIN)
.event(REEXPORT_TO_A)
.and().withChoice()
.source(EXPORT_TO_A_AGAIN)
.first(EXPORTING_TO_A, exportingToAGuardSsm)
.then(EXPORT_TO_A_ERROR, checkRepeatExportGuard)
.then(REPEATED_EXPORT_TO_A, repeatExportToBGuardSsm)
.last(EXPORT_TO_A_ERROR)
但这一行动尚未执行
private Action<StatusId, ActionId> reexportEvent() {
//some code
return context -> {
Doc doc = SsmUtil.getDoc(context);
doc.setRepeatCount(doc.getRepeatCount() + 1);
context.getStateMachine().sendEvent(REEXPORT_TO_A);
};
}
私有操作reexportEvent(){
//一些代码
返回上下文->{
Doc Doc=ssmulti.getDoc(上下文);
doc.setRepeatCount(doc.getRepeatCount()+1);
context.getStateMachine().sendEvent(将\重新导出到\ A);
};
}
对于Spring状态机中的触发器,有一件关键的事情需要理解——它们与一个状态相关联,您需要保持该状态才能执行触发器。延迟从您进入该状态的那一刻开始-如果您在到达延迟时间之前退出该状态,则触发器不会执行
例如:
- 为状态“a”指定一个5秒延迟的触发器
- 输入状态“A”
- 第二次退出状态“A”
签出演示此行为的单元测试(TestTriggersDelay)。对于Spring状态机中的触发器,有一件关键的事情需要理解——它们与一个状态关联,您需要保持该状态才能执行触发器。延迟从您进入该状态的那一刻开始-如果您在到达延迟时间之前退出该状态,则触发器不会执行 例如:
- 为状态“a”指定一个5秒延迟的触发器
- 输入状态“A”
- 第二次退出状态“A”
private Action<StatusId, ActionId> reexportEvent() {
//some code
return context -> {
Doc doc = SsmUtil.getDoc(context);
doc.setRepeatCount(doc.getRepeatCount() + 1);
context.getStateMachine().sendEvent(REEXPORT_TO_A);
};
}