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);
}
}
Aggregations