Search in sources :

Example 1 with SplunkResultProcessor

use of org.apache.camel.component.splunk.support.SplunkResultProcessor in project camel by apache.

the class SplunkConsumer method poll.

@Override
protected int poll() throws Exception {
    try {
        if (endpoint.getConfiguration().isStreaming()) {
            dataReader.read(new SplunkResultProcessor() {

                @Override
                public void process(SplunkEvent splunkEvent) {
                    final Exchange exchange = getEndpoint().createExchange();
                    Message message = exchange.getIn();
                    message.setBody(splunkEvent);
                    try {
                        LOG.trace("Processing exchange [{}]...", exchange);
                        getAsyncProcessor().process(exchange, new AsyncCallback() {

                            @Override
                            public void done(boolean doneSync) {
                                LOG.trace("Done processing exchange [{}]...", exchange);
                            }
                        });
                    } catch (Exception e) {
                        exchange.setException(e);
                    }
                    if (exchange.getException() != null) {
                        getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
                    }
                }
            });
            // Return 0: no exchanges returned by poll, as exchanges have been returned asynchronously
            return 0;
        } else {
            List<SplunkEvent> events = dataReader.read();
            Queue<Exchange> exchanges = createExchanges(events);
            return processBatch(CastUtils.cast(exchanges));
        }
    } catch (Exception e) {
        endpoint.reset(e);
        getExceptionHandler().handleException(e);
        return 0;
    }
}
Also used : SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) Exchange(org.apache.camel.Exchange) SplunkResultProcessor(org.apache.camel.component.splunk.support.SplunkResultProcessor) Message(org.apache.camel.Message) AsyncCallback(org.apache.camel.AsyncCallback)

Aggregations

AsyncCallback (org.apache.camel.AsyncCallback)1 Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1 SplunkEvent (org.apache.camel.component.splunk.event.SplunkEvent)1 SplunkResultProcessor (org.apache.camel.component.splunk.support.SplunkResultProcessor)1