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