}
protected Aggregator createAggregator(RouteContext routeContext) throws Exception {
final Processor processor = routeContext.createProcessor(this);
final Aggregator aggregator;
if (getAggregationCollection() == null) {
setAggregationCollection(createAggregationCollection(routeContext));
}
if (aggregationCollection != null) {
// create the aggregator using the collection
// pre configure the collection if its expression and strategy is not set, then
// use the ones that is pre configured with this type
if (aggregationCollection.getCorrelationExpression() == null) {
aggregationCollection.setCorrelationExpression(getExpression());
}
if (aggregationCollection.getAggregationStrategy() == null) {
AggregationStrategy strategy = createAggregationStrategy(routeContext);
aggregationCollection.setAggregationStrategy(strategy);
}
aggregator = new Aggregator(processor, aggregationCollection);
} else {
// create the aggregator using a default collection
AggregationStrategy strategy = createAggregationStrategy(routeContext);
if (getExpression() == null) {
throw new IllegalArgumentException("You need to specify an expression or "
+ "aggregation collection for this aggregator: " + this);
}
Expression aggregateExpression = getExpression().createExpression(routeContext);
Predicate predicate = null;
if (getCompletionPredicate() != null) {
predicate = getCompletionPredicate().createPredicate(routeContext);
}
if (predicate != null) {
aggregator = new Aggregator(processor, aggregateExpression, strategy, predicate);
} else {
aggregator = new Aggregator(processor, aggregateExpression, strategy);
}
}
if (batchSize != null) {
aggregator.setBatchSize(batchSize);
}
if (batchTimeout != null) {
aggregator.setBatchTimeout(batchTimeout);
}
if (outBatchSize != null) {
aggregator.setOutBatchSize(outBatchSize);
}
if (groupExchanges != null) {
aggregator.setGroupExchanges(groupExchanges);
}
if (batchSizeFromConsumer != null) {
aggregator.setBatchConsumer(batchSizeFromConsumer);
}
return aggregator;
}