Coverage Report - org.apache.camel.component.seda.SedaConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
SedaConsumer
70% 
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.component.seda;
 18  
 
 19  
 import java.util.concurrent.TimeUnit;
 20  
 
 21  
 import org.apache.camel.AlreadyStoppedException;
 22  
 import org.apache.camel.Consumer;
 23  
 import org.apache.camel.Exchange;
 24  
 import org.apache.camel.Processor;
 25  
 import org.apache.camel.impl.ServiceSupport;
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 
 29  
 /**
 30  
  * @version $Revision: 563607 $
 31  
  */
 32  
 public class SedaConsumer<E extends Exchange> extends ServiceSupport implements Consumer<E>, Runnable {
 33  3
     private static final Log LOG = LogFactory.getLog(SedaConsumer.class);
 34  
 
 35  
     private SedaEndpoint<E> endpoint;
 36  
     private Processor processor;
 37  
     private Thread thread;
 38  
 
 39  24
     public SedaConsumer(SedaEndpoint<E> endpoint, Processor processor) {
 40  24
         this.endpoint = endpoint;
 41  24
         this.processor = processor;
 42  24
     }
 43  
 
 44  
     @Override
 45  
     public String toString() {
 46  0
         return "QueueConsumer: " + endpoint.getEndpointUri();
 47  
     }
 48  
 
 49  
     public void run() {
 50  78
         while (!isStopping()) {
 51  
             E exchange;
 52  
             try {
 53  54
                 exchange = endpoint.getQueue().poll(1000, TimeUnit.MILLISECONDS);
 54  0
             } catch (InterruptedException e) {
 55  0
                 break;
 56  54
             }
 57  54
             if (exchange != null && !isStopping()) {
 58  
                 try {
 59  30
                     processor.process(exchange);
 60  0
                 } catch (AlreadyStoppedException e) {
 61  0
                     LOG.debug("Ignoring failed message due to shutdown: " + e, e);
 62  0
                     break;
 63  0
                 } catch (Throwable e) {
 64  0
                     LOG.error(e);
 65  30
                 }
 66  
             }
 67  54
         }
 68  24
     }
 69  
 
 70  
     protected void doStart() throws Exception {
 71  24
         thread = new Thread(this, getThreadName(endpoint.getEndpointUri()));
 72  24
         thread.setDaemon(true);
 73  24
         thread.start();
 74  24
     }
 75  
 
 76  
     protected void doStop() throws Exception {
 77  24
         thread.join();
 78  24
     }
 79  
 
 80  
 }