public void process(Exchange exchange) throws Exception {
AsyncProcessorHelper.process(this, exchange);
}
public boolean process(Exchange exchange, AsyncCallback callback) {
final AtomicExchange result = new AtomicExchange();
final Iterable<ProcessorExchangePair> pairs;
// multicast uses fine grained error handling on the output processors
// so use try .. catch to cater for this
boolean exhaust = false;
try {
boolean sync = true;
pairs = createProcessorExchangePairs(exchange);
// after we have created the processors we consider the exchange as exhausted if an unhandled
// exception was thrown, (used in the catch block)
// if the processors is working in Streaming model, the exchange could not be processed at this point.
exhaust = !isStreaming();
if (isParallelProcessing()) {
// ensure an executor is set when running in parallel
ObjectHelper.notNull(executorService, "executorService", this);
doProcessParallel(exchange, result, pairs, isStreaming(), callback);
} else {
sync = doProcessSequential(exchange, result, pairs, callback);
}
if (!sync) {
// the remainder of the multicast will be completed async
// so we break out now, then the callback will be invoked which then continue routing from where we left here
return false;
}
} catch (Throwable e) {
exchange.setException(e);
// and do the done work
doDone(exchange, null, callback, true, exhaust);
return true;
}
// multicasting was processed successfully
// and do the done work
Exchange subExchange = result.get() != null ? result.get() : null;
doDone(exchange, subExchange, callback, true, exhaust);
return true;
}