我需要相同的 SM 来服务同一数据库表中的各种记录(无法为每个记录创建 SM)。这是使用另一条记录中的新状态重新初始化 SM 的合适方法吗?或者您能建议更好的方法吗?
public static <S, E> void reinitStateMachine(Integer key, IStateMachineEnabledService sees, StateMachine<S, E> stateMachine, Class<? extends Enum> statesClazz) {
String dbReadState;
try {
dbReadState = sees.findStateById(key);
} catch (Exception e) {
throw new MissingResourceException("Error while trying to load record with state, no record found: "+key+". Extra info:"+e.getMessage(),sees.toString(),String.valueOf(key));
}
S currentState = (S) Enum.valueOf(statesClazz, dbReadState);
stateMachine.stop();
((AbstractStateMachine<S, E>) stateMachine).resetStateMachine(new DefaultStateMachineContext<S, E>(currentState, null, null, null));
stateMachine.start();
}
Thanks !
PS:我知道 1.1.0 中存在持久和恢复接口,但持久 SMContext 仅适用于字符串状态机,而我使用枚举。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)