我正在测试 Spring Statemachine,特别是我对应用状态机来管理我的对象的状态很感兴趣。
我的状态机是StateMachine<EpisodeState, EpisodeEvent>
.
我的业务对象Episode
有一个类型为 的枚举属性 ( state
) EpisodeState
,它应该保存剧集的状态机状态。我有一个批处理过程,它将在初始化时获得一个 Statemachine 实例。我想遵循基本流程:
Episode
从数据库加载一个EpisodeState
从该Episode
实例中的状态机设置当前状态。- 向状态机发送事件。
- 从 Statemachine(发布事件)获取结果状态并
EpisodeState
在我的Episode
实例中设置。 - 保存
Episode
实例。
文档提到了一个extendedState
属性,在我的测试中它是空的,但似乎支持任意对象的映射,我想我可以用它来保存我的主键Episode
,但我不知道如何设置当前状态将状态机的EpisodeState
值转换为Episode
.
我已经StateMachineInterceptorAdapter<EpisodeState, EpisodeEvent>
用preEvent
.