Search in sources :

Example 1 with RequestEvent

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

Example 2 with RequestEvent

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

the class GenericRequestOperator method receiveRequest.

@Override
public OwsServiceResponse receiveRequest(final OwsServiceRequest abstractRequest) throws OwsExceptionReport {
    this.eventBus.submit(new RequestEvent(abstractRequest));
    if (requestType.isAssignableFrom(abstractRequest.getClass())) {
        Q request = requestType.cast(abstractRequest);
        checkForModifierAndProcess(request);
        this.validator.validate(request);
        A response = receive(request);
        this.eventBus.submit(new ResponseEvent(response));
        checkForModifierAndProcess(request, response);
        return response;
    } else {
        throw new OperationNotSupportedException(abstractRequest.getOperationName());
    }
}
Also used : OperationNotSupportedException(org.n52.shetland.ogc.ows.exception.OperationNotSupportedException) RequestEvent(org.n52.iceland.event.events.RequestEvent) ResponseEvent(org.n52.iceland.event.events.ResponseEvent)

Aggregations

RequestEvent (org.n52.iceland.event.events.RequestEvent)2 AbstractFlowEvent (org.n52.iceland.event.events.AbstractFlowEvent)1 OutgoingResponseEvent (org.n52.iceland.event.events.OutgoingResponseEvent)1 ResponseEvent (org.n52.iceland.event.events.ResponseEvent)1 OperationNotSupportedException (org.n52.shetland.ogc.ows.exception.OperationNotSupportedException)1