Coverage Report - ca.uhn.hl7v2.protocol.impl.JMSTopicAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
JMSTopicAdapter
0%
0/30
0%
0/4
1.2
 
 1  
 /*
 2  
 The contents of this file are subject to the Mozilla Public License Version 1.1 
 3  
 (the "License"); you may not use this file except in compliance with the License. 
 4  
 You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
 5  
 Software distributed under the License is distributed on an "AS IS" basis, 
 6  
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
 7  
 specific language governing rights and limitations under the License. 
 8  
 
 9  
 The Original Code is "JMSTopicAdapter.java".  Description: 
 10  
 "An implementation of JMSDestination that uses an underlying Topic." 
 11  
 
 12  
 The Initial Developer of the Original Code is University Health Network. Copyright (C) 
 13  
 2004.  All Rights Reserved. 
 14  
 
 15  
 Contributor(s): ______________________________________. 
 16  
 
 17  
 Alternatively, the contents of this file may be used under the terms of the 
 18  
 GNU General Public License (the "GPL"), in which case the provisions of the GPL are 
 19  
 applicable instead of those above.  If you wish to allow use of your version of this 
 20  
 file only under the terms of the GPL and not to allow others to use your version 
 21  
 of this file under the MPL, indicate your decision by deleting  the provisions above 
 22  
 and replace  them with the notice and other provisions required by the GPL License.  
 23  
 If you do not delete the provisions above, a recipient may use your version of 
 24  
 this file under either the MPL or the GPL. 
 25  
 */
 26  
 
 27  
 package ca.uhn.hl7v2.protocol.impl;
 28  
 
 29  
 import javax.jms.Connection;
 30  
 import javax.jms.JMSException;
 31  
 import javax.jms.Message;
 32  
 import javax.jms.Session;
 33  
 import javax.jms.TextMessage;
 34  
 import javax.jms.Topic;
 35  
 import javax.jms.TopicConnection;
 36  
 import javax.jms.TopicPublisher;
 37  
 import javax.jms.TopicSession;
 38  
 import javax.jms.TopicSubscriber;
 39  
 
 40  
 import ca.uhn.hl7v2.protocol.JMSDestination;
 41  
 
 42  
 /**
 43  
  * An implementation of <code>JMSDestination</code> that uses an underlying 
 44  
  * Topic.
 45  
  *   
 46  
  * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
 47  
  * @version $Revision: 1.1 $ updated on $Date: 2007-02-19 02:24:26 $ by $Author: jamesagnew $
 48  
  */
 49  
 public class JMSTopicAdapter implements JMSDestination {
 50  
 
 51  
     private TopicSession mySendingSession;
 52  
     private TopicSession myReceivingSession; 
 53  
     private TopicPublisher myPublisher;
 54  
     private TopicSubscriber mySubscriber;
 55  
     private TopicConnection myConnection;
 56  
     private Topic myTopic;
 57  
     private boolean myIsConnected;
 58  
 
 59  
     /**
 60  
      * @param theConnection the connection over which messages are written and read 
 61  
      * @param theDestination the destination to/from which messages are written/read
 62  
      */
 63  0
     public JMSTopicAdapter(TopicConnection theConnection, Topic theDestination) {
 64  0
         myConnection = theConnection;
 65  0
         myTopic = theDestination;
 66  0
     }
 67  
 
 68  
     /**
 69  
      * @param theConnection the connection over which messages are written and read 
 70  
      * @param theDestination the destination to/from which messages are written/read
 71  
      * @param theMessageSelector a JMS message selector which restricts the inbound 
 72  
      *      messages that are received (see JMS docs)
 73  
      */
 74  0
     public JMSTopicAdapter(TopicConnection theConnection, Topic theDestination, String theMessageSelector) {
 75  0
         myConnection = theConnection;
 76  0
         myTopic = theDestination;
 77  0
     }
 78  
 
 79  
     /** 
 80  
      * @see ca.uhn.hl7v2.protocol.JMSDestination#getName()
 81  
      */
 82  
     public String getName() throws JMSException {
 83  0
         return myTopic.getTopicName();
 84  
     }
 85  
 
 86  
     /**
 87  
      * @see ca.uhn.hl7v2.protocol.JMSDestination#createMessage()
 88  
      */
 89  
     public TextMessage createMessage() throws JMSException {
 90  0
         return mySendingSession.createTextMessage();
 91  
     }
 92  
 
 93  
     /**
 94  
      * @see ca.uhn.hl7v2.protocol.JMSDestination#connect()
 95  
      */
 96  
     public void connect() throws JMSException {
 97  0
         boolean transacted = false;
 98  0
         int ackMode = Session.AUTO_ACKNOWLEDGE;
 99  
 
 100  0
         disconnect();
 101  
         
 102  0
         mySendingSession = myConnection.createTopicSession(transacted, ackMode);
 103  0
         myPublisher = mySendingSession.createPublisher(myTopic);
 104  
 
 105  0
         myReceivingSession = myConnection.createTopicSession(transacted, ackMode);
 106  0
         mySubscriber = myReceivingSession.createSubscriber(myTopic);
 107  
         
 108  0
         myIsConnected = true;
 109  0
     }
 110  
 
 111  
     /**
 112  
      * @see ca.uhn.hl7v2.protocol.JMSDestination#disconnect()
 113  
      */
 114  
     public void disconnect() throws JMSException {
 115  0
         myIsConnected = false;
 116  
         
 117  0
         if (mySendingSession != null) {
 118  0
             mySendingSession.close();
 119  
         }
 120  0
         if (myReceivingSession != null) {
 121  0
             myReceivingSession.close();
 122  
         }
 123  0
     }
 124  
 
 125  
     /**
 126  
      * @see ca.uhn.hl7v2.protocol.JMSDestination#isConnected()
 127  
      */
 128  
     public boolean isConnected() {
 129  0
         return myIsConnected;
 130  
     }
 131  
 
 132  
     /** 
 133  
      * @see ca.uhn.hl7v2.protocol.JMSDestination#send(javax.jms.Message)
 134  
      */
 135  
     public void send(Message theMessage) throws JMSException {
 136  0
         myPublisher.publish(theMessage);
 137  0
     }
 138  
 
 139  
     /**
 140  
      * @see ca.uhn.hl7v2.protocol.JMSDestination#receive()
 141  
      */
 142  
     public Message receive() throws JMSException {
 143  0
         return mySubscriber.receive();
 144  
     }
 145  
 
 146  
     /**
 147  
      * @see ca.uhn.hl7v2.protocol.JMSDestination#getConnection()
 148  
      */
 149  
     public Connection getConnection() {
 150  0
         return myConnection;
 151  
     }
 152  
 
 153  
 }