扩展activiti event logger的handler

重写initializeDefaultHandlers方法

public class EsEventLogger extends EventLogger{

    private static final Logger logger = LoggerFactory.getLogger(EsEventLogger.class);

    public static final String EVENT_FLUSHER_KEY = "eventFlusher";

    public EsEventLogger(Clock clock, ObjectMapper objectMapper) {
        super(clock, objectMapper);
    }

    @Override
    public void onEvent(ActivitiEvent event) {
        EventLoggerEventHandler eventHandler = getEventHandler(event);
        if (eventHandler != null) {

            // Events are flushed when command context is closed
            CommandContext currentCommandContext = Context.getCommandContext();
            EventFlusher eventFlusher = (EventFlusher) currentCommandContext.getAttribute(EVENT_FLUSHER_KEY);

            if (eventHandler != null && eventFlusher == null) {

                eventFlusher = createEventFlusher();
                if (eventFlusher == null) {
                    eventFlusher = new EsEventFlusher(); // change to es event logger
                }
                currentCommandContext.addAttribute(EVENT_FLUSHER_KEY, eventFlusher);

                currentCommandContext.addCloseListener(eventFlusher);
                currentCommandContext
                        .addCloseListener(new CommandContextCloseListener() {

                            @Override
                            public void closing(CommandContext commandContext) {
                            }

                            @Override
                            public void closed(CommandContext commandContext) {
                                // For those who are interested: we can now broadcast the events were added
                                if (listeners != null) {
                                    for (EventLoggerListener listener : listeners) {
                                        listener.eventsAdded(EsEventLogger.this);
                                    }
                                }
                            }

                        });
            }

            eventFlusher.addEventHandler(eventHandler);
        }
    }

    /**
     * 重写父类
     * 更改事件记录的类型
     * 以下是activiti默认自带的event log事件类型处理
     * activiti-engine-5.20.0-sources.jar!/org/activiti/engine/impl/event/logger/handler/*EventHandler.java
     * @return
     */
    @Override
    protected void initializeDefaultHandlers() {
        super.initializeDefaultHandlers();
        addEventHandler(ActivitiEventType.ENTITY_UPDATED, TaskUpdatedEventHandler.class);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值