0
我有一個關於重置狀態機的問題。 配置春季狀態機重置
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還沒有完成。 不幸的是,在將狀態機重置爲狀態2後,step2Action未被調用。 是否有可能爲這種情況觸發此操作?