240 發(fā)簡(jiǎn)信
IP屬地:山西
  • MyStateMachineUtils類(lèi)使用反射就能解決包名問(wèn)題了。
    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反射不出方法,所以混著用

  • 想請(qǐng)問(wèn)下博主,既然可以直接設(shè)置當(dāng)前狀態(tài)機(jī)狀態(tài)了,還需要持久化嗎

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

    一直以來(lái)张咳,總覺(jué)得ssm不夠靈活,主要原因是沒(méi)找到為狀態(tài)機(jī)指定狀態(tài)的方式似舵,也就意味著狀態(tài)機(jī)引擎實(shí)例必須要跟對(duì)應(yīng)的業(yè)務(wù)數(shù)據(jù)一起持久化脚猾,雖然ssm提供了多重持久化的方式,依然覺(jué)得有...

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