Coverage Report - org.apache.camel.processor.RecipientList
 
Classes in this File Line Coverage Branch Coverage Complexity
RecipientList
100% 
100% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.processor;
 18  
 
 19  
 import java.util.Iterator;
 20  
 
 21  
 import org.apache.camel.Endpoint;
 22  
 import org.apache.camel.Exchange;
 23  
 import org.apache.camel.Expression;
 24  
 import org.apache.camel.Processor;
 25  
 import org.apache.camel.converter.ObjectConverter;
 26  
 import org.apache.camel.impl.ServiceSupport;
 27  
 import org.apache.camel.util.ExchangeHelper;
 28  
 import org.apache.camel.util.ProducerCache;
 29  
 
 30  
 import static org.apache.camel.util.ObjectHelper.notNull;
 31  
 
 32  
 /**
 33  
  * Implements a dynamic <a
 34  
  * href="http://activemq.apache.org/camel/recipient-list.html">Recipient List</a>
 35  
  * pattern where the list of actual endpoints to send a message exchange to are
 36  
  * dependent on some dynamic expression.
 37  
  * 
 38  
  * @version $Revision: 563607 $
 39  
  */
 40  
 public class RecipientList extends ServiceSupport implements Processor {
 41  
     private final Expression<Exchange> expression;
 42  255
     private ProducerCache<Exchange> producerCache = new ProducerCache<Exchange>();
 43  
 
 44  255
     public RecipientList(Expression<Exchange> expression) {
 45  255
         notNull(expression, "expression");
 46  255
         this.expression = expression;
 47  255
     }
 48  
 
 49  
     @Override
 50  
     public String toString() {
 51  303
         return "RecipientList[" + expression + "]";
 52  
     }
 53  
 
 54  
     public void process(Exchange exchange) throws Exception {
 55  3
         Object receipientList = expression.evaluate(exchange);
 56  3
         Iterator iter = ObjectConverter.iterator(receipientList);
 57  12
         while (iter.hasNext()) {
 58  9
             Object recipient = iter.next();
 59  9
             Endpoint<Exchange> endpoint = resolveEndpoint(exchange, recipient);
 60  9
             producerCache.getProducer(endpoint).process(exchange);
 61  9
         }
 62  3
     }
 63  
 
 64  
     protected Endpoint<Exchange> resolveEndpoint(Exchange exchange, Object recipient) {
 65  9
         return ExchangeHelper.resolveEndpoint(exchange, recipient);
 66  
     }
 67  
 
 68  
     protected void doStop() throws Exception {
 69  213
         producerCache.stop();
 70  213
     }
 71  
 
 72  
     protected void doStart() throws Exception {
 73  216
     }
 74  
 }