Coverage Report - org.apache.camel.processor.RecipientList
 
Classes in this File Line Coverage Branch Coverage Complexity
RecipientList
100% 
100% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 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  
  * Implements a dynamic <a href="http://activemq.apache.org/camel/recipient-list.html">Recipient List</a> pattern
 34  
  * where the list of actual endpoints to send a message exchange to are dependent on some dynamic expression.
 35  
  *
 36  
  * @version $Revision: 534145 $
 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  
 }