Search in sources :

Example 1 with ProcessRouter

use of io.seata.saga.proctrl.ProcessRouter in project seata by seata.

the class DefaultRouterHandler method route.

@Override
public void route(ProcessContext context) throws FrameworkException {
    try {
        ProcessType processType = matchProcessType(context);
        if (processType == null) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Process type not found, context= {}", context);
            }
            throw new FrameworkException(FrameworkErrorCode.ProcessTypeNotFound);
        }
        ProcessRouter processRouter = processRouters.get(processType.getCode());
        if (processRouter == null) {
            LOGGER.error("Cannot find process router by type {}, context = {}", processType.getCode(), context);
            throw new FrameworkException(FrameworkErrorCode.ProcessRouterNotFound);
        }
        Instruction instruction = processRouter.route(context);
        if (instruction == null) {
            LOGGER.info("route instruction is null, process end");
        } else {
            context.setInstruction(instruction);
            eventPublisher.publish(context);
        }
    } catch (FrameworkException e) {
        throw e;
    } catch (Exception ex) {
        throw new FrameworkException(ex, ex.getMessage(), FrameworkErrorCode.UnknownAppError);
    }
}
Also used : ProcessType(io.seata.saga.proctrl.ProcessType) FrameworkException(io.seata.common.exception.FrameworkException) ProcessRouter(io.seata.saga.proctrl.ProcessRouter) Instruction(io.seata.saga.proctrl.Instruction) FrameworkException(io.seata.common.exception.FrameworkException)

Example 2 with ProcessRouter

use of io.seata.saga.proctrl.ProcessRouter 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)

Aggregations

ProcessRouter (io.seata.saga.proctrl.ProcessRouter)2 FrameworkException (io.seata.common.exception.FrameworkException)1 StateMachineProcessHandler (io.seata.saga.engine.pcext.StateMachineProcessHandler)1 StateMachineProcessRouter (io.seata.saga.engine.pcext.StateMachineProcessRouter)1 Instruction (io.seata.saga.proctrl.Instruction)1 ProcessType (io.seata.saga.proctrl.ProcessType)1 DefaultRouterHandler (io.seata.saga.proctrl.handler.DefaultRouterHandler)1 ProcessHandler (io.seata.saga.proctrl.handler.ProcessHandler)1 RouterHandler (io.seata.saga.proctrl.handler.RouterHandler)1 ProcessControllerImpl (io.seata.saga.proctrl.impl.ProcessControllerImpl)1 CustomizeBusinessProcessor (io.seata.saga.proctrl.process.impl.CustomizeBusinessProcessor)1 HashMap (java.util.HashMap)1