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