KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ra > ManagedSessionProxy


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.ra;
19
20 import java.io.Serializable JavaDoc;
21
22 import javax.jms.BytesMessage JavaDoc;
23 import javax.jms.Destination JavaDoc;
24 import javax.jms.IllegalStateException JavaDoc;
25 import javax.jms.JMSException JavaDoc;
26 import javax.jms.MapMessage JavaDoc;
27 import javax.jms.Message JavaDoc;
28 import javax.jms.MessageConsumer JavaDoc;
29 import javax.jms.MessageListener JavaDoc;
30 import javax.jms.MessageProducer JavaDoc;
31 import javax.jms.ObjectMessage JavaDoc;
32 import javax.jms.Queue JavaDoc;
33 import javax.jms.QueueBrowser JavaDoc;
34 import javax.jms.QueueReceiver JavaDoc;
35 import javax.jms.QueueSender JavaDoc;
36 import javax.jms.QueueSession JavaDoc;
37 import javax.jms.Session JavaDoc;
38 import javax.jms.StreamMessage JavaDoc;
39 import javax.jms.TemporaryQueue JavaDoc;
40 import javax.jms.TemporaryTopic JavaDoc;
41 import javax.jms.TextMessage JavaDoc;
42 import javax.jms.Topic JavaDoc;
43 import javax.jms.TopicPublisher JavaDoc;
44 import javax.jms.TopicSession JavaDoc;
45 import javax.jms.TopicSubscriber JavaDoc;
46
47 import org.apache.activemq.ActiveMQSession;
48
49 /**
50  * Acts as a pass through proxy for a JMS Session object. It intercepts events
51  * that are of interest of the ActiveMQManagedConnection.
52  *
53  * @version $Revision$
54  */

55 public class ManagedSessionProxy implements Session JavaDoc, QueueSession JavaDoc, TopicSession JavaDoc {
56
57     private final ActiveMQSession session;
58     boolean closed = false;
59
60     public ManagedSessionProxy(ActiveMQSession session) {
61         this.session = session;
62     }
63
64     public void setUseSharedTxContext(boolean enable) throws JMSException JavaDoc {
65         if( session.getTransactionContext() !=null ) {
66             ((ManagedTransactionContext)session.getTransactionContext()).setUseSharedTxContext(enable);
67         }
68     }
69
70     /**
71      * @throws JMSException
72      */

73     public void close() throws JMSException JavaDoc {
74         cleanup();
75     }
76
77     /**
78      * Called by the ActiveMQManagedConnection to invalidate this proxy.
79      * @throws JMSException
80      *
81      * @throws JMSException
82      */

83     public void cleanup() throws JMSException JavaDoc {
84         closed = true;
85         session.close();
86     }
87
88     /**
89      *
90      */

91     private Session JavaDoc getSession() throws JMSException JavaDoc {
92         if (closed) {
93             throw new IllegalStateException JavaDoc("The Session is closed");
94         }
95         return session;
96     }
97
98     /**
99      * @throws JMSException
100      */

101     public void commit() throws JMSException JavaDoc {
102         getSession().commit();
103     }
104
105     /**
106      * @param queue
107      * @return
108      * @throws JMSException
109      */

110     public QueueBrowser JavaDoc createBrowser(Queue JavaDoc queue) throws JMSException JavaDoc {
111         return getSession().createBrowser(queue);
112     }
113
114     /**
115      * @param queue
116      * @param messageSelector
117      * @return
118      * @throws JMSException
119      */

120     public QueueBrowser JavaDoc createBrowser(Queue JavaDoc queue, String JavaDoc messageSelector) throws JMSException JavaDoc {
121         return getSession().createBrowser(queue, messageSelector);
122     }
123
124     /**
125      * @return
126      * @throws JMSException
127      */

128     public BytesMessage JavaDoc createBytesMessage() throws JMSException JavaDoc {
129         return getSession().createBytesMessage();
130     }
131
132     /**
133      * @param destination
134      * @return
135      * @throws JMSException
136      */

137     public MessageConsumer JavaDoc createConsumer(Destination JavaDoc destination) throws JMSException JavaDoc {
138         return getSession().createConsumer(destination);
139     }
140
141     /**
142      * @param destination
143      * @param messageSelector
144      * @return
145      * @throws JMSException
146      */

147     public MessageConsumer JavaDoc createConsumer(Destination JavaDoc destination, String JavaDoc messageSelector) throws JMSException JavaDoc {
148         return getSession().createConsumer(destination, messageSelector);
149     }
150
151     /**
152      * @param destination
153      * @param messageSelector
154      * @param NoLocal
155      * @return
156      * @throws JMSException
157      */

158     public MessageConsumer JavaDoc createConsumer(Destination JavaDoc destination, String JavaDoc messageSelector, boolean NoLocal)
159             throws JMSException JavaDoc {
160         return getSession().createConsumer(destination, messageSelector, NoLocal);
161     }
162
163     /**
164      * @param topic
165      * @param name
166      * @return
167      * @throws JMSException
168      */

169     public TopicSubscriber JavaDoc createDurableSubscriber(Topic JavaDoc topic, String JavaDoc name) throws JMSException JavaDoc {
170         return getSession().createDurableSubscriber(topic, name);
171     }
172
173     /**
174      * @param topic
175      * @param name
176      * @param messageSelector
177      * @param noLocal
178      * @return
179      * @throws JMSException
180      */

181     public TopicSubscriber JavaDoc createDurableSubscriber(Topic JavaDoc topic, String JavaDoc name, String JavaDoc messageSelector, boolean noLocal)
182             throws JMSException JavaDoc {
183         return getSession().createDurableSubscriber(topic, name, messageSelector, noLocal);
184     }
185
186     /**
187      * @return
188      * @throws JMSException
189      */

190     public MapMessage JavaDoc createMapMessage() throws JMSException JavaDoc {
191         return getSession().createMapMessage();
192     }
193
194     /**
195      * @return
196      * @throws JMSException
197      */

198     public Message JavaDoc createMessage() throws JMSException JavaDoc {
199         return getSession().createMessage();
200     }
201
202     /**
203      * @return
204      * @throws JMSException
205      */

206     public ObjectMessage JavaDoc createObjectMessage() throws JMSException JavaDoc {
207         return getSession().createObjectMessage();
208     }
209
210     /**
211      * @param object
212      * @return
213      * @throws JMSException
214      */

215     public ObjectMessage JavaDoc createObjectMessage(Serializable JavaDoc object) throws JMSException JavaDoc {
216         return getSession().createObjectMessage(object);
217     }
218
219     /**
220      * @param destination
221      * @return
222      * @throws JMSException
223      */

224     public MessageProducer JavaDoc createProducer(Destination JavaDoc destination) throws JMSException JavaDoc {
225         return getSession().createProducer(destination);
226     }
227
228     /**
229      * @param queueName
230      * @return
231      * @throws JMSException
232      */

233     public Queue JavaDoc createQueue(String JavaDoc queueName) throws JMSException JavaDoc {
234         return getSession().createQueue(queueName);
235     }
236
237     /**
238      * @return
239      * @throws JMSException
240      */

241     public StreamMessage JavaDoc createStreamMessage() throws JMSException JavaDoc {
242         return getSession().createStreamMessage();
243     }
244
245     /**
246      * @return
247      * @throws JMSException
248      */

249     public TemporaryQueue JavaDoc createTemporaryQueue() throws JMSException JavaDoc {
250         return getSession().createTemporaryQueue();
251     }
252
253     /**
254      * @return
255      * @throws JMSException
256      */

257     public TemporaryTopic JavaDoc createTemporaryTopic() throws JMSException JavaDoc {
258         return getSession().createTemporaryTopic();
259     }
260
261     /**
262      * @return
263      * @throws JMSException
264      */

265     public TextMessage JavaDoc createTextMessage() throws JMSException JavaDoc {
266         return getSession().createTextMessage();
267     }
268
269     /**
270      * @param text
271      * @return
272      * @throws JMSException
273      */

274     public TextMessage JavaDoc createTextMessage(String JavaDoc text) throws JMSException JavaDoc {
275         return getSession().createTextMessage(text);
276     }
277
278     /**
279      * @param topicName
280      * @return
281      * @throws JMSException
282      */

283     public Topic JavaDoc createTopic(String JavaDoc topicName) throws JMSException JavaDoc {
284         return getSession().createTopic(topicName);
285     }
286
287     /**
288      * @return
289      * @throws JMSException
290      */

291     public int getAcknowledgeMode() throws JMSException JavaDoc {
292         return getSession().getAcknowledgeMode();
293     }
294
295     /**
296      * @return
297      * @throws JMSException
298      */

299     public MessageListener JavaDoc getMessageListener() throws JMSException JavaDoc {
300         return getSession().getMessageListener();
301     }
302
303     /**
304      * @return
305      * @throws JMSException
306      */

307     public boolean getTransacted() throws JMSException JavaDoc {
308         return getSession().getTransacted();
309     }
310
311     /**
312      * @throws JMSException
313      */

314     public void recover() throws JMSException JavaDoc {
315         getSession().recover();
316     }
317
318     /**
319      * @throws JMSException
320      */

321     public void rollback() throws JMSException JavaDoc {
322         getSession().rollback();
323     }
324
325     /**
326      * @param listener
327      * @throws JMSException
328      */

329     public void setMessageListener(MessageListener JavaDoc listener) throws JMSException JavaDoc {
330         getSession(); // .setMessageListener(listener);
331
}
332
333     /**
334      * @param name
335      * @throws JMSException
336      */

337     public void unsubscribe(String JavaDoc name) throws JMSException JavaDoc {
338         getSession().unsubscribe(name);
339     }
340
341     /**
342      * @param queue
343      * @return
344      * @throws JMSException
345      */

346     public QueueReceiver JavaDoc createReceiver(Queue JavaDoc queue) throws JMSException JavaDoc {
347         return ((QueueSession JavaDoc) getSession()).createReceiver(queue);
348     }
349
350     /**
351      * @param queue
352      * @param messageSelector
353      * @return
354      * @throws JMSException
355      */

356     public QueueReceiver JavaDoc createReceiver(Queue JavaDoc queue, String JavaDoc messageSelector) throws JMSException JavaDoc {
357         return ((QueueSession JavaDoc) getSession()).createReceiver(queue, messageSelector);
358     }
359
360     /**
361      * @param queue
362      * @return
363      * @throws JMSException
364      */

365     public QueueSender JavaDoc createSender(Queue JavaDoc queue) throws JMSException JavaDoc {
366         return ((QueueSession JavaDoc) getSession()).createSender(queue);
367     }
368
369     /**
370      * @param topic
371      * @return
372      * @throws JMSException
373      */

374     public TopicPublisher JavaDoc createPublisher(Topic JavaDoc topic) throws JMSException JavaDoc {
375         return ((TopicSession JavaDoc) getSession()).createPublisher(topic);
376     }
377
378     /**
379      * @param topic
380      * @return
381      * @throws JMSException
382      */

383     public TopicSubscriber JavaDoc createSubscriber(Topic JavaDoc topic) throws JMSException JavaDoc {
384         return ((TopicSession JavaDoc) getSession()).createSubscriber(topic);
385     }
386
387     /**
388      * @param topic
389      * @param messageSelector
390      * @param noLocal
391      * @return
392      * @throws JMSException
393      */

394     public TopicSubscriber JavaDoc createSubscriber(Topic JavaDoc topic, String JavaDoc messageSelector, boolean noLocal) throws JMSException JavaDoc {
395         return ((TopicSession JavaDoc) getSession()).createSubscriber(topic, messageSelector, noLocal);
396     }
397
398     /**
399      * @see javax.jms.Session#run()
400      */

401     public void run() {
402         throw new RuntimeException JavaDoc("Operation not supported.");
403     }
404
405     public String JavaDoc toString() {
406         return "ManagedSessionProxy { "+session+" }";
407     }
408
409 }
410
Popular Tags