KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_jms > JQueueSession


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JQueueSession.java,v 1.7 2004/03/19 14:31:48 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_jms;
27
28 import javax.jms.JMSException JavaDoc;
29 import javax.jms.Queue JavaDoc;
30 import javax.jms.QueueBrowser JavaDoc;
31 import javax.jms.QueueReceiver JavaDoc;
32 import javax.jms.QueueSender JavaDoc;
33 import javax.jms.QueueSession JavaDoc;
34 import javax.jms.Session JavaDoc;
35 import javax.jms.TemporaryQueue JavaDoc;
36 import javax.jms.XAQueueConnection JavaDoc;
37 import javax.jms.XAQueueSession JavaDoc;
38 import javax.transaction.RollbackException JavaDoc;
39 import javax.transaction.SystemException JavaDoc;
40 import javax.transaction.Transaction JavaDoc;
41
42 import org.objectweb.util.monolog.api.BasicLevel;
43
44 /**
45  * @author Laurent Chauvirey, Frederic Maistre, Nicolas Tachker
46  * Contributor(s):
47  * Philippe Durieux
48  * Philippe Coq
49  */

50 public class JQueueSession extends JSession implements QueueSession JavaDoc {
51
52     // Underlaying Objects
53
protected XAQueueConnection JavaDoc xaqc;
54     protected QueueSession JavaDoc qs = null;
55     protected XAQueueSession JavaDoc xaqs = null;
56     
57     /**
58      * Constructor
59      */

60     public JQueueSession(JConnection jconn, XAQueueConnection JavaDoc xaqc) {
61     super(jconn);
62     this.xaqc = xaqc;
63     }
64
65     // -----------------------------------------------------------------------
66
// Internal Methods
67
// -----------------------------------------------------------------------
68

69     /**
70      * Get the underlaying MOM Session.
71      */

72     protected Session JavaDoc getMOMSession() throws JMSException JavaDoc {
73     return getMOMQueueSession();
74     }
75
76     protected QueueSession JavaDoc getMOMQueueSession() throws JMSException JavaDoc {
77     Transaction JavaDoc tx = null;
78     try {
79         tx = tm.getTransaction();
80     } catch (SystemException JavaDoc e) {
81         TraceJms.logger.log(BasicLevel.ERROR,"cannot get Transaction");
82     }
83     if (tx == null) {
84         if (qs == null) {
85         qs = xaqc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
86         jconn.sessionOpen(this);
87         }
88         return qs;
89     } else {
90         if (xaqs == null) {
91         xaqs = xaqc.createXAQueueSession();
92         if (currtx != null) {
93             TraceJms.logger.log(BasicLevel.ERROR,"mixed transactions");
94         }
95         currtx = tx;
96         xares = xaqs.getXAResource();
97         try {
98             tx.enlistResource(this.getXAResource());
99             txover = false;
100         } catch (SystemException JavaDoc e) {
101             TraceJms.logger.log(BasicLevel.ERROR,"cannot enlist session:"+e);
102             throw new JMSException JavaDoc(e.toString());
103         } catch (RollbackException JavaDoc e) {
104             TraceJms.logger.log(BasicLevel.ERROR,"transaction rolled back");
105             throw new JMSException JavaDoc(e.toString());
106         }
107         }
108         return xaqs.getQueueSession();
109     }
110     }
111
112     protected void MOMSessionClose() {
113     try {
114         if (xaqs != null) {
115         xaqs.close();
116         xaqs = null;
117         }
118         if (qs != null) {
119         qs.close();
120         qs = null;
121         jconn.sessionClose(this);
122         }
123     } catch (JMSException JavaDoc e) {
124         TraceJms.logger.log(BasicLevel.ERROR,"exception:"+e);
125     }
126     }
127
128     // -----------------------------------------------------------------------
129
// QueueSession Implementation
130
// -----------------------------------------------------------------------
131

132     /**
133      *
134      */

135     public QueueBrowser JavaDoc createBrowser(Queue JavaDoc queue) throws JMSException JavaDoc {
136     TraceJms.logger.log(BasicLevel.DEBUG, "");
137     return getMOMQueueSession().createBrowser(queue);
138     }
139
140     /**
141      *
142      */

143     public QueueBrowser JavaDoc createBrowser(Queue JavaDoc queue, String JavaDoc messageSelector) throws JMSException JavaDoc {
144     TraceJms.logger.log(BasicLevel.DEBUG, "");
145     return getMOMQueueSession().createBrowser(queue, messageSelector);
146     }
147
148     /**
149      *
150      */

151     public Queue JavaDoc createQueue(String JavaDoc queueName) throws JMSException JavaDoc {
152     TraceJms.logger.log(BasicLevel.DEBUG, "");
153     return getMOMQueueSession().createQueue(queueName);
154     }
155
156     /**
157      *
158      */

159     public QueueReceiver JavaDoc createReceiver(Queue JavaDoc queue) throws JMSException JavaDoc {
160     TraceJms.logger.log(BasicLevel.DEBUG, "");
161     return getMOMQueueSession().createReceiver(queue);
162     }
163
164     /**
165      *
166      */

167     public QueueReceiver JavaDoc createReceiver(Queue JavaDoc queue, String JavaDoc messageSelector) throws JMSException JavaDoc {
168     TraceJms.logger.log(BasicLevel.DEBUG, "");
169     return getMOMQueueSession().createReceiver(queue, messageSelector);
170     }
171     
172     /**
173      *
174      */

175     public QueueSender JavaDoc createSender(Queue JavaDoc queue) throws JMSException JavaDoc {
176     TraceJms.logger.log(BasicLevel.DEBUG, "");
177     return getMOMQueueSession().createSender(queue);
178     }
179
180     /**
181      *
182      */

183     public TemporaryQueue JavaDoc createTemporaryQueue() throws JMSException JavaDoc {
184     TraceJms.logger.log(BasicLevel.DEBUG, "");
185     return getMOMQueueSession().createTemporaryQueue();
186     }
187
188
189 }
190
Popular Tags