Search in sources :

Example 1 with OutgoingResponseEvent

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

the class Service method logResponse.

private void logResponse(HttpServletRequest request, HttpServletResponse response, long count, Stopwatch stopwatch) {
    long elapsed = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
    this.serviceEventBus.submit(new OutgoingResponseEvent(request, response, count, elapsed));
    LOGGER.debug("Outgoing response for request No. {} is committed = {} (took {} ms)", count, response.isCommitted(), elapsed);
}
Also used : OutgoingResponseEvent(org.n52.iceland.event.events.OutgoingResponseEvent)

Example 2 with OutgoingResponseEvent

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

the class AbstractStatisticsServiceEventListener method addEventToResolver.

private void addEventToResolver(BatchResolver resolver, Event event) {
    StatisticsServiceEventResolver<?> evtResolver = null;
    if (event instanceof ExceptionEvent) {
        ExceptionEventResolver sosExceptionEventResolver = resolverFactory.getExceptionEventResolver();
        sosExceptionEventResolver.setEvent((ExceptionEvent) event);
        evtResolver = sosExceptionEventResolver;
    } else if (event instanceof OutgoingResponseEvent) {
        OutgoingResponseEventResolver outgoingResponseEventResolver = resolverFactory.getOutgoingResponseEventResolver();
        outgoingResponseEventResolver.setEvent((OutgoingResponseEvent) event);
        evtResolver = outgoingResponseEventResolver;
    } else if (event instanceof CountingOutputStreamEvent) {
        CountingOutputStreamEventResolver countingOutputstreamEventResolver = resolverFactory.getCountingOutputstreamEventResolver();
        countingOutputstreamEventResolver.setEvent((CountingOutputStreamEvent) event);
        evtResolver = countingOutputstreamEventResolver;
    } else {
        evtResolver = findResolver(event);
    }
    // Default fallback event resolver
    if (evtResolver == null) {
        DefaultServiceEventResolver defaultServiceEventResolver = resolverFactory.getDefaultServiceEventResolver();
        defaultServiceEventResolver.setEvent(event);
        evtResolver = defaultServiceEventResolver;
    }
    resolver.addEventResolver(evtResolver);
}
Also used : ExceptionEvent(org.n52.iceland.event.events.ExceptionEvent) CountingOutputStreamEventResolver(org.n52.iceland.statistics.impl.resolvers.CountingOutputStreamEventResolver) CountingOutputStreamEvent(org.n52.iceland.event.events.CountingOutputStreamEvent) DefaultServiceEventResolver(org.n52.iceland.statistics.impl.resolvers.DefaultServiceEventResolver) OutgoingResponseEventResolver(org.n52.iceland.statistics.impl.resolvers.OutgoingResponseEventResolver) ExceptionEventResolver(org.n52.iceland.statistics.impl.resolvers.ExceptionEventResolver) OutgoingResponseEvent(org.n52.iceland.event.events.OutgoingResponseEvent)

Example 3 with OutgoingResponseEvent

use of org.n52.iceland.event.events.OutgoingResponseEvent 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

OutgoingResponseEvent (org.n52.iceland.event.events.OutgoingResponseEvent)3 AbstractFlowEvent (org.n52.iceland.event.events.AbstractFlowEvent)1 CountingOutputStreamEvent (org.n52.iceland.event.events.CountingOutputStreamEvent)1 ExceptionEvent (org.n52.iceland.event.events.ExceptionEvent)1 RequestEvent (org.n52.iceland.event.events.RequestEvent)1 CountingOutputStreamEventResolver (org.n52.iceland.statistics.impl.resolvers.CountingOutputStreamEventResolver)1 DefaultServiceEventResolver (org.n52.iceland.statistics.impl.resolvers.DefaultServiceEventResolver)1 ExceptionEventResolver (org.n52.iceland.statistics.impl.resolvers.ExceptionEventResolver)1 OutgoingResponseEventResolver (org.n52.iceland.statistics.impl.resolvers.OutgoingResponseEventResolver)1