1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.oracle.jms; |
12 | |
|
13 | |
import java.util.ArrayList; |
14 | |
import java.util.Iterator; |
15 | |
import java.util.List; |
16 | |
|
17 | |
import javax.jms.Connection; |
18 | |
import javax.jms.ConnectionConsumer; |
19 | |
import javax.jms.ConnectionMetaData; |
20 | |
import javax.jms.ExceptionListener; |
21 | |
import javax.jms.JMSException; |
22 | |
import javax.jms.Queue; |
23 | |
import javax.jms.QueueConnection; |
24 | |
import javax.jms.QueueSession; |
25 | |
import javax.jms.ServerSessionPool; |
26 | |
import javax.jms.Topic; |
27 | |
import javax.jms.TopicConnection; |
28 | |
import javax.jms.TopicSession; |
29 | |
|
30 | |
import oracle.jms.AQjmsConnection; |
31 | |
import oracle.jms.AQjmsQueueConnectionFactory; |
32 | |
import oracle.jms.AQjmsTopicConnectionFactory; |
33 | |
import org.apache.commons.logging.Log; |
34 | |
import org.apache.commons.logging.LogFactory; |
35 | |
|
36 | |
public class OracleJmsConnection implements TopicConnection, QueueConnection |
37 | |
{ |
38 | |
|
39 | |
private TopicConnection topicConnection; |
40 | |
private QueueConnection queueConnection; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
private List connections; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
private OracleJmsConnector connector; |
54 | |
|
55 | |
public OracleJmsConnection(OracleJmsConnector connector) |
56 | 0 | { |
57 | 0 | this.connector = connector; |
58 | 0 | connections = new ArrayList(); |
59 | 0 | } |
60 | |
|
61 | |
|
62 | |
public void start() throws JMSException |
63 | |
{ |
64 | 0 | Connection jmsConnection = null; |
65 | |
|
66 | 0 | for (Iterator i = connections.iterator(); i.hasNext();) |
67 | |
{ |
68 | 0 | jmsConnection = (Connection)i.next(); |
69 | 0 | if (jmsConnection != null) |
70 | |
{ |
71 | 0 | jmsConnection.start(); |
72 | |
} |
73 | |
} |
74 | 0 | } |
75 | |
|
76 | |
|
77 | |
public void stop() throws JMSException |
78 | |
{ |
79 | 0 | Connection jmsConnection = null; |
80 | |
|
81 | 0 | for (Iterator i = connections.iterator(); i.hasNext();) |
82 | |
{ |
83 | 0 | jmsConnection = (Connection)i.next(); |
84 | 0 | if (jmsConnection != null) |
85 | |
{ |
86 | 0 | jmsConnection.stop(); |
87 | |
} |
88 | |
} |
89 | 0 | } |
90 | |
|
91 | |
|
92 | |
public void close() throws JMSException |
93 | |
{ |
94 | |
Connection jmsConnection; |
95 | |
|
96 | |
|
97 | 0 | for (Iterator i = connections.iterator(); i.hasNext();) |
98 | |
{ |
99 | 0 | jmsConnection = (Connection)i.next(); |
100 | 0 | if (jmsConnection != null) |
101 | |
{ |
102 | |
try |
103 | |
{ |
104 | |
|
105 | 0 | connector.close(((AQjmsConnection)jmsConnection).getCurrentJmsSession()); |
106 | |
|
107 | 0 | jmsConnection.close(); |
108 | |
} |
109 | 0 | catch (JMSException e) |
110 | |
{ |
111 | 0 | logger.error("Unable to close Oracle JMS connection: " + e.getMessage()); |
112 | 0 | } |
113 | |
} |
114 | |
} |
115 | 0 | } |
116 | |
|
117 | |
protected QueueConnection getQueueConnection() throws JMSException |
118 | |
{ |
119 | |
QueueConnection connection; |
120 | |
|
121 | 0 | if (connector.isMultipleSessionsPerConnection()) |
122 | |
{ |
123 | 0 | if (queueConnection == null) |
124 | |
{ |
125 | 0 | queueConnection = AQjmsQueueConnectionFactory.createQueueConnection(connector.getJdbcConnection()); |
126 | 0 | queueConnection.start(); |
127 | |
} |
128 | 0 | connection = queueConnection; |
129 | |
} |
130 | |
else |
131 | |
{ |
132 | 0 | connection = AQjmsQueueConnectionFactory.createQueueConnection(connector.getJdbcConnection()); |
133 | 0 | connection.start(); |
134 | |
|
135 | 0 | connections.add(connection); |
136 | |
} |
137 | 0 | return connection; |
138 | |
} |
139 | |
|
140 | |
protected TopicConnection getTopicConnection() throws JMSException |
141 | |
{ |
142 | |
TopicConnection connection; |
143 | |
|
144 | 0 | if (connector.isMultipleSessionsPerConnection()) |
145 | |
{ |
146 | 0 | if (topicConnection == null) |
147 | |
{ |
148 | 0 | topicConnection = AQjmsTopicConnectionFactory.createTopicConnection(connector.getJdbcConnection()); |
149 | 0 | topicConnection.start(); |
150 | |
} |
151 | 0 | connection = topicConnection; |
152 | |
} |
153 | |
else |
154 | |
{ |
155 | 0 | connection = AQjmsTopicConnectionFactory.createTopicConnection(connector.getJdbcConnection()); |
156 | 0 | connection.start(); |
157 | |
|
158 | 0 | connections.add(connection); |
159 | |
} |
160 | 0 | connection.start(); |
161 | 0 | return connection; |
162 | |
} |
163 | |
|
164 | |
public QueueSession createQueueSession(boolean transacted, int ackMode) throws JMSException |
165 | |
{ |
166 | 0 | return getQueueConnection().createQueueSession(transacted, ackMode); |
167 | |
} |
168 | |
|
169 | |
public TopicSession createTopicSession(boolean transacted, int ackMode) throws JMSException |
170 | |
{ |
171 | 0 | return getTopicConnection().createTopicSession(transacted, ackMode); |
172 | |
} |
173 | |
|
174 | |
public ConnectionConsumer createConnectionConsumer(Topic arg0, |
175 | |
String arg1, |
176 | |
ServerSessionPool arg2, |
177 | |
int arg3) throws JMSException |
178 | |
{ |
179 | 0 | return getTopicConnection().createConnectionConsumer(arg0, arg1, arg2, arg3); |
180 | |
} |
181 | |
|
182 | |
public ConnectionConsumer createDurableConnectionConsumer(Topic arg0, |
183 | |
String arg1, |
184 | |
String arg2, |
185 | |
ServerSessionPool arg3, |
186 | |
int arg4) throws JMSException |
187 | |
{ |
188 | 0 | return getTopicConnection().createDurableConnectionConsumer(arg0, arg1, arg2, arg3, arg4); |
189 | |
} |
190 | |
|
191 | |
public ConnectionConsumer createConnectionConsumer(Queue arg0, |
192 | |
String arg1, |
193 | |
ServerSessionPool arg2, |
194 | |
int arg3) throws JMSException |
195 | |
{ |
196 | 0 | return getQueueConnection().createConnectionConsumer(arg0, arg1, arg2, arg3); |
197 | |
} |
198 | |
|
199 | |
|
200 | |
public String getClientID() throws JMSException |
201 | |
{ |
202 | 0 | return null; |
203 | |
} |
204 | |
|
205 | |
|
206 | |
public ExceptionListener getExceptionListener() throws JMSException |
207 | |
{ |
208 | 0 | return null; |
209 | |
} |
210 | |
|
211 | |
|
212 | |
public ConnectionMetaData getMetaData() throws JMSException |
213 | |
{ |
214 | 0 | return null; |
215 | |
} |
216 | |
|
217 | |
public void setClientID(String arg0) throws JMSException |
218 | |
{ |
219 | |
|
220 | 0 | } |
221 | |
|
222 | |
public void setExceptionListener(ExceptionListener arg0) throws JMSException |
223 | |
{ |
224 | |
|
225 | 0 | } |
226 | |
|
227 | 0 | private static Log logger = LogFactory.getLog(OracleJmsConnection.class); |
228 | |
} |