KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > jms > XASession


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - 2004 ScalAgent Distributed Technologies
4  * Copyright (C) 2004 - Bull SA
5  * Copyright (C) 1996 - 2000 Dyade
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  * USA.
21  *
22  * Initial developer(s): Frederic Maistre (INRIA)
23  * Contributor(s): ScalAgent Distributed Technologies
24  * Nicolas Tachker (Bull SA)
25  */

26 package org.objectweb.joram.client.jms;
27
28 import javax.jms.JMSException JavaDoc;
29 import javax.jms.IllegalStateException JavaDoc;
30 import javax.jms.TransactionInProgressException JavaDoc;
31
32 import org.objectweb.joram.shared.client.*;
33
34 import org.objectweb.util.monolog.api.BasicLevel;
35
36 /**
37  * Implements the <code>javax.jms.XASession</code> interface.
38  * <p>
39  * An XA session actually extends the behaviour of a normal session by
40  * providing an XA resource representing it to a Transaction Manager, so that
41  * it is part of a distributed transaction. The XASession wraps what looks like
42  * a "normal"Session object. This object takes care of producing and
43  * consuming messages, the actual sendings and acknowledgement being managed
44  * by this XA wrapper.
45  */

46 public class XASession implements javax.jms.XASession JavaDoc {
47
48   /** The XA resource representing the session to the transaction manager. */
49   private javax.transaction.xa.XAResource JavaDoc xaResource;
50   
51   protected Session sess;
52
53   /**
54    * Constructs an <code>XASession</code>.
55    * <p>
56    * This constructor is called by subclasses.
57    *
58    * @param cnx The connection the session belongs to.
59    * @param sess The wrapped "regular" session.
60    * @param rm The resource manager.
61    *
62    * @exception JMSException Actually never thrown.
63    */

64   public XASession(Connection cnx,
65                    Session sess,
66                    XAResourceMngr rm)
67     throws JMSException JavaDoc {
68     this.sess = sess;
69     xaResource = new XAResource(rm, sess);
70   }
71
72   public final Session getDelegateSession() {
73     return sess;
74   }
75
76    /** Returns a String image of this session. */
77   public String JavaDoc toString()
78   {
79     return "XASess:" + sess.getId();
80   }
81   
82   /**
83    * API method.
84    *
85    * @exception IllegalStateException If the session is closed.
86    */

87   public javax.jms.Session JavaDoc getSession() throws JMSException JavaDoc
88   {
89     return sess;
90   }
91  
92   /** API method. */
93   public javax.transaction.xa.XAResource JavaDoc getXAResource()
94   {
95     return xaResource;
96   }
97
98   /**
99    * API method.
100    *
101    * @exception IllegalStateException If the session is closed.
102    */

103   public boolean getTransacted() throws JMSException JavaDoc
104   {
105     return sess.getTransacted();
106   }
107
108   /**
109    * Delegates the call to the wrapped JMS session.
110    */

111   public javax.jms.QueueBrowser JavaDoc
112          createBrowser(javax.jms.Queue JavaDoc queue, String JavaDoc selector)
113          throws JMSException JavaDoc
114   {
115     return sess.createBrowser(queue, selector);
116   }
117
118   /**
119    * Delegates the call to the wrapped JMS session.
120    */

121   public javax.jms.QueueBrowser JavaDoc createBrowser(javax.jms.Queue JavaDoc queue)
122          throws JMSException JavaDoc
123   {
124     return sess.createBrowser(queue);
125   }
126
127   /**
128    * Delegates the call to the wrapped JMS session.
129    */

130   public javax.jms.MessageProducer JavaDoc createProducer(javax.jms.Destination JavaDoc dest)
131          throws JMSException JavaDoc
132   {
133     return sess.createProducer(dest);
134   }
135
136   /**
137    * Delegates the call to the wrapped JMS session.
138    */

139   public javax.jms.MessageConsumer JavaDoc
140          createConsumer(javax.jms.Destination JavaDoc dest,
141                         String JavaDoc selector,
142                         boolean noLocal)
143          throws JMSException JavaDoc
144   {
145     return sess.createConsumer(dest, selector, noLocal);
146   }
147
148   /**
149    * Delegates the call to the wrapped JMS session.
150    */

151   public javax.jms.MessageConsumer JavaDoc
152          createConsumer(javax.jms.Destination JavaDoc dest, String JavaDoc selector)
153          throws JMSException JavaDoc
154   {
155     return sess.createConsumer(dest, selector);
156   }
157
158   /**
159    * Delegates the call to the wrapped JMS session.
160    */

161   public javax.jms.MessageConsumer JavaDoc createConsumer(javax.jms.Destination JavaDoc dest)
162          throws JMSException JavaDoc
163   {
164     return sess.createConsumer(dest);
165   }
166
167   /**
168    * Delegates the call to the wrapped JMS session.
169    */

170   public javax.jms.TopicSubscriber JavaDoc
171          createDurableSubscriber(javax.jms.Topic JavaDoc topic,
172                                  String JavaDoc name,
173                                  String JavaDoc selector,
174                                  boolean noLocal)
175          throws JMSException JavaDoc
176   {
177     return sess.createDurableSubscriber(topic, name, selector, noLocal);
178   }
179
180   /**
181    * Delegates the call to the wrapped JMS session.
182    */

183   public javax.jms.TopicSubscriber JavaDoc
184          createDurableSubscriber(javax.jms.Topic JavaDoc topic, String JavaDoc name)
185          throws JMSException JavaDoc
186   {
187     return sess.createDurableSubscriber(topic, name);
188   }
189
190   /**
191    * API method inherited from session, but intercepted here for
192    * forbidding its use in the XA context (as defined by the API).
193    *
194    * @exception IllegalStateException Systematically thrown.
195    */

196   public void commit() throws JMSException JavaDoc
197   {
198     throw new IllegalStateException JavaDoc("Forbidden call on an XA session.");
199   }
200
201   /**
202    * API method inherited from session, but intercepted here for
203    * forbidding its use in the XA context (as defined by the API).
204    *
205    * @exception IllegalStateException Systematically thrown.
206    */

207   public void rollback() throws JMSException JavaDoc
208   {
209     throw new IllegalStateException JavaDoc("Forbidden call on an XA session.");
210   }
211
212   /**
213    * API method inherited from session, but intercepted here for
214    * forbidding its use in the XA context (as defined by the API).
215    *
216    * @exception IllegalStateException Systematically thrown.
217    */

218   public void recover() throws JMSException JavaDoc
219   {
220     throw new IllegalStateException JavaDoc("Forbidden call on an XA session.");
221   }
222
223   /**
224    *
225    * @exception JMSException Actually never thrown.
226    */

227   public void close() throws JMSException JavaDoc {
228     sess.close();
229   }
230   
231   /**
232    *
233    */

234   public void run() {
235     sess.run();
236   }
237
238   public void unsubscribe(String JavaDoc name)
239     throws JMSException JavaDoc {
240     sess.unsubscribe(name);
241   }
242
243   public synchronized javax.jms.TemporaryQueue JavaDoc createTemporaryQueue()
244     throws JMSException JavaDoc {
245     return sess.createTemporaryQueue();
246   }
247
248   public synchronized javax.jms.TemporaryTopic JavaDoc createTemporaryTopic()
249     throws JMSException JavaDoc {
250     return sess.createTemporaryTopic();
251   }
252
253   public synchronized javax.jms.Topic JavaDoc createTopic(
254     String JavaDoc topicName)
255     throws JMSException JavaDoc {
256     return sess.createTopic(topicName);
257   }
258
259   public javax.jms.Queue JavaDoc createQueue(String JavaDoc queueName)
260     throws JMSException JavaDoc {
261     return sess.createQueue(queueName);
262   }
263
264   public void setMessageListener(
265     javax.jms.MessageListener JavaDoc messageListener)
266     throws JMSException JavaDoc {
267     sess.setMessageListener(messageListener);
268   }
269
270   public javax.jms.MessageListener JavaDoc
271       getMessageListener()
272     throws JMSException JavaDoc {
273     return sess.getMessageListener();
274   }
275
276   public int getAcknowledgeMode()
277     throws JMSException JavaDoc {
278     return sess.getAcknowledgeMode();
279   }
280
281   public javax.jms.TextMessage JavaDoc createTextMessage()
282     throws JMSException JavaDoc {
283     return sess.createTextMessage();
284   }
285
286   public javax.jms.TextMessage JavaDoc createTextMessage(String JavaDoc text)
287     throws JMSException JavaDoc {
288     return sess.createTextMessage(text);
289   }
290
291   public javax.jms.StreamMessage JavaDoc createStreamMessage()
292     throws JMSException JavaDoc {
293     return sess.createStreamMessage();
294   }
295
296   public javax.jms.ObjectMessage JavaDoc createObjectMessage()
297     throws JMSException JavaDoc {
298     return sess.createObjectMessage();
299   }
300
301   public javax.jms.ObjectMessage JavaDoc createObjectMessage(java.io.Serializable JavaDoc obj)
302     throws JMSException JavaDoc {
303     return sess.createObjectMessage(obj);
304   }
305
306   public javax.jms.Message JavaDoc createMessage()
307     throws JMSException JavaDoc {
308     return sess.createMessage();
309   }
310
311   public javax.jms.MapMessage JavaDoc createMapMessage()
312     throws JMSException JavaDoc {
313     return sess.createMapMessage();
314   }
315
316   public javax.jms.BytesMessage JavaDoc createBytesMessage()
317     throws JMSException JavaDoc {
318     return sess.createBytesMessage();
319   }
320 }
321
Popular Tags