ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Flowable源码注释(二十)数据库事件刷新器

2022-02-05 23:04:57  阅读:212  来源: 互联网

标签:engine Flowable 数据库 flowable 源码 import org public impl


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;
    }
}

标签:engine,Flowable,数据库,flowable,源码,import,org,public,impl
来源: https://blog.csdn.net/JinYJ2014/article/details/122794376

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有