Search in sources :

Example 1 with AbstractFlowEvent

use of org.n52.iceland.event.events.AbstractFlowEvent in project arctic-sea by 52North.

the class AbstractStatisticsServiceEventListener method handle.

@Override
public void handle(Event serviceEvent) {
    LOG.debug("Event received: {}", serviceEvent);
    if (!dataHandler.isLoggingEnabled()) {
        return;
    }
    try {
        if (serviceEvent instanceof AbstractFlowEvent) {
            List<AbstractFlowEvent> eventList;
            AbstractFlowEvent evt = (AbstractFlowEvent) serviceEvent;
            // empty the list on the first event of the given group id
            if (serviceEvent instanceof RequestEvent) {
                eventList = new ArrayList<>(EVENTS_ARR_SIZE);
                eventsCache.put(evt.getMessageGroupId(), eventList);
            }
            // fall back
            if (eventsCache.get(evt.getMessageGroupId()) == null) {
                eventList = new ArrayList<>(EVENTS_ARR_SIZE);
                eventsCache.put(evt.getMessageGroupId(), eventList);
            }
            eventsCache.get(evt.getMessageGroupId()).add(evt);
            // received last event process eventsResolvers on a new thread
            if (serviceEvent instanceof OutgoingResponseEvent) {
                BatchResolver resolvers = new BatchResolver(dataHandler);
                eventsCache.get(evt.getMessageGroupId()).stream().forEach(l -> addEventToResolver(resolvers, l));
                executorService.execute(resolvers);
            }
        } else {
            LOG.trace("Unssupported type of event: {}", serviceEvent.getClass());
            BatchResolver singleOp = new BatchResolver(dataHandler);
            addEventToResolver(singleOp, serviceEvent);
            executorService.execute(singleOp);
        }
    } catch (Throwable e) {
        LOG.error("Can't handle event for statistics logging: {}", serviceEvent, e);
    }
}
Also used : RequestEvent(org.n52.iceland.event.events.RequestEvent) AbstractFlowEvent(org.n52.iceland.event.events.AbstractFlowEvent) OutgoingResponseEvent(org.n52.iceland.event.events.OutgoingResponseEvent)

Aggregations

AbstractFlowEvent (org.n52.iceland.event.events.AbstractFlowEvent)1 OutgoingResponseEvent (org.n52.iceland.event.events.OutgoingResponseEvent)1 RequestEvent (org.n52.iceland.event.events.RequestEvent)1