Search in sources :

Example 1 with EventLoggerEventHandler

use of org.activiti.engine.impl.event.logger.handler.EventLoggerEventHandler in project Activiti by Activiti.

the class EventLogger method onEvent.

@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) {
                // Default
                eventFlusher = new DatabaseEventFlusher();
            }
            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(EventLogger.this);
                        }
                    }
                }
            });
        }
        eventFlusher.addEventHandler(eventHandler);
    }
}
Also used : EventLoggerEventHandler(org.activiti.engine.impl.event.logger.handler.EventLoggerEventHandler) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandContextCloseListener(org.activiti.engine.impl.interceptor.CommandContextCloseListener)

Example 2 with EventLoggerEventHandler

use of org.activiti.engine.impl.event.logger.handler.EventLoggerEventHandler in project Activiti by Activiti.

the class EventLogger method instantiateEventHandler.

protected EventLoggerEventHandler instantiateEventHandler(ActivitiEvent event, Class<? extends EventLoggerEventHandler> eventHandlerClass) {
    try {
        EventLoggerEventHandler eventHandler = eventHandlerClass.newInstance();
        eventHandler.setTimeStamp(clock.getCurrentTime());
        eventHandler.setEvent(event);
        eventHandler.setObjectMapper(objectMapper);
        return eventHandler;
    } catch (Exception e) {
        logger.warn("Could not instantiate " + eventHandlerClass + ", this is most likely a programmatic error");
    }
    return null;
}
Also used : EventLoggerEventHandler(org.activiti.engine.impl.event.logger.handler.EventLoggerEventHandler)

Aggregations

EventLoggerEventHandler (org.activiti.engine.impl.event.logger.handler.EventLoggerEventHandler)2 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 CommandContextCloseListener (org.activiti.engine.impl.interceptor.CommandContextCloseListener)1