Flowable源码注释(十九)命令上下文关闭监听器

本文深入解析了Flowable源码中的CommandContextCloseListener接口,介绍了其在事件日志中的关键作用,包括closing、afterSessionsFlush、closed和closeFailure方法的使用场景。通过理解这个接口,开发者可以更好地掌握事务管理和会话刷新的流程控制。

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

讲到数据库事件日志刷新器,就要先看它实现的接口。

对于事件日志来说,实现CommandContextCloseListener 接口主要关注两个方法,closing(命令上下文正在关闭)和closed(命令上下文已经关闭)。

包路径:org.flowable.common.engine.impl.interceptor

CommandContextCloseListener 命令上下文关闭监听器

package org.flowable.common.engine.impl.interceptor;

import org.flowable.common.engine.impl.cfg.TransactionContext;

/**
 * 一个监听器,可用于通知命令上下文{@link CommandContext}的生命周期事件。
 * 
 * @author Joram Barrez
 */
public interface CommandContextCloseListener {

    /**
     * 在关闭命令上下文{@link CommandContext}但未执行“关闭逻辑”时调用。
     * 
     * 此时,事务上下文{@link TransactionContext}(如果适用)尚未提交/回滚,会话{@link Session}实例均未刷新。
     * 
     * 如果发生异常且未在此方法中捕获:-将不刷新会话{@link Session}实例,事务上下文{@link TransactionContext}将回滚(如果适用)
     */
    void closing(CommandContext commandContext);

    /**
     * 在成功刷新会话{@link Session}时调用。当刷新会话期间发生异常时,将不会调用此方法。
     * 
     * 如果发生异常且未在此方法中捕获:-将不刷新会话{@link Session}实例,事务上下文{@link TransactionContext}将回滚(如果适用)
     */
    void afterSessionsFlush(CommandContext commandContext);

    /**
     * 当命令上下文{@link CommandContext}成功关闭时调用。
     * 
     * 此时,事务上下文{@link TransactionContext}(如果适用)已成功提交,没有发生回滚。所有会话{@link Session}实例都已关闭。
     * 
     * 请注意,在此处引发异常不会影响事务。命令上下文{@link CommandContext}将记录异常。
     */
    void closed(CommandContext commandContext);

    /**
     * 在命令上下文{@link CommandContext}由于发生异常而未成功关闭时调用。
     * 
     * 请注意,在此处引发异常不会影响事务。命令上下文{@link CommandContext}将记录异常。
     */
    void closeFailure(CommandContext commandContext);
    
    /**
     * 确定关闭监听器的执行顺序
     * 
     * @return 顺序最低者将首先执行
     */
    Integer order();
    
    /**
     * 确定此关闭监听器是否允许多次出现
     * 
     * @return 是否允许多次出现
     */
    boolean multipleAllowed();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值