Coverage Report - org.apache.camel.impl.EventDrivenConsumerRoute
 
Classes in this File Line Coverage Branch Coverage Complexity
EventDrivenConsumerRoute
88% 
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.impl;
 19  
 
 20  
 import org.apache.camel.Route;
 21  
 import org.apache.camel.Endpoint;
 22  
 import org.apache.camel.Processor;
 23  
 import org.apache.camel.Service;
 24  
 import org.apache.camel.Consumer;
 25  
 import org.apache.camel.Exchange;
 26  
 
 27  
 import java.util.List;
 28  
 
 29  
 /**
 30  
  * A {@link Route} which starts with an
 31  
  * <a href="http://activemq.apache.org/camel/event-driven-consumer.html">Event Driven Consumer</a>
 32  
  *
 33  
  * @version $Revision: 1.1 $
 34  
  */
 35  
 public class EventDrivenConsumerRoute<E extends Exchange> extends Route<E> {
 36  
     private Processor processor;
 37  
 
 38  
     public EventDrivenConsumerRoute(Endpoint endpoint, Processor processor) {
 39  53
         super(endpoint);
 40  53
         this.processor = processor;
 41  53
     }
 42  
 
 43  
     @Override
 44  
     public String toString() {
 45  55
         return "EventDrivenConsumerRoute[" + getEndpoint() + " -> " + processor + "]";
 46  
     }
 47  
 
 48  
     public Processor getProcessor() {
 49  53
         return processor;
 50  
     }
 51  
 
 52  
     public void setProcessor(Processor processor) {
 53  0
         this.processor = processor;
 54  0
     }
 55  
 
 56  
     /**
 57  
      * Factory method to lazily create the complete list of services required for this route
 58  
      * such as adding the processor or consumer
 59  
      */
 60  
     protected void addServices(List<Service> services) throws Exception {
 61  40
         Processor processor = getProcessor();
 62  40
         if (processor instanceof Service) {
 63  40
             Service service = (Service) processor;
 64  40
             services.add(service);
 65  
         }
 66  40
         Endpoint<E> endpoint = getEndpoint();
 67  40
         Consumer<E> consumer = endpoint.createConsumer(processor);
 68  40
         if (consumer != null) {
 69  40
             services.add(consumer);
 70  
         }
 71  40
     }
 72  
 }