Clover coverage report - Lingo - 1.0-SNAPSHOT
Coverage timestamp: Fri May 13 2005 08:50:34 BST
file stats: LOC: 128   Methods: 11
NCLOC: 78   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
SingleThreadedRequestor.java 20% 43.8% 63.6% 43.4%
coverage coverage
 1   
 /**
 2   
  *
 3   
  * Copyright 2005 LogicBlaze, Inc.
 4   
  *
 5   
  * Licensed under the Apache License, Version 2.0 (the "License");
 6   
  * you may not use this file except in compliance with the License.
 7   
  * 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   
  **/
 18   
 package org.logicblaze.lingo.jms.impl;
 19   
 
 20   
 import org.logicblaze.lingo.jms.JmsProducer;
 21   
 import org.logicblaze.lingo.jms.Requestor;
 22   
 
 23   
 import javax.jms.Connection;
 24   
 import javax.jms.ConnectionFactory;
 25   
 import javax.jms.Destination;
 26   
 import javax.jms.JMSException;
 27   
 import javax.jms.Message;
 28   
 import javax.jms.MessageConsumer;
 29   
 import javax.jms.Session;
 30   
 import javax.jms.TemporaryQueue;
 31   
 import javax.jms.TemporaryTopic;
 32   
 
 33   
 /**
 34   
  * A simple {@link org.logicblaze.lingo.jms.Requestor} which can only be used by one thread at once
 35   
  * and only used for one message exchange at once.
 36   
  *
 37   
  * @version $Revision: 1.1 $
 38   
  */
 39   
 public class SingleThreadedRequestor extends OneWayRequestor {
 40   
     private Connection connection;
 41   
     private Session session;
 42   
     private Destination temporaryDestination;
 43   
     private MessageConsumer receiver;
 44   
     private long maximumTimeout = 20000L;
 45   
 
 46   
 
 47  0
     public static Requestor newInstance(ConnectionFactory connectionFactory, Destination serverDestination) throws JMSException {
 48  0
         JmsProducer producer = DefaultJmsProducer.newInstance(connectionFactory);
 49  0
         return new SingleThreadedRequestor(producer.getSession(), producer, serverDestination);
 50   
     }
 51   
 
 52  25
     public SingleThreadedRequestor(Session session, JmsProducer producer, Destination serverDestination) throws JMSException {
 53  25
         super(producer, serverDestination);
 54  25
         this.session = session;
 55  25
         temporaryDestination = createTemporaryDestination(session);
 56  25
         receiver = session.createConsumer(temporaryDestination);
 57   
     }
 58   
 
 59  21
     public Message request(Destination destination, Message message) throws JMSException {
 60  21
         oneWay(destination, message);
 61  21
         long timeout = getMaximumTimeout();
 62  21
         return receive(timeout);
 63   
     }
 64   
 
 65  0
     public Message request(Destination destination, Message message, long timeout) throws JMSException {
 66  0
         oneWay(destination, message);
 67  0
         return receive(timeout);
 68   
     }
 69   
 
 70  21
     public Message receive(long timeout) throws JMSException {
 71  21
         if (timeout < 0) {
 72  0
             return receiver.receive();
 73   
         }
 74  21
         else if (timeout == 0) {
 75  0
             return receiver.receiveNoWait();
 76   
         }
 77  21
         return receiver.receive(timeout);
 78   
     }
 79   
 
 80  0
     public synchronized void close() throws JMSException {
 81   
         // producer and consumer created by constructor are implicitly closed.
 82  0
         session.close();
 83  0
         if (temporaryDestination instanceof TemporaryQueue) {
 84  0
             ((TemporaryQueue) temporaryDestination).delete();
 85   
         }
 86  0
         else if (temporaryDestination instanceof TemporaryTopic) {
 87  0
             ((TemporaryTopic) temporaryDestination).delete();
 88   
         }
 89  0
         super.close();
 90   
 
 91  0
         if (connection != null) {
 92  0
             connection.close();
 93   
         }
 94  0
         connection = null;
 95  0
         session = null;
 96  0
         temporaryDestination = null;
 97   
     }
 98   
 
 99  87
     public long getMaximumTimeout() {
 100  87
         return maximumTimeout;
 101   
     }
 102   
 
 103   
     /**
 104   
      * Sets the maximum default timeout used for remote requests. If set to <= 0 then
 105   
      * the timeout is ignored.
 106   
      *
 107   
      * @param maximumTimeout
 108   
      */
 109  0
     public void setMaximumTimeout(long maximumTimeout) {
 110  0
         this.maximumTimeout = maximumTimeout;
 111   
     }
 112   
 
 113   
     // Implementation methods
 114   
     //-------------------------------------------------------------------------
 115  25
     protected TemporaryQueue createTemporaryDestination(Session session) throws JMSException {
 116  25
         return session.createTemporaryQueue();
 117   
     }
 118   
 
 119  92
     protected void populateHeaders(Message message) throws JMSException {
 120  92
         message.setJMSReplyTo(temporaryDestination);
 121   
     }
 122   
 
 123  18
     protected MessageConsumer getReceiver() {
 124  18
         return receiver;
 125   
     }
 126   
 
 127   
 }
 128