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;
}
}
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
}
});
}
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
}
});
}
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
}
});
}
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
}
});
}
}
Aggregations