1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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.Queue;
33 import javax.jms.QueueConnection;
34 import javax.jms.QueueReceiver;
35 import javax.jms.QueueSender;
36 import javax.jms.QueueSession;
37 import javax.jms.Session;
38
39 import ca.uhn.hl7v2.protocol.TransportException;
40
41
42
43
44
45
46
47 public class JMSQueueTransport extends AbstractJMSTransport {
48
49 private QueueSession mySendingSession;
50 private QueueSession myReceivingSession;
51 private QueueSender mySender;
52 private QueueReceiver myReceiver;
53 private final QueueConnection myConnection;
54 private final Queue myQueue;
55
56
57
58
59
60 public JMSQueueTransport(QueueConnection theConnection, Queue theDestination) {
61 myConnection = theConnection;
62 myQueue = theDestination;
63 }
64
65
66
67
68 protected String getDestinationName() throws JMSException {
69 return myQueue.getQueueName();
70 }
71
72
73
74
75 public Connection getConnection() {
76 return myConnection;
77 }
78
79
80
81
82 protected Message getMessage() throws JMSException {
83 return mySendingSession.createTextMessage();
84 }
85
86
87
88
89 protected void sendJMS(Message theMessage) throws JMSException {
90 mySender.send(theMessage);
91 }
92
93
94
95
96 protected Message receiveJMS() throws JMSException {
97 return myReceiver.receive();
98 }
99
100
101
102
103 public void doConnect() throws TransportException {
104 boolean transacted = false;
105 int ackMode = Session.AUTO_ACKNOWLEDGE;
106
107 doDisconnect();
108 try {
109 mySendingSession = myConnection.createQueueSession(transacted, ackMode);
110 mySender = mySendingSession.createSender(myQueue);
111
112 myReceivingSession = myConnection.createQueueSession(transacted, ackMode);
113 myReceiver = myReceivingSession.createReceiver(myQueue);
114 } catch (JMSException e) {
115 throw new TransportException(e);
116 }
117 }
118
119
120
121
122 public void doDisconnect() throws TransportException {
123 try {
124 if (mySendingSession != null) {
125 mySendingSession.close();
126 }
127 if (myReceivingSession != null) {
128 myReceivingSession.close();
129 }
130 } catch (JMSException e) {
131 throw new TransportException(e);
132 }
133 }
134
135 }