2017-08-15 108 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上创建增强请求,因为在思考重置后可能发生的情况时,可能会执行状态操作。我们绝不会执行一个输入动作,因为在复位期间没有输入状态,但正如我所说的,执行状态执行动作可能是有意义的。