Flowable源码注释(二十)数据库事件刷新器
2022/2/6 2:12:25
本文主要是介绍Flowable源码注释(二十)数据库事件刷新器,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Flowable源码地址:https://github.com/flowable/flowable-engine
包路径:org.flowable.engine.impl.event.logger
EventFlusher事件刷新器接口
继承CommandContextCloseListener接口,在CommandContextCloseListener接口定义功能的基础上增加了获取日志处理器、添加日志处理器的支持。
package org.flowable.engine.impl.event.logger; import java.util.List; import org.flowable.common.engine.impl.interceptor.CommandContextCloseListener; import org.flowable.engine.impl.event.logger.handler.EventLoggerEventHandler; public interface EventFlusher extends CommandContextCloseListener { List<EventLoggerEventHandler> getEventHandlers(); void setEventHandlers(List<EventLoggerEventHandler> eventHandlers); void addEventHandler(EventLoggerEventHandler databaseEventLoggerEventHandler); }
AbstractEventFlusher事件刷新器抽象类
对EventFlusher 接口中的部分方法进行实现。
package org.flowable.engine.impl.event.logger; import java.util.ArrayList; import java.util.List; import org.flowable.common.engine.impl.interceptor.CommandContext; import org.flowable.engine.impl.event.logger.handler.EventLoggerEventHandler; public abstract class AbstractEventFlusher implements EventFlusher { protected List<EventLoggerEventHandler> eventHandlers = new ArrayList<>(); @Override public void closed(CommandContext commandContext) { // 未关注已关闭方法 } @Override public List<EventLoggerEventHandler> getEventHandlers() { return eventHandlers; } @Override public void setEventHandlers(List<EventLoggerEventHandler> eventHandlers) { this.eventHandlers = eventHandlers; } @Override public void addEventHandler(EventLoggerEventHandler databaseEventLoggerEventHandler) { eventHandlers.add(databaseEventLoggerEventHandler); } }
DatabaseEventFlusher数据库事件刷新器
继承AbstractEventFlusher类,并对CommandContextCloseListener接口中定义的closing方法进行实现。
package org.flowable.engine.impl.event.logger; import org.flowable.common.engine.impl.interceptor.CommandContext; import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl; import org.flowable.engine.impl.event.logger.handler.EventLoggerEventHandler; import org.flowable.engine.impl.persistence.entity.EventLogEntryEntityManager; import org.flowable.engine.impl.util.CommandContextUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class DatabaseEventFlusher extends AbstractEventFlusher { private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseEventFlusher.class); @Override public void closing(CommandContext commandContext) { if (commandContext.getException() != null) { return; //未关注事件异常 } // 根据命令上下文工具类获取流程引擎配置类 ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); // 根据流程引擎配置类获取EventLogEntryEntityManager类对象,它负责 ACT_EVT_LOG 表的操作 EventLogEntryEntityManager eventLogEntryEntityManager = processEngineConfiguration.getEventLogEntryEntityManager(); // 遍历事件日志处理器对象 for (EventLoggerEventHandler eventHandler : eventHandlers) { try { // 通过事件日志实体对象管理器的插入方法,新增事件处理器根据命令上下文生成的事件日志。 eventLogEntryEntityManager.insert(eventHandler.generateEventLogEntry(commandContext), false); } catch (Exception e) { // 无法创建事件日志 LOGGER.warn("Could not create event log", e); } } } // 在成功刷新会话{@link Session}时调用。当刷新会话期间发生异常时,将不会调用此方法。 // 如果发生异常且未在此方法中捕获:-将不刷新会话{@link Session}实例,事务上下文{@link TransactionContext}将回滚(如果适用) @Override public void afterSessionsFlush(CommandContext commandContext) { } // 关闭失败时调用 @Override public void closeFailure(CommandContext commandContext) { } // 确定关闭监听器的执行顺序。数值最低者先执行 @Override public Integer order() { return 100; } // 确定此关闭监听器是否允许多次出现 @Override public boolean multipleAllowed() { return false; } }
这篇关于Flowable源码注释(二十)数据库事件刷新器的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)