到目前为止,我在状态机方面取得了不错的进展。当我想使用 fork 时,我最近的问题出现了(我正在使用 UML)。叉子没有按预期工作,我认为这是因为持久性。我将我的机器保存在redis中。参考下图。
这是我的顶级机器,其中 Manage-commands 是子机器参考,而顶级区域就是这样。
现在说我在 redis 中保持了一些状态,来自下面的区域,然后一个 ONLINE 事件来了,然后机器不接受该事件,显然是因为我已经要求机器使用给定的键从 redis 恢复状态。bur 我希望两个区域都被持久化,以便根据事件选择其中一个。有什么办法可以做到这一点?
以下是我坚持恢复的方式
private void feedMachine(StateMachine<String, String> stateMachine, String user, GenericMessage<String> event)
throws Exception {
stateMachine.sendEvent(event);
System.out.println("persist machine --- > state :" + stateMachine.getState().toString());
redisStateMachinePersister.persist(stateMachine, "testprefixSw:" + user);
}
private StateMachine<String, String> resetStateMachineFromStore(StateMachine<String, String> stateMachine,
String user) throws Exception {
StateMachine<String, String> machine = redisStateMachinePersister.restore(stateMachine, "testprefixSw:" + user);
System.out.println("restore machine --- > state :" + machine.getState().toString());
return machine;
}