| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.processor.aggregate; |
| 18 |
|
|
| 19 |
|
import java.util.AbstractCollection; |
| 20 |
|
import java.util.Iterator; |
| 21 |
|
import java.util.LinkedHashMap; |
| 22 |
|
import java.util.Map; |
| 23 |
|
|
| 24 |
|
import org.apache.camel.Exchange; |
| 25 |
|
import org.apache.camel.Expression; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
300 |
public class AggregationCollection extends AbstractCollection<Exchange> { |
| 35 |
|
private final Expression<Exchange> correlationExpression; |
| 36 |
|
private final AggregationStrategy aggregationStrategy; |
| 37 |
3 |
private Map<Object, Exchange> map = new LinkedHashMap<Object, Exchange>(); |
| 38 |
|
|
| 39 |
|
public AggregationCollection(Expression<Exchange> correlationExpression, |
| 40 |
3 |
AggregationStrategy aggregationStrategy) { |
| 41 |
3 |
this.correlationExpression = correlationExpression; |
| 42 |
3 |
this.aggregationStrategy = aggregationStrategy; |
| 43 |
3 |
} |
| 44 |
|
|
| 45 |
|
@Override |
| 46 |
|
public boolean add(Exchange exchange) { |
| 47 |
300 |
Object correlationKey = correlationExpression.evaluate(exchange); |
| 48 |
300 |
Exchange oldExchange = map.get(correlationKey); |
| 49 |
300 |
Exchange newExchange = exchange; |
| 50 |
300 |
if (oldExchange != null) { |
| 51 |
297 |
newExchange = aggregationStrategy.aggregate(oldExchange, newExchange); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
300 |
if (newExchange != oldExchange) { |
| 56 |
300 |
map.put(correlationKey, newExchange); |
| 57 |
|
} |
| 58 |
300 |
return true; |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
public Iterator<Exchange> iterator() { |
| 62 |
9 |
return map.values().iterator(); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
public int size() { |
| 66 |
0 |
return map.size(); |
| 67 |
|
} |
| 68 |
|
} |