2017-08-15 112 views
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未被調用。 是否有可能爲這種情況觸發此操作?

回答

0

不,它不是step2Action操作附加到轉換並且重置不會導致任何狀態條目。

隨時在github上創建增強請求,因爲在思考重置後可能發生的情況時,可能會執行狀態操作。我們絕不會執行一個輸入動作,因爲在復位期間沒有輸入狀態,但正如我所說的,執行狀態執行動作可能是有意義的。