我有一个关于重置状态机的问题。配置
protected StateMachine<ProfilingState, ProfilingEvent> buildStateMachine(
StateMachineBuilder.Builder<SomeState, SomeEvent> builder) throws Exception {
builder.configureStates()
.withStates()
.initial(SomeState.State1)
.states(EnumSet.allOf(SomeState.class));
builder.configureTransitions()
.withExternal()
.source(SomeState.Step1)
.target(SomeState.Step2)
.event(SomeEvent.Event1)
.action(step1Action())
.and()
.withExternal()
.source(SomeState.Step2)
.target(SomeState.Step3)
.event(SomeEvent.Event2)
.action(step2Action())
.and();
return builder.build();
}
我有用于持久/恢复状态机的 api。在恢复期间,我将状态机重置为以前的持久状态。
stateMachine
.getStateMachineAccessor()
.doWithAllRegions(access -> {
access.resetStateMachine(
new DefaultStateMachineContext(currentState, null, null, extendedState));
});
stateMachine.start();
我希望我可以在 jvm 崩溃后重置状态机并从我上次持久的状态继续。例如,最后一个持久状态是 Step2。让我们假设 Step2 的动作是一个长循环。让我们假设在处理这个循环的过程中发生了 Jvm 崩溃。在应用程序启动期间,应用程序识别出有未完成的流程。所以目标是从最后一个持久状态继续。这意味着在将状态机重置为 State2 后,我预计 step2Action 将被触发并且我将继续处理,因为 Step2 尚未完成。不幸的是,在我将状态机重置为 State2 之后,没有调用 step2Action。是否可以针对这种情况触发此操作?