Search in sources :

Example 1 with CommandContextCloseListener

use of org.activiti.engine.impl.interceptor.CommandContextCloseListener 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)

Aggregations

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