Coverage Report - org.apache.camel.component.jms.JmsPollingConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
JmsPollingConsumer
0% 
0% 
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.jms;
 18  
 
 19  
 import javax.jms.Message;
 20  
 
 21  
 import org.apache.camel.impl.PollingConsumerSupport;
 22  
 
 23  
 import org.springframework.jms.core.JmsOperations;
 24  
 import org.springframework.jms.core.JmsTemplate;
 25  
 import org.springframework.jms.core.JmsTemplate102;
 26  
 
 27  
 /**
 28  
  * @version $Revision: 1.1 $
 29  
  */
 30  0
 public class JmsPollingConsumer extends PollingConsumerSupport<JmsExchange> {
 31  
     private JmsOperations template;
 32  
 
 33  
     public JmsPollingConsumer(JmsEndpoint endpoint, JmsOperations template) {
 34  0
         super(endpoint);
 35  0
         this.template = template;
 36  0
     }
 37  
 
 38  
     @Override
 39  
     public JmsEndpoint getEndpoint() {
 40  0
         return (JmsEndpoint)super.getEndpoint();
 41  
     }
 42  
 
 43  
     public JmsExchange receiveNoWait() {
 44  0
         return receive(0);
 45  
     }
 46  
 
 47  
     public JmsExchange receive() {
 48  0
         return receive(-1);
 49  
     }
 50  
 
 51  
     public JmsExchange receive(long timeout) {
 52  0
         setReceiveTimeout(timeout);
 53  0
         Message message = template.receive();
 54  0
         if (message != null) {
 55  0
             return getEndpoint().createExchange(message);
 56  
         }
 57  0
         return null;
 58  
     }
 59  
 
 60  
     protected void doStart() throws Exception {
 61  0
     }
 62  
 
 63  
     protected void doStop() throws Exception {
 64  0
     }
 65  
 
 66  
     protected void setReceiveTimeout(long timeout) {
 67  0
         if (template instanceof JmsTemplate) {
 68  0
             JmsTemplate jmsTemplate = (JmsTemplate)template;
 69  0
             jmsTemplate.setReceiveTimeout(timeout);
 70  0
         } else if (template instanceof JmsTemplate102) {
 71  0
             JmsTemplate102 jmsTemplate102 = (JmsTemplate102)template;
 72  0
             jmsTemplate102.setReceiveTimeout(timeout);
 73  0
         } else {
 74  0
             throw new IllegalArgumentException("Cannot set the receiveTimeout property on unknown JmsOperations type: " + template);
 75  
         }
 76  0
     }
 77  
 }