| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
package org.apache.camel.processor; |
| 19 |
|
|
| 20 |
|
import org.apache.camel.Endpoint; |
| 21 |
|
import org.apache.camel.Exchange; |
| 22 |
|
import org.apache.camel.Expression; |
| 23 |
|
import org.apache.camel.Processor; |
| 24 |
|
import org.apache.camel.converter.ObjectConverter; |
| 25 |
|
import org.apache.camel.impl.ServiceSupport; |
| 26 |
|
import org.apache.camel.util.ExchangeHelper; |
| 27 |
|
import static org.apache.camel.util.ObjectHelper.notNull; |
| 28 |
|
import org.apache.camel.util.ProducerCache; |
| 29 |
|
|
| 30 |
|
import java.util.Iterator; |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
public class RecipientList extends ServiceSupport implements Processor { |
| 39 |
|
private final Expression<Exchange> expression; |
| 40 |
84 |
private ProducerCache<Exchange> producerCache = new ProducerCache<Exchange>(); |
| 41 |
|
|
| 42 |
84 |
public RecipientList(Expression<Exchange> expression) { |
| 43 |
84 |
notNull(expression, "expression"); |
| 44 |
84 |
this.expression = expression; |
| 45 |
84 |
} |
| 46 |
|
|
| 47 |
|
@Override |
| 48 |
|
public String toString() { |
| 49 |
142 |
return "RecipientList[" + expression + "]"; |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
public void process(Exchange exchange) throws Exception { |
| 53 |
1 |
Object receipientList = expression.evaluate(exchange); |
| 54 |
1 |
Iterator iter = ObjectConverter.iterator(receipientList); |
| 55 |
4 |
while (iter.hasNext()) { |
| 56 |
3 |
Object recipient = iter.next(); |
| 57 |
3 |
Endpoint<Exchange> endpoint = resolveEndpoint(exchange, recipient); |
| 58 |
3 |
producerCache.getProducer(endpoint).process(exchange); |
| 59 |
3 |
} |
| 60 |
1 |
} |
| 61 |
|
|
| 62 |
|
protected Endpoint<Exchange> resolveEndpoint(Exchange exchange, Object recipient) { |
| 63 |
3 |
return ExchangeHelper.resolveEndpoint(exchange, recipient); |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
protected void doStop() throws Exception { |
| 67 |
60 |
producerCache.stop(); |
| 68 |
60 |
} |
| 69 |
|
|
| 70 |
|
protected void doStart() throws Exception { |
| 71 |
62 |
} |
| 72 |
|
} |