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 尚未完成。不幸的是,在我将状态机重置为 State2 之后,没有调用 step2Action。是否可以针对这种情况触发此操作?

4

1 回答 1

0

不,这不是因为step2Action动作附加到转换并且重置不会导致任何状态进入。

随意在 github 上创建增强请求,因为在考虑重置后可能发生的情况时,可能会执行状态操作。我们永远不会执行进入动作,因为在重置期间没有进入状态,但正如我所说,执行状态执行动作可能是有意义的。

于 2017-08-18T06:00:11.607 回答