// we do not run in parallel mode, but use a synchronous executor, so we run in current thread
threadPool = new SynchronousExecutorService();
shutdownThreadPool = true;
}
AggregateProcessor answer = new AggregateProcessor(routeContext.getCamelContext(), processor,
correlation, strategy, threadPool, shutdownThreadPool);
AggregationRepository repository = createAggregationRepository(routeContext);
if (repository != null) {
answer.setAggregationRepository(repository);
}
// this EIP supports using a shared timeout checker thread pool or fallback to create a new thread pool
boolean shutdownTimeoutThreadPool = false;
ScheduledExecutorService timeoutThreadPool = timeoutCheckerExecutorService;
if (timeoutThreadPool == null && timeoutCheckerExecutorServiceRef != null) {
// lookup existing thread pool
timeoutThreadPool = routeContext.getCamelContext().getRegistry().lookup(timeoutCheckerExecutorServiceRef, ScheduledExecutorService.class);
if (timeoutThreadPool == null) {
// then create a thread pool assuming the ref is a thread pool profile id
timeoutThreadPool = routeContext.getCamelContext().getExecutorServiceManager().newScheduledThreadPool(this,
AggregateProcessor.AGGREGATE_TIMEOUT_CHECKER, timeoutCheckerExecutorServiceRef);
if (timeoutThreadPool == null) {
throw new IllegalArgumentException("ExecutorServiceRef " + timeoutCheckerExecutorServiceRef + " not found in registry or as a thread pool profile.");
}
shutdownTimeoutThreadPool = true;
}
}
answer.setTimeoutCheckerExecutorService(timeoutThreadPool);
answer.setShutdownTimeoutCheckerExecutorService(shutdownTimeoutThreadPool);
// set other options
answer.setParallelProcessing(isParallelProcessing());
if (getCompletionPredicate() != null) {
Predicate predicate = getCompletionPredicate().createPredicate(routeContext);
answer.setCompletionPredicate(predicate);
}
if (getCompletionTimeoutExpression() != null) {
Expression expression = getCompletionTimeoutExpression().createExpression(routeContext);
answer.setCompletionTimeoutExpression(expression);
}
if (getCompletionTimeout() != null) {
answer.setCompletionTimeout(getCompletionTimeout());
}
if (getCompletionInterval() != null) {
answer.setCompletionInterval(getCompletionInterval());
}
if (getCompletionSizeExpression() != null) {
Expression expression = getCompletionSizeExpression().createExpression(routeContext);
answer.setCompletionSizeExpression(expression);
}
if (getCompletionSize() != null) {
answer.setCompletionSize(getCompletionSize());
}
if (getCompletionFromBatchConsumer() != null) {
answer.setCompletionFromBatchConsumer(isCompletionFromBatchConsumer());
}
if (getEagerCheckCompletion() != null) {
answer.setEagerCheckCompletion(isEagerCheckCompletion());
}
if (getIgnoreInvalidCorrelationKeys() != null) {
answer.setIgnoreInvalidCorrelationKeys(isIgnoreInvalidCorrelationKeys());
}
if (getCloseCorrelationKeyOnCompletion() != null) {
answer.setCloseCorrelationKeyOnCompletion(getCloseCorrelationKeyOnCompletion());
}
if (getDiscardOnCompletionTimeout() != null) {
answer.setDiscardOnCompletionTimeout(isDiscardOnCompletionTimeout());
}
if (getForceCompletionOnStop() != null) {
answer.setForceCompletionOnStop(getForceCompletionOnStop());
}
return answer;
}