Search in sources :

Example 31 with StateInstance

use of io.seata.saga.statelang.domain.StateInstance 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

StateInstance (io.seata.saga.statelang.domain.StateInstance)31 StateMachineInstance (io.seata.saga.statelang.domain.StateMachineInstance)16 EngineExecutionException (io.seata.saga.engine.exception.EngineExecutionException)12 StateInstruction (io.seata.saga.engine.pcext.StateInstruction)11 StateMachineConfig (io.seata.saga.engine.StateMachineConfig)9 ForwardInvalidException (io.seata.saga.engine.exception.ForwardInvalidException)7 Map (java.util.Map)7 StateMachine (io.seata.saga.statelang.domain.StateMachine)5 AbstractTaskState (io.seata.saga.statelang.domain.impl.AbstractTaskState)5 ServiceTaskStateImpl (io.seata.saga.statelang.domain.impl.ServiceTaskStateImpl)5 ArrayList (java.util.ArrayList)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 HierarchicalProcessContext (io.seata.saga.proctrl.HierarchicalProcessContext)4 ExecutionStatus (io.seata.saga.statelang.domain.ExecutionStatus)4 State (io.seata.saga.statelang.domain.State)4 HashMap (java.util.HashMap)4 List (java.util.List)4 ProcessContext (io.seata.saga.proctrl.ProcessContext)3 Loop (io.seata.saga.statelang.domain.TaskState.Loop)3 LinkedHashMap (java.util.LinkedHashMap)3