2

同じ db テーブルからさまざまなレコードを提供するために同じ 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();
}   

ありがとう !

PS: 1.1.0 でインターフェイスの永続化と復元を認識していますが、列挙型を使用している間、SMContext の永続化は文字列ステート マシンに対してのみ機能します。

4

0 に答える 0