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

被折叠的 条评论
为什么被折叠?



