Flowable源码注释(五十七)事务监听器(上)

本文深入探讨Flowable流程引擎的事务监听器,包括TransactionListener、ExecuteExecutionListenerTransactionListener、ExecuteEventListenerTransactionListener和ExecuteTaskListenerTransactionListener。通过对源码的注释和分析,了解它们在流程执行中的作用。
摘要由CSDN通过智能技术生成

Flowable源码地址:https://github.com/flowable/flowable-engine

Flowable-6.7.2 源码注释地址:https://github.com/solojin/flowable-6.7.2-annotated

事务监听器,包路径:org.flowable.common.engine.impl.cfg

TransactionListener 事务监听器

/**
 * 事务监听器
 *
 * @author Tom Baeyens
 */
public interface TransactionListener {

    void execute(CommandContext commandContext);
}

ExecuteExecutionListenerTransactionListener 执行监听器事务监听器

/**
 * 执行监听器事务监听器
 * 调用执行监听器{@link ExecutionListener}的事务监听器{@link TransactionListener}。
 * 
 * @author Joram Barrez
 */
public class ExecuteExecutionListenerTransactionListener implements TransactionListener {

    protected TransactionDependentExecutionListener listener;
    protected TransactionDependentExecutionListenerExecutionScope scope;
    protected CommandExecutor commandExecutor;

    public ExecuteExecutionListenerTransactionListener(TransactionDependentExecutionListener listener,
            TransactionDependentExecutionListenerExecutionScope scope, CommandExecutor commandExecutor) {
        this.listener = listener;
        this.scope = scope;
        this.commandExecutor = commandExecutor;
    }

    @Override
    public void execute(CommandContext commandContext) {
        CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
        commandExecutor.execute(commandConfig, new Command<Void>() {
            @Override
            public Void execute(CommandContext commandContext) {
                listener.notify(scope.getProcessInstanceId(), scope.getExecutionId(), scope.getFlowElement(),
                        scope.getExecutionVariables(), scope.getCustomPropertiesMap());
                return null;
            }
        });
    }

}

ExecuteEventListenerTransactionListener 执行事件监听器事务监听器

/**
 * 执行事件监听器事务监听器
 */
public class ExecuteEventListenerTransactionListener implements TransactionListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(ExecuteEventListenerTransactionListener.class);
    
    protected FlowableEventListener listener;
    protected FlowableEvent flowableEvent;

    public ExecuteEventListenerTransactionListener(FlowableEventListener listener, FlowableEvent flowableEvent) {
        this.listener = listener;
        this.flowableEvent = flowableEvent;
    }

    @Override
    public void execute(CommandContext commandContext) {
        try {
            listener.onEvent(flowableEvent);
        } catch (Throwable t) {
            if (listener.isFailOnException()) {
                throw t;
            } else {
                // Ignore the exception and continue notifying remaining listeners. The listener
                // explicitly states that the exception should not bubble up
                LOGGER.warn("Exception while executing event-listener, which was ignored", t);
            }
        }
    }
}

ExecuteTaskListenerTransactionListener 执行任务监听器事务监听器

/**
 * 执行任务监听器事务监听器
 * 调用执行监听器{@link ExecutionListener}的事务监听器{@link TransactionListener}。
 *
 * @author Joram Barrez
 */
public class ExecuteTaskListenerTransactionListener implements TransactionListener {

    protected TransactionDependentTaskListener listener;
    protected TransactionDependentTaskListenerExecutionScope scope;
    protected CommandExecutor commandExecutor;

    public ExecuteTaskListenerTransactionListener(TransactionDependentTaskListener listener,
            TransactionDependentTaskListenerExecutionScope scope, CommandExecutor commandExecutor) {
        this.listener = listener;
        this.scope = scope;
        this.commandExecutor = commandExecutor;
    }

    @Override
    public void execute(CommandContext commandContext) {
        CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
        commandExecutor.execute(commandConfig, new Command<Void>() {
            @Override
            public Void execute(CommandContext commandContext) {
                listener.notify(scope.getProcessInstanceId(), scope.getExecutionId(), scope.getTask(),
                        scope.getExecutionVariables(), scope.getCustomPropertiesMap());
                return null;
            }
        });
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值