Search in sources :

Example 1 with StateLogStore

use of io.seata.saga.engine.store.StateLogStore in project seata by seata.

the class SubStateMachineHandler method forwardStateMachine.

private StateMachineInstance forwardStateMachine(Map<String, Object> startParams, StateMachineEngine engine, ProcessContext context, StateInstance stateInstance, SubStateMachine subStateMachine) {
    StateMachineConfig stateMachineConfig = (StateMachineConfig) context.getVariable(DomainConstants.VAR_NAME_STATEMACHINE_CONFIG);
    StateLogStore statePersister = stateMachineConfig.getStateLogStore();
    if (statePersister == null) {
        throw new ForwardInvalidException("StatePersister is not configured", FrameworkErrorCode.ObjectNotExists);
    }
    StateInstance originalStateInst = stateInstance;
    do {
        originalStateInst = statePersister.getStateInstance(originalStateInst.getStateIdRetriedFor(), originalStateInst.getMachineInstanceId());
    } while (StringUtils.hasText(originalStateInst.getStateIdRetriedFor()));
    List<StateMachineInstance> subInst = statePersister.queryStateMachineInstanceByParentId(EngineUtils.generateParentId(originalStateInst));
    if (subInst.size() > 0) {
        String subInstId = subInst.get(0).getId();
        return engine.forward(subInstId, startParams);
    } else {
        originalStateInst.setStateMachineInstance(stateInstance.getStateMachineInstance());
        return startNewStateMachine(startParams, engine, originalStateInst, subStateMachine);
    }
}
Also used : ForwardInvalidException(io.seata.saga.engine.exception.ForwardInvalidException) StateMachineConfig(io.seata.saga.engine.StateMachineConfig) StateLogStore(io.seata.saga.engine.store.StateLogStore) StateInstance(io.seata.saga.statelang.domain.StateInstance) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance)

Aggregations

StateMachineConfig (io.seata.saga.engine.StateMachineConfig)1 ForwardInvalidException (io.seata.saga.engine.exception.ForwardInvalidException)1 StateLogStore (io.seata.saga.engine.store.StateLogStore)1 StateInstance (io.seata.saga.statelang.domain.StateInstance)1 StateMachineInstance (io.seata.saga.statelang.domain.StateMachineInstance)1