240 發(fā)簡信
IP屬地:廣西
  • MyStateMachineUtils類使用反射就能解決包名問題了誉简。
    public abstract class MyStateMachineUtils extends StateMachineUtils {

    public static <S, E> void setCurrentState(StateMachine<S, E> stateMachine, S state) {
    if (stateMachine instanceof AbstractStateMachine) {
    setCurrentState((AbstractStateMachine<S, E>) stateMachine, state);

    System.out.println("StateMachine Current:" + stateMachine);
    } else {
    throw new IllegalArgumentException("Provided StateMachine is not a valid type");
    }
    }

    public static <S, E> void setCurrentState(AbstractStateMachine<S, E> stateMachine, S state) {
    Method method = ReflectUtil.getMethod(stateMachine.getClass(),"setCurrentStateInternal"
    ,State.class, Message.class, Transition.class,Boolean.class,StateMachine.class,
    Collection.class,Collection.class);
    method.setAccessible(true);
    ReflectionUtils.invokeMethod(method,stateMachine,findState(stateMachine, state), null, null, false, stateMachine,null,null);
    }

    private static <S, E> State<S, E> findState(AbstractStateMachine<S, E> stateMachine, S stateId) {
    for (State<S, E> state : stateMachine.getStates()) {
    if (state.getId() == stateId) {
    return state;
    }
    }

    throw new IllegalArgumentException("Specified State ID is not valid");
    }
    }

    ReflectUtil是hutool里的号杠,ReflectionUtils是spring的渤愁。
    ReflectUtil能反射出方法但執(zhí)行不了居夹,ReflectionUtils反射不出方法榨婆,所以混著用

  • 想請問下博主顺少,既然可以直接設(shè)置當(dāng)前狀態(tài)機狀態(tài)了枢赔,還需要持久化嗎

    Spring StateMachine狀態(tài)機引擎在項目中的應(yīng)用(八)-靈活指定引擎實例狀態(tài)

    一直以來,總覺得ssm不夠靈活括授,主要原因是沒找到為狀態(tài)機指定狀態(tài)的方式坞笙,也就意味著狀態(tài)機引擎實例必須要跟對應(yīng)的業(yè)務(wù)數(shù)據(jù)一起持久化,雖然ssm提供了多重持久化的方式荚虚,依然覺得有...

亚洲A日韩AV无卡,小受高潮白浆痉挛av免费观看,成人AV无码久久久久不卡网站,国产AV日韩精品