Search in sources :

Example 1 with ProcessControllerImpl

use of io.seata.saga.proctrl.impl.ProcessControllerImpl in project seata by seata.

the class ProcessControllerTests method createProcessorController.

private ProcessControllerImpl createProcessorController(ProcessCtrlEventPublisher eventPublisher) throws Exception {
    DefaultRouterHandler defaultRouterHandler = new DefaultRouterHandler();
    defaultRouterHandler.setEventPublisher(eventPublisher);
    Map<String, ProcessRouter> processRouterMap = new HashMap<>(1);
    processRouterMap.put(ProcessType.STATE_LANG.getCode(), new MockProcessRouter());
    defaultRouterHandler.setProcessRouters(processRouterMap);
    CustomizeBusinessProcessor customizeBusinessProcessor = new CustomizeBusinessProcessor();
    Map<String, ProcessHandler> processHandlerMap = new HashMap<>(1);
    processHandlerMap.put(ProcessType.STATE_LANG.getCode(), new MockProcessHandler());
    customizeBusinessProcessor.setProcessHandlers(processHandlerMap);
    Map<String, RouterHandler> routerHandlerMap = new HashMap<>(1);
    routerHandlerMap.put(ProcessType.STATE_LANG.getCode(), defaultRouterHandler);
    customizeBusinessProcessor.setRouterHandlers(routerHandlerMap);
    ProcessControllerImpl processorController = new ProcessControllerImpl();
    processorController.setBusinessProcessor(customizeBusinessProcessor);
    return processorController;
}
Also used : DefaultRouterHandler(io.seata.saga.proctrl.handler.DefaultRouterHandler) CustomizeBusinessProcessor(io.seata.saga.proctrl.process.impl.CustomizeBusinessProcessor) HashMap(java.util.HashMap) MockProcessRouter(io.seata.saga.proctrl.mock.MockProcessRouter) MockProcessHandler(io.seata.saga.proctrl.mock.MockProcessHandler) ProcessControllerImpl(io.seata.saga.proctrl.impl.ProcessControllerImpl) RouterHandler(io.seata.saga.proctrl.handler.RouterHandler) DefaultRouterHandler(io.seata.saga.proctrl.handler.DefaultRouterHandler) MockProcessRouter(io.seata.saga.proctrl.mock.MockProcessRouter) ProcessHandler(io.seata.saga.proctrl.handler.ProcessHandler) MockProcessHandler(io.seata.saga.proctrl.mock.MockProcessHandler)

Example 2 with ProcessControllerImpl

use of io.seata.saga.proctrl.impl.ProcessControllerImpl in project seata by seata.

the class ProcessControllerTests method buildAsyncEventPublisher.

private ProcessCtrlEventPublisher buildAsyncEventPublisher() throws Exception {
    ProcessCtrlEventPublisher asyncEventPublisher = new ProcessCtrlEventPublisher();
    ProcessControllerImpl processorController = createProcessorController(asyncEventPublisher);
    ProcessCtrlEventConsumer processCtrlEventConsumer = new ProcessCtrlEventConsumer();
    processCtrlEventConsumer.setProcessController(processorController);
    AsyncEventBus asyncEventBus = new AsyncEventBus();
    asyncEventBus.setThreadPoolExecutor(new ThreadPoolExecutor(1, 5, 5000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()));
    asyncEventPublisher.setEventBus(asyncEventBus);
    asyncEventBus.registerEventConsumer(processCtrlEventConsumer);
    return asyncEventPublisher;
}
Also used : ProcessCtrlEventConsumer(io.seata.saga.proctrl.eventing.impl.ProcessCtrlEventConsumer) ProcessControllerImpl(io.seata.saga.proctrl.impl.ProcessControllerImpl) ProcessCtrlEventPublisher(io.seata.saga.proctrl.eventing.impl.ProcessCtrlEventPublisher) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) AsyncEventBus(io.seata.saga.proctrl.eventing.impl.AsyncEventBus)

Example 3 with ProcessControllerImpl

use of io.seata.saga.proctrl.impl.ProcessControllerImpl in project seata by seata.

the class ProcessControllerTests method buildEventPublisher.

private ProcessCtrlEventPublisher buildEventPublisher() throws Exception {
    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);
    return syncEventPublisher;
}
Also used : ProcessCtrlEventConsumer(io.seata.saga.proctrl.eventing.impl.ProcessCtrlEventConsumer) ProcessControllerImpl(io.seata.saga.proctrl.impl.ProcessControllerImpl) ProcessCtrlEventPublisher(io.seata.saga.proctrl.eventing.impl.ProcessCtrlEventPublisher) DirectEventBus(io.seata.saga.proctrl.eventing.impl.DirectEventBus)

Example 4 with ProcessControllerImpl

use of io.seata.saga.proctrl.impl.ProcessControllerImpl in project seata by seata.

the class DefaultStateMachineConfig method createProcessorController.

protected ProcessControllerImpl createProcessorController(ProcessCtrlEventPublisher eventPublisher) throws Exception {
    StateMachineProcessRouter stateMachineProcessRouter = new StateMachineProcessRouter();
    stateMachineProcessRouter.initDefaultStateRouters();
    loadStateRouterInterceptors(stateMachineProcessRouter.getStateRouters());
    StateMachineProcessHandler stateMachineProcessHandler = new StateMachineProcessHandler();
    stateMachineProcessHandler.initDefaultHandlers();
    loadStateHandlerInterceptors(stateMachineProcessHandler.getStateHandlers());
    DefaultRouterHandler defaultRouterHandler = new DefaultRouterHandler();
    defaultRouterHandler.setEventPublisher(eventPublisher);
    Map<String, ProcessRouter> processRouterMap = new HashMap<>(1);
    processRouterMap.put(ProcessType.STATE_LANG.getCode(), stateMachineProcessRouter);
    defaultRouterHandler.setProcessRouters(processRouterMap);
    CustomizeBusinessProcessor customizeBusinessProcessor = new CustomizeBusinessProcessor();
    Map<String, ProcessHandler> processHandlerMap = new HashMap<>(1);
    processHandlerMap.put(ProcessType.STATE_LANG.getCode(), stateMachineProcessHandler);
    customizeBusinessProcessor.setProcessHandlers(processHandlerMap);
    Map<String, RouterHandler> routerHandlerMap = new HashMap<>(1);
    routerHandlerMap.put(ProcessType.STATE_LANG.getCode(), defaultRouterHandler);
    customizeBusinessProcessor.setRouterHandlers(routerHandlerMap);
    ProcessControllerImpl processorController = new ProcessControllerImpl();
    processorController.setBusinessProcessor(customizeBusinessProcessor);
    return processorController;
}
Also used : DefaultRouterHandler(io.seata.saga.proctrl.handler.DefaultRouterHandler) CustomizeBusinessProcessor(io.seata.saga.proctrl.process.impl.CustomizeBusinessProcessor) StateMachineProcessHandler(io.seata.saga.engine.pcext.StateMachineProcessHandler) HashMap(java.util.HashMap) StateMachineProcessRouter(io.seata.saga.engine.pcext.StateMachineProcessRouter) ProcessRouter(io.seata.saga.proctrl.ProcessRouter) ProcessControllerImpl(io.seata.saga.proctrl.impl.ProcessControllerImpl) StateMachineProcessRouter(io.seata.saga.engine.pcext.StateMachineProcessRouter) DefaultRouterHandler(io.seata.saga.proctrl.handler.DefaultRouterHandler) RouterHandler(io.seata.saga.proctrl.handler.RouterHandler) ProcessHandler(io.seata.saga.proctrl.handler.ProcessHandler) StateMachineProcessHandler(io.seata.saga.engine.pcext.StateMachineProcessHandler)

Example 5 with ProcessControllerImpl

use of io.seata.saga.proctrl.impl.ProcessControllerImpl 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

ProcessControllerImpl (io.seata.saga.proctrl.impl.ProcessControllerImpl)5 ProcessCtrlEventConsumer (io.seata.saga.proctrl.eventing.impl.ProcessCtrlEventConsumer)3 ProcessCtrlEventPublisher (io.seata.saga.proctrl.eventing.impl.ProcessCtrlEventPublisher)3 AsyncEventBus (io.seata.saga.proctrl.eventing.impl.AsyncEventBus)2 DirectEventBus (io.seata.saga.proctrl.eventing.impl.DirectEventBus)2 DefaultRouterHandler (io.seata.saga.proctrl.handler.DefaultRouterHandler)2 ProcessHandler (io.seata.saga.proctrl.handler.ProcessHandler)2 RouterHandler (io.seata.saga.proctrl.handler.RouterHandler)2 CustomizeBusinessProcessor (io.seata.saga.proctrl.process.impl.CustomizeBusinessProcessor)2 HashMap (java.util.HashMap)2 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 StateMachineProcessHandler (io.seata.saga.engine.pcext.StateMachineProcessHandler)1 StateMachineProcessRouter (io.seata.saga.engine.pcext.StateMachineProcessRouter)1