The right way to reload and restart State Machine with different data set

 ̄綄美尐妖づ 提交于 2019-12-24 00:45:33

问题


I need the same SM to serve various records from the same db-table (can't create SM per each record). Would this be appropriate way to reinitialize SM with new states from another record OR can you advice a better approach please ?

    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: I am aware of persist and restore interfaces in 1.1.0, but persisting SMContext works only for string state machine, while i use enum.

来源:https://stackoverflow.com/questions/38262665/the-right-way-to-reload-and-restart-state-machine-with-different-data-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!