Search in sources :

Example 1 with DefaultStateMachineConfig

use of io.seata.saga.engine.impl.DefaultStateMachineConfig in project seata by seata.

the class DbAndReportTcStateLogStore method isUpdateMode.

private boolean isUpdateMode(StateInstance stateInstance, ProcessContext context) {
    DefaultStateMachineConfig stateMachineConfig = (DefaultStateMachineConfig) context.getVariable(DomainConstants.VAR_NAME_STATEMACHINE_CONFIG);
    StateInstruction instruction = context.getInstruction(StateInstruction.class);
    ServiceTaskStateImpl state = (ServiceTaskStateImpl) instruction.getState(context);
    StateMachine stateMachine = stateInstance.getStateMachineInstance().getStateMachine();
    if (StringUtils.hasLength(stateInstance.getStateIdRetriedFor())) {
        if (null != state.isRetryPersistModeUpdate()) {
            return state.isRetryPersistModeUpdate();
        } else if (null != stateMachine.isRetryPersistModeUpdate()) {
            return stateMachine.isRetryPersistModeUpdate();
        }
        return stateMachineConfig.isSagaRetryPersistModeUpdate();
    } else if (StringUtils.hasLength(stateInstance.getStateIdCompensatedFor())) {
        // find if this compensate has been executed
        for (int i = 0; i < stateInstance.getStateMachineInstance().getStateList().size(); i++) {
            StateInstance aStateInstance = stateInstance.getStateMachineInstance().getStateList().get(i);
            if (aStateInstance.isForCompensation() && aStateInstance.getName().equals(stateInstance.getName())) {
                if (null != state.isCompensatePersistModeUpdate()) {
                    return state.isCompensatePersistModeUpdate();
                } else if (null != stateMachine.isCompensatePersistModeUpdate()) {
                    return stateMachine.isCompensatePersistModeUpdate();
                }
                return stateMachineConfig.isSagaCompensatePersistModeUpdate();
            }
        }
        return false;
    }
    return false;
}
Also used : StateInstruction(io.seata.saga.engine.pcext.StateInstruction) StateMachine(io.seata.saga.statelang.domain.StateMachine) DefaultStateMachineConfig(io.seata.saga.engine.impl.DefaultStateMachineConfig) ServiceTaskStateImpl(io.seata.saga.statelang.domain.impl.ServiceTaskStateImpl) StateInstance(io.seata.saga.statelang.domain.StateInstance)

Aggregations

DefaultStateMachineConfig (io.seata.saga.engine.impl.DefaultStateMachineConfig)1 StateInstruction (io.seata.saga.engine.pcext.StateInstruction)1 StateInstance (io.seata.saga.statelang.domain.StateInstance)1 StateMachine (io.seata.saga.statelang.domain.StateMachine)1 ServiceTaskStateImpl (io.seata.saga.statelang.domain.impl.ServiceTaskStateImpl)1