hekailiang / squirrel

squirrel-foundation is a State Machine library, which provided a lightweight, easy use, type safe and programmable state machine implementation for Java.
http://hekailiang.github.io/squirrel/
Other
2.19k stars 540 forks source link

Persistence Requirement #82

Open aniketvsawant opened 6 years ago

aniketvsawant commented 6 years ago

Hi Team, I am in a process of evaluating squirrel state machine and looking for the features that are best fits to my requirement. As a state machine I would like to persist the states as I have long running states requirement. As this state machine is embedded in nature and tightly coupled with the application, any failure in the application will results into the loss of the state machines instances and will be hard to recover the states back when application restarts. What is the best way to store and recover the states of an entities. Do you have any plan to support out of the box persistence capability. Thanks.

hekailiang commented 6 years ago

please refer to the "Save/Load State Machine Data" in the doc. By default squirrel provide string content based StateMachineData implementation, for simple solution you can just dump the state machine data and store where u want, and restore the state machine states by reload from the string data. Or you can customize the StateMachineData(Reader/Writer) implementation for more fine granularity storage control. The customized StateMachineData can be register into state machine by org.squirrelframework.foundation.component.SquirrelProvider#register, register the StateMachineData interface with ur customize implementations.

aniketvsawant commented 6 years ago

Thanks @hekailiang I have gone through the documentation and find helpful. As per my understanding we can create a single instance of state machine at a time. If its correct then I would like to know the -

  1. Support for maintaining multiple state machine instance
  2. Support for concurrent state machine engines

As state machine is associated with the entity object (e.g. User), how can squirrel maintain multiple instances of state machine per entity as an embedded state machine behaviour without persistence. Is this the out of the box feature or do we need to implement our own solution.