KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > ra > JMSSessionProxy


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Coridan.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34  
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46
47 package org.mr.ra;
48
49 import java.io.Serializable JavaDoc;
50
51 import javax.jms.BytesMessage JavaDoc;
52 import javax.jms.Destination JavaDoc;
53 import javax.jms.IllegalStateException JavaDoc;
54 import javax.jms.JMSException JavaDoc;
55 import javax.jms.MapMessage JavaDoc;
56 import javax.jms.Message JavaDoc;
57 import javax.jms.MessageConsumer JavaDoc;
58 import javax.jms.MessageListener JavaDoc;
59 import javax.jms.MessageProducer JavaDoc;
60 import javax.jms.ObjectMessage JavaDoc;
61 import javax.jms.Queue JavaDoc;
62 import javax.jms.QueueBrowser JavaDoc;
63 import javax.jms.QueueReceiver JavaDoc;
64 import javax.jms.QueueSender JavaDoc;
65 import javax.jms.QueueSession JavaDoc;
66 import javax.jms.Session JavaDoc;
67 import javax.jms.StreamMessage JavaDoc;
68 import javax.jms.TemporaryQueue JavaDoc;
69 import javax.jms.TemporaryTopic JavaDoc;
70 import javax.jms.TextMessage JavaDoc;
71 import javax.jms.Topic JavaDoc;
72 import javax.jms.TopicPublisher JavaDoc;
73 import javax.jms.TopicSession JavaDoc;
74 import javax.jms.TopicSubscriber JavaDoc;
75
76 import org.apache.commons.logging.Log;
77 import org.apache.commons.logging.LogFactory;
78 import org.mr.api.jms.MantaSession;
79
80 /**
81  * Acts as a pass through proxy for a JMS Session object. It intercepts events
82  * that are of interest of the ActiveMQManagedConnection.
83  *
84  * @version $Revision: 1.1.1.1 $
85  */

86 public class JMSSessionProxy implements Session JavaDoc, QueueSession JavaDoc, TopicSession JavaDoc {
87
88     static final private Log log = LogFactory.getLog(JMSSessionProxy.class);
89
90     private final MantaSession session;
91     boolean closed = false;
92
93     public JMSSessionProxy(MantaSession session) {
94         log.info("JMSSessionProxy()");
95         this.session = session;
96     }
97
98     public void setUseSharedTxContext(boolean enable) throws JMSException JavaDoc {
99         log.info("setUseSharedTxContext()");
100         ((RATransactionContext)session.getTransactionContext()).setUseSharedTxContext(enable);
101     }
102
103     /**
104      * @throws JMSException
105      */

106     public void close() throws JMSException JavaDoc {
107         log.info("close()");
108         cleanup();
109     }
110
111     /**
112      * Called by the ActiveMQManagedConnection to invalidate this proxy.
113      * @throws JMSException
114      *
115      * @throws JMSException
116      */

117     public void cleanup() throws JMSException JavaDoc {
118         log.info("cleanup()");
119         closed = true;
120         session.close();
121     }
122
123     /**
124      *
125      */

126     private Session JavaDoc getSession() throws JMSException JavaDoc {
127         log.info("getSession()");
128         if (closed) {
129             throw new IllegalStateException JavaDoc("The Session is closed");
130         }
131         return session;
132     }
133
134     /**
135      * @throws JMSException
136      */

137     public void commit() throws JMSException JavaDoc {
138         log.info("commit()");
139         getSession().commit();
140     }
141
142     /**
143      * @param queue
144      * @return
145      * @throws JMSException
146      */

147     public QueueBrowser JavaDoc createBrowser(Queue JavaDoc queue) throws JMSException JavaDoc {
148         log.info("createBrowser(Queue)");
149         return getSession().createBrowser(queue);
150     }
151
152     /**
153      * @param queue
154      * @param messageSelector
155      * @return
156      * @throws JMSException
157      */

158     public QueueBrowser JavaDoc createBrowser(Queue JavaDoc queue, String JavaDoc messageSelector) throws JMSException JavaDoc {
159         log.info("createBrowser(Queue, String)");
160         return getSession().createBrowser(queue, messageSelector);
161     }
162
163     /**
164      * @return
165      * @throws JMSException
166      */

167     public BytesMessage JavaDoc createBytesMessage() throws JMSException JavaDoc {
168         log.info("createBytesMessage()");
169         return getSession().createBytesMessage();
170     }
171
172     /**
173      * @param destination
174      * @return
175      * @throws JMSException
176      */

177     public MessageConsumer JavaDoc createConsumer(Destination JavaDoc destination) throws JMSException JavaDoc {
178         log.info("createConsumer(Destination)");
179         return getSession().createConsumer(destination);
180     }
181
182     /**
183      * @param destination
184      * @param messageSelector
185      * @return
186      * @throws JMSException
187      */

188     public MessageConsumer JavaDoc createConsumer(Destination JavaDoc destination, String JavaDoc messageSelector) throws JMSException JavaDoc {
189         log.info("createConsumer(Destination, String)");
190         return getSession().createConsumer(destination, messageSelector);
191     }
192
193     /**
194      * @param destination
195      * @param messageSelector
196      * @param NoLocal
197      * @return
198      * @throws JMSException
199      */

200     public MessageConsumer JavaDoc createConsumer(Destination JavaDoc destination, String JavaDoc messageSelector, boolean NoLocal)
201             throws JMSException JavaDoc {
202         log.info("createConsumer(Destination, String, boolean)");
203         return getSession().createConsumer(destination, messageSelector, NoLocal);
204     }
205
206     /**
207      * @param topic
208      * @param name
209      * @return
210      * @throws JMSException
211      */

212     public TopicSubscriber JavaDoc createDurableSubscriber(Topic JavaDoc topic, String JavaDoc name) throws JMSException JavaDoc {
213         log.info("createDurableSubscriber(Topic, String)");
214         return getSession().createDurableSubscriber(topic, name);
215     }
216
217     /**
218      * @param topic
219      * @param name
220      * @param messageSelector
221      * @param noLocal
222      * @return
223      * @throws JMSException
224      */

225     public TopicSubscriber JavaDoc createDurableSubscriber(Topic JavaDoc topic,
226                                                    String JavaDoc name,
227                                                    String JavaDoc messageSelector,
228                                                    boolean noLocal)
229             throws JMSException JavaDoc {
230         log.info("createDurableSubscriber(Topic, String, String, boolean)");
231         return getSession().createDurableSubscriber(topic, name, messageSelector, noLocal);
232     }
233
234     /**
235      * @return
236      * @throws JMSException
237      */

238     public MapMessage JavaDoc createMapMessage() throws JMSException JavaDoc {
239         log.info("createMapMessage()");
240         return getSession().createMapMessage();
241     }
242
243     /**
244      * @return
245      * @throws JMSException
246      */

247     public Message JavaDoc createMessage() throws JMSException JavaDoc {
248         log.info("createMessage()");
249         return getSession().createMessage();
250     }
251
252     /**
253      * @return
254      * @throws JMSException
255      */

256     public ObjectMessage JavaDoc createObjectMessage() throws JMSException JavaDoc {
257         log.info("createObjectMessage()");
258         return getSession().createObjectMessage();
259     }
260
261     /**
262      * @param object
263      * @return
264      * @throws JMSException
265      */

266     public ObjectMessage JavaDoc createObjectMessage(Serializable JavaDoc object) throws JMSException JavaDoc {
267         log.info("createObjectMessage(Serializable)");
268         return getSession().createObjectMessage(object);
269     }
270
271     /**
272      * @param destination
273      * @return
274      * @throws JMSException
275      */

276     public MessageProducer JavaDoc createProducer(Destination JavaDoc destination) throws JMSException JavaDoc {
277         log.info("createProducer()");
278         return getSession().createProducer(destination);
279     }
280
281     /**
282      * @param queueName
283      * @return
284      * @throws JMSException
285      */

286     public Queue JavaDoc createQueue(String JavaDoc queueName) throws JMSException JavaDoc {
287         log.info("createQueue()");
288         return getSession().createQueue(queueName);
289     }
290
291     /**
292      * @return
293      * @throws JMSException
294      */

295     public StreamMessage JavaDoc createStreamMessage() throws JMSException JavaDoc {
296         log.info("createStreamMessage()");
297         return getSession().createStreamMessage();
298     }
299
300     /**
301      * @return
302      * @throws JMSException
303      */

304     public TemporaryQueue JavaDoc createTemporaryQueue() throws JMSException JavaDoc {
305         log.info("createTemporaryQueue()");
306         return getSession().createTemporaryQueue();
307     }
308
309     /**
310      * @return
311      * @throws JMSException
312      */

313     public TemporaryTopic JavaDoc createTemporaryTopic() throws JMSException JavaDoc {
314         log.info("createTemporaryTopic()");
315         return getSession().createTemporaryTopic();
316     }
317
318     /**
319      * @return
320      * @throws JMSException
321      */

322     public TextMessage JavaDoc createTextMessage() throws JMSException JavaDoc {
323         log.info("createTextMessage()");
324         return getSession().createTextMessage();
325     }
326
327     /**
328      * @param text
329      * @return
330      * @throws JMSException
331      */

332     public TextMessage JavaDoc createTextMessage(String JavaDoc text) throws JMSException JavaDoc {
333         log.info("createTextMessage(String)");
334         return getSession().createTextMessage(text);
335     }
336
337     /**
338      * @param topicName
339      * @return
340      * @throws JMSException
341      */

342     public Topic JavaDoc createTopic(String JavaDoc topicName) throws JMSException JavaDoc {
343         log.info("createTopic()");
344         return getSession().createTopic(topicName);
345     }
346
347     /**
348      * @return
349      * @throws JMSException
350      */

351     public int getAcknowledgeMode() throws JMSException JavaDoc {
352         log.info("getAcknowledgeMode()");
353         return getSession().getAcknowledgeMode();
354     }
355
356     /**
357      * @return
358      * @throws JMSException
359      */

360     public MessageListener JavaDoc getMessageListener() throws JMSException JavaDoc {
361         log.info("getMessageListener()");
362         return getSession().getMessageListener();
363     }
364
365     /**
366      * @return
367      * @throws JMSException
368      */

369     public boolean getTransacted() throws JMSException JavaDoc {
370         log.info("getTransacted()");
371         return getSession().getTransacted();
372     }
373
374     /**
375      * @throws JMSException
376      */

377     public void recover() throws JMSException JavaDoc {
378         log.info("recover()");
379         getSession().recover();
380     }
381
382     /**
383      * @throws JMSException
384      */

385     public void rollback() throws JMSException JavaDoc {
386         log.info("rollback()");
387         getSession().rollback();
388     }
389
390     /**
391      * @param listener
392      * @throws JMSException
393      */

394     public void setMessageListener(MessageListener JavaDoc listener) throws JMSException JavaDoc {
395         log.info("setMessageListener() - take a look here!");
396         getSession().setMessageListener(listener);
397     }
398
399     /**
400      * @param name
401      * @throws JMSException
402      */

403     public void unsubscribe(String JavaDoc name) throws JMSException JavaDoc {
404         log.info("unsubscribe()");
405         getSession().unsubscribe(name);
406     }
407
408     /**
409      * @param queue
410      * @return
411      * @throws JMSException
412      */

413     public QueueReceiver JavaDoc createReceiver(Queue JavaDoc queue) throws JMSException JavaDoc {
414         log.info("createReceiver(Queue)");
415         return ((QueueSession JavaDoc) getSession()).createReceiver(queue);
416     }
417
418     /**
419      * @param queue
420      * @param messageSelector
421      * @return
422      * @throws JMSException
423      */

424     public QueueReceiver JavaDoc createReceiver(Queue JavaDoc queue, String JavaDoc messageSelector) throws JMSException JavaDoc {
425         log.info("createReceiver(Queue, String)");
426         return ((QueueSession JavaDoc) getSession()).createReceiver(queue, messageSelector);
427     }
428
429     /**
430      * @param queue
431      * @return
432      * @throws JMSException
433      */

434     public QueueSender JavaDoc createSender(Queue JavaDoc queue) throws JMSException JavaDoc {
435         log.info("createSender()");
436         return ((QueueSession JavaDoc) getSession()).createSender(queue);
437     }
438
439     /**
440      * @param topic
441      * @return
442      * @throws JMSException
443      */

444     public TopicPublisher JavaDoc createPublisher(Topic JavaDoc topic) throws JMSException JavaDoc {
445         log.info("createPublisher()");
446         return ((TopicSession JavaDoc) getSession()).createPublisher(topic);
447     }
448
449     /**
450      * @param topic
451      * @return
452      * @throws JMSException
453      */

454     public TopicSubscriber JavaDoc createSubscriber(Topic JavaDoc topic) throws JMSException JavaDoc {
455         log.info("createSubscriber(Topic)");
456         return ((TopicSession JavaDoc) getSession()).createSubscriber(topic);
457     }
458
459     /**
460      * @param topic
461      * @param messageSelector
462      * @param noLocal
463      * @return
464      * @throws JMSException
465      */

466     public TopicSubscriber JavaDoc createSubscriber(Topic JavaDoc topic,
467                                             String JavaDoc messageSelector,
468                                             boolean noLocal)
469                                             throws JMSException JavaDoc {
470         log.info("JMSSessionProxy(Topic, String, boolean)");
471         return ((TopicSession JavaDoc) getSession()).createSubscriber(topic, messageSelector, noLocal);
472     }
473
474     /**
475      * @see javax.jms.Session#run()
476      */

477     public void run() {
478         log.info("run() - no support");
479         throw new RuntimeException JavaDoc("Operation not supported.");
480     }
481
482 }
483
Popular Tags