Closed zivyou closed 2 years ago
After further debugging, I got the real reason. Since I configured the state machine with ".autoStartup(true)" enable, when stateMachineFactory.getStateMachine(machineId) was called, state transition will be triggered and the data will be wrote back to Redis. That is why I got the wrong state machine context. So, it is neither a design constrain of FSM theory, nor a code issue. It is just a configuration issue.
Hi: I config a EnumStateMachine with StateMachinePersist and RuntimePersister enabled. The config process may like this:
With debugging the project, I think the project works like this:
But when call DefaultStateMachineService.acquireStateMachine(), the problem happens.
As we can see, when stateMachine == null, we firstly try to get a stateMachine by stateMachineFactory.getStateMachine(machineId); then try to replace the stateMachine object with then context loaded from stateMachinePersist. The key point is that, when we call stateMachineFactory.getStateMachine(machineId), it comes with state transition and will write data back into Redis. That means the following codes which try to load state machine context will get un-excepted result. I am not sure if it is a design contrain of FSM theory, or just a code issue. Anyway, I am going to extend DefaultStateMachineService class to override these codes.
Thanks.