Iterable<ProcessorExchangePair> pairs = createProcessorExchangePairs(exchange);
// Parallel Processing the producer
if (isParallelProcessing) {
List<Exchange> exchanges = new LinkedList<Exchange>();
final CountingLatch completedExchanges = new CountingLatch();
int i = 0;
for (ProcessorExchangePair pair : pairs) {
Processor producer = pair.getProcessor();
final Exchange subExchange = pair.getExchange();
updateNewExchange(subExchange, i, pairs);
exchanges.add(subExchange);
completedExchanges.increment();
ProcessCall call = new ProcessCall(subExchange, producer, new AsyncCallback() {
public void done(boolean doneSynchronously) {
if (streaming && aggregationStrategy != null) {
doAggregate(result, subExchange);
}
completedExchanges.decrement();
}
});
executor.execute(call);
i++;
}
completedExchanges.await();
if (!streaming && aggregationStrategy != null) {
for (Exchange resultExchange : exchanges) {
doAggregate(result, resultExchange);
}
}