Coverage Report - org.apache.camel.processor.SendProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
SendProcessor
77% 
75% 
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 org.apache.camel.Endpoint;
 20  
 import org.apache.camel.Exchange;
 21  
 import org.apache.camel.Processor;
 22  
 import org.apache.camel.Producer;
 23  
 import org.apache.camel.Service;
 24  
 import org.apache.camel.impl.ServiceSupport;
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 
 28  
 /**
 29  
  * @version $Revision: 563607 $
 30  
  */
 31  
 public class SendProcessor extends ServiceSupport implements Processor, Service {
 32  3
     private static final transient Log LOG = LogFactory.getLog(SendProcessor.class);
 33  
     private Endpoint destination;
 34  
     private Producer producer;
 35  
 
 36  315
     public SendProcessor(Endpoint destination) {
 37  315
         if (destination == null) {
 38  0
             throw new IllegalArgumentException("Endpoint cannot be null!");
 39  
         }
 40  315
         this.destination = destination;
 41  315
     }
 42  
 
 43  
     protected void doStop() throws Exception {
 44  267
         if (producer != null) {
 45  
             try {
 46  267
                 producer.stop();
 47  
             } finally {
 48  267
                 producer = null;
 49  267
             }
 50  
         }
 51  267
     }
 52  
 
 53  
     protected void doStart() throws Exception {
 54  276
         this.producer = destination.createProducer();
 55  276
     }
 56  
 
 57  
     public void process(Exchange exchange) throws Exception {
 58  327
         if (producer == null) {
 59  0
             if (isStopped()) {
 60  0
                 LOG.warn("Ignoring exchange sent after processor is stopped: " + exchange);
 61  0
             } else {
 62  0
                 throw new IllegalStateException("No producer, this processor has not been started!");
 63  
             }
 64  
         } else {
 65  327
             producer.process(exchange);
 66  
         }
 67  327
     }
 68  
 
 69  
     public Endpoint getDestination() {
 70  27
         return destination;
 71  
     }
 72  
 
 73  
     @Override
 74  
     public String toString() {
 75  366
         return "sendTo(" + destination + ")";
 76  
     }
 77  
 }