Search in sources :

Example 1 with DefaultStatusDecisionStrategy

use of io.seata.saga.engine.strategy.impl.DefaultStatusDecisionStrategy in project seata by seata.

the class DefaultStateMachineConfig method init.

protected void init() throws Exception {
    if (expressionFactoryManager == null) {
        expressionFactoryManager = new ExpressionFactoryManager();
        SpringELExpressionFactory springELExpressionFactory = new SpringELExpressionFactory();
        springELExpressionFactory.setApplicationContext(getApplicationContext());
        expressionFactoryManager.putExpressionFactory(ExpressionFactoryManager.DEFAULT_EXPRESSION_TYPE, springELExpressionFactory);
        SequenceExpressionFactory sequenceExpressionFactory = new SequenceExpressionFactory();
        sequenceExpressionFactory.setSeqGenerator(getSeqGenerator());
        expressionFactoryManager.putExpressionFactory(DomainConstants.EXPRESSION_TYPE_SEQUENCE, sequenceExpressionFactory);
    }
    if (evaluatorFactoryManager == null) {
        evaluatorFactoryManager = new EvaluatorFactoryManager();
        ExpressionEvaluatorFactory expressionEvaluatorFactory = new ExpressionEvaluatorFactory();
        expressionEvaluatorFactory.setExpressionFactory(expressionFactoryManager.getExpressionFactory(ExpressionFactoryManager.DEFAULT_EXPRESSION_TYPE));
        evaluatorFactoryManager.putEvaluatorFactory(EvaluatorFactoryManager.EVALUATOR_TYPE_DEFAULT, expressionEvaluatorFactory);
        evaluatorFactoryManager.putEvaluatorFactory(DomainConstants.EVALUATOR_TYPE_EXCEPTION, new ExceptionMatchEvaluatorFactory());
    }
    if (stateMachineRepository == null) {
        StateMachineRepositoryImpl stateMachineRepository = new StateMachineRepositoryImpl();
        stateMachineRepository.setCharset(charset);
        stateMachineRepository.setSeqGenerator(seqGenerator);
        stateMachineRepository.setStateLangStore(stateLangStore);
        stateMachineRepository.setDefaultTenantId(defaultTenantId);
        stateMachineRepository.setJsonParserName(sagaJsonParser);
        if (resources != null) {
            try {
                stateMachineRepository.registryByResources(resources, defaultTenantId);
            } catch (IOException e) {
                LOGGER.error("Load State Language Resources failed.", e);
            }
        }
        this.stateMachineRepository = stateMachineRepository;
    }
    if (stateLogRepository == null) {
        StateLogRepositoryImpl stateLogRepositoryImpl = new StateLogRepositoryImpl();
        stateLogRepositoryImpl.setStateLogStore(stateLogStore);
        this.stateLogRepository = stateLogRepositoryImpl;
    }
    if (statusDecisionStrategy == null) {
        statusDecisionStrategy = new DefaultStatusDecisionStrategy();
    }
    if (syncProcessCtrlEventPublisher == null) {
        ProcessCtrlEventPublisher syncEventPublisher = new ProcessCtrlEventPublisher();
        ProcessControllerImpl processorController = createProcessorController(syncEventPublisher);
        ProcessCtrlEventConsumer processCtrlEventConsumer = new ProcessCtrlEventConsumer();
        processCtrlEventConsumer.setProcessController(processorController);
        DirectEventBus directEventBus = new DirectEventBus();
        syncEventPublisher.setEventBus(directEventBus);
        directEventBus.registerEventConsumer(processCtrlEventConsumer);
        syncProcessCtrlEventPublisher = syncEventPublisher;
    }
    if (enableAsync && asyncProcessCtrlEventPublisher == null) {
        ProcessCtrlEventPublisher asyncEventPublisher = new ProcessCtrlEventPublisher();
        ProcessControllerImpl processorController = createProcessorController(asyncEventPublisher);
        ProcessCtrlEventConsumer processCtrlEventConsumer = new ProcessCtrlEventConsumer();
        processCtrlEventConsumer.setProcessController(processorController);
        AsyncEventBus asyncEventBus = new AsyncEventBus();
        asyncEventBus.setThreadPoolExecutor(getThreadPoolExecutor());
        asyncEventPublisher.setEventBus(asyncEventBus);
        asyncEventBus.registerEventConsumer(processCtrlEventConsumer);
        asyncProcessCtrlEventPublisher = asyncEventPublisher;
    }
    if (this.serviceInvokerManager == null) {
        this.serviceInvokerManager = new ServiceInvokerManager();
        SpringBeanServiceInvoker springBeanServiceInvoker = new SpringBeanServiceInvoker();
        springBeanServiceInvoker.setApplicationContext(getApplicationContext());
        springBeanServiceInvoker.setThreadPoolExecutor(threadPoolExecutor);
        springBeanServiceInvoker.setSagaJsonParser(getSagaJsonParser());
        this.serviceInvokerManager.putServiceInvoker(DomainConstants.SERVICE_TYPE_SPRING_BEAN, springBeanServiceInvoker);
    }
    if (this.scriptEngineManager == null) {
        this.scriptEngineManager = new ScriptEngineManager();
    }
}
Also used : ProcessCtrlEventConsumer(io.seata.saga.proctrl.eventing.impl.ProcessCtrlEventConsumer) EvaluatorFactoryManager(io.seata.saga.engine.evaluation.EvaluatorFactoryManager) SequenceExpressionFactory(io.seata.saga.engine.expression.seq.SequenceExpressionFactory) ScriptEngineManager(javax.script.ScriptEngineManager) IOException(java.io.IOException) ServiceInvokerManager(io.seata.saga.engine.invoker.ServiceInvokerManager) SpringELExpressionFactory(io.seata.saga.engine.expression.spel.SpringELExpressionFactory) StateMachineRepositoryImpl(io.seata.saga.engine.repo.impl.StateMachineRepositoryImpl) StateLogRepositoryImpl(io.seata.saga.engine.repo.impl.StateLogRepositoryImpl) DefaultStatusDecisionStrategy(io.seata.saga.engine.strategy.impl.DefaultStatusDecisionStrategy) ExpressionEvaluatorFactory(io.seata.saga.engine.evaluation.expression.ExpressionEvaluatorFactory) ExpressionFactoryManager(io.seata.saga.engine.expression.ExpressionFactoryManager) ProcessControllerImpl(io.seata.saga.proctrl.impl.ProcessControllerImpl) ProcessCtrlEventPublisher(io.seata.saga.proctrl.eventing.impl.ProcessCtrlEventPublisher) DirectEventBus(io.seata.saga.proctrl.eventing.impl.DirectEventBus) SpringBeanServiceInvoker(io.seata.saga.engine.invoker.impl.SpringBeanServiceInvoker) ExceptionMatchEvaluatorFactory(io.seata.saga.engine.evaluation.exception.ExceptionMatchEvaluatorFactory) AsyncEventBus(io.seata.saga.proctrl.eventing.impl.AsyncEventBus)

Aggregations

EvaluatorFactoryManager (io.seata.saga.engine.evaluation.EvaluatorFactoryManager)1 ExceptionMatchEvaluatorFactory (io.seata.saga.engine.evaluation.exception.ExceptionMatchEvaluatorFactory)1 ExpressionEvaluatorFactory (io.seata.saga.engine.evaluation.expression.ExpressionEvaluatorFactory)1 ExpressionFactoryManager (io.seata.saga.engine.expression.ExpressionFactoryManager)1 SequenceExpressionFactory (io.seata.saga.engine.expression.seq.SequenceExpressionFactory)1 SpringELExpressionFactory (io.seata.saga.engine.expression.spel.SpringELExpressionFactory)1 ServiceInvokerManager (io.seata.saga.engine.invoker.ServiceInvokerManager)1 SpringBeanServiceInvoker (io.seata.saga.engine.invoker.impl.SpringBeanServiceInvoker)1 StateLogRepositoryImpl (io.seata.saga.engine.repo.impl.StateLogRepositoryImpl)1 StateMachineRepositoryImpl (io.seata.saga.engine.repo.impl.StateMachineRepositoryImpl)1 DefaultStatusDecisionStrategy (io.seata.saga.engine.strategy.impl.DefaultStatusDecisionStrategy)1 AsyncEventBus (io.seata.saga.proctrl.eventing.impl.AsyncEventBus)1 DirectEventBus (io.seata.saga.proctrl.eventing.impl.DirectEventBus)1 ProcessCtrlEventConsumer (io.seata.saga.proctrl.eventing.impl.ProcessCtrlEventConsumer)1 ProcessCtrlEventPublisher (io.seata.saga.proctrl.eventing.impl.ProcessCtrlEventPublisher)1 ProcessControllerImpl (io.seata.saga.proctrl.impl.ProcessControllerImpl)1 IOException (java.io.IOException)1 ScriptEngineManager (javax.script.ScriptEngineManager)1