Search in sources :

Example 61 with AsyncCallback

use of org.apache.camel.AsyncCallback 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)

Example 62 with AsyncCallback

use of org.apache.camel.AsyncCallback in project camel by apache.

the class CamelEventHandler method doEventReceived.

/**
     * Callback executed to propagate event from Guava listener to Camel route.
     *
     * @param event the event received by Guava EventBus.
     */
public void doEventReceived(Object event) {
    log.trace("Received event: {}");
    final Exchange exchange = eventBusEndpoint.createExchange(event);
    log.debug("Processing event: {}", event);
    // use async processor to support async routing engine
    processor.process(exchange, new AsyncCallback() {

        @Override
        public void done(boolean doneSync) {
        // noop
        }
    });
}
Also used : Exchange(org.apache.camel.Exchange) AsyncCallback(org.apache.camel.AsyncCallback)

Example 63 with AsyncCallback

use of org.apache.camel.AsyncCallback in project camel by apache.

the class IgniteCacheContinuousQueryConsumer method fireGroupedExchange.

private void fireGroupedExchange(Iterable<CacheEntryEvent<? extends Object, ? extends Object>> events) {
    Exchange exchange = createExchange(events);
    getAsyncProcessor().process(exchange, new AsyncCallback() {

        @Override
        public void done(boolean doneSync) {
        // do nothing
        }
    });
}
Also used : Exchange(org.apache.camel.Exchange) AsyncCallback(org.apache.camel.AsyncCallback)

Example 64 with AsyncCallback

use of org.apache.camel.AsyncCallback in project camel by apache.

the class IgniteCacheContinuousQueryConsumer method fireSingleExchange.

private void fireSingleExchange(CacheEntryEvent<? extends Object, ? extends Object> entry) {
    Exchange exchange = createExchange(entry.getValue());
    exchange.getIn().setHeader(IgniteConstants.IGNITE_CACHE_EVENT_TYPE, entry.getEventType());
    exchange.getIn().setHeader(IgniteConstants.IGNITE_CACHE_OLD_VALUE, entry.getOldValue());
    exchange.getIn().setHeader(IgniteConstants.IGNITE_CACHE_KEY, entry.getKey());
    getAsyncProcessor().process(exchange, new AsyncCallback() {

        @Override
        public void done(boolean doneSync) {
        // do nothing
        }
    });
}
Also used : Exchange(org.apache.camel.Exchange) AsyncCallback(org.apache.camel.AsyncCallback)

Example 65 with AsyncCallback

use of org.apache.camel.AsyncCallback in project camel by apache.

the class IgniteCacheContinuousQueryConsumer method maybeFireExistingQueryResults.

private void maybeFireExistingQueryResults() {
    if (!endpoint.isFireExistingQueryResults()) {
        LOG.info(String.format("Skipping existing cache results for cache name = %s.", endpoint.getCacheName()));
        return;
    }
    LOG.info(String.format("Processing existing cache results for cache name = %s.", endpoint.getCacheName()));
    for (Entry<Object, Object> entry : cursor) {
        Exchange exchange = createExchange(entry.getValue());
        exchange.getIn().setHeader(IgniteConstants.IGNITE_CACHE_KEY, entry.getKey());
        getAsyncProcessor().process(createExchange(entry), new AsyncCallback() {

            @Override
            public void done(boolean doneSync) {
            // do nothing
            }
        });
    }
}
Also used : Exchange(org.apache.camel.Exchange) AsyncCallback(org.apache.camel.AsyncCallback)

Aggregations

AsyncCallback (org.apache.camel.AsyncCallback)67 Exchange (org.apache.camel.Exchange)47 AsyncProcessor (org.apache.camel.AsyncProcessor)12 CamelExchangeException (org.apache.camel.CamelExchangeException)8 Message (org.apache.camel.Message)5 Processor (org.apache.camel.Processor)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 Endpoint (org.apache.camel.Endpoint)4 Producer (org.apache.camel.Producer)4 Synchronization (org.apache.camel.spi.Synchronization)4 StopWatch (org.apache.camel.util.StopWatch)4 InetSocketAddress (java.net.InetSocketAddress)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ExchangePattern (org.apache.camel.ExchangePattern)3 ChannelHandler (io.netty.channel.ChannelHandler)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ConnectException (java.net.ConnectException)2