001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JQueueSession.java 4408 2004-03-19 14:31:54Z sauthieg $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas_jms;
027:
028: import javax.jms.JMSException;
029: import javax.jms.Queue;
030: import javax.jms.QueueBrowser;
031: import javax.jms.QueueReceiver;
032: import javax.jms.QueueSender;
033: import javax.jms.QueueSession;
034: import javax.jms.Session;
035: import javax.jms.TemporaryQueue;
036: import javax.jms.XAQueueConnection;
037: import javax.jms.XAQueueSession;
038: import javax.transaction.RollbackException;
039: import javax.transaction.SystemException;
040: import javax.transaction.Transaction;
041:
042: import org.objectweb.util.monolog.api.BasicLevel;
043:
044: /**
045: * @author Laurent Chauvirey, Frederic Maistre, Nicolas Tachker
046: * Contributor(s):
047: * Philippe Durieux
048: * Philippe Coq
049: */
050: public class JQueueSession extends JSession implements QueueSession {
051:
052: // Underlaying Objects
053: protected XAQueueConnection xaqc;
054: protected QueueSession qs = null;
055: protected XAQueueSession xaqs = null;
056:
057: /**
058: * Constructor
059: */
060: public JQueueSession(JConnection jconn, XAQueueConnection xaqc) {
061: super (jconn);
062: this .xaqc = xaqc;
063: }
064:
065: // -----------------------------------------------------------------------
066: // Internal Methods
067: // -----------------------------------------------------------------------
068:
069: /**
070: * Get the underlaying MOM Session.
071: */
072: protected Session getMOMSession() throws JMSException {
073: return getMOMQueueSession();
074: }
075:
076: protected QueueSession getMOMQueueSession() throws JMSException {
077: Transaction tx = null;
078: try {
079: tx = tm.getTransaction();
080: } catch (SystemException e) {
081: TraceJms.logger.log(BasicLevel.ERROR,
082: "cannot get Transaction");
083: }
084: if (tx == null) {
085: if (qs == null) {
086: qs = xaqc.createQueueSession(false,
087: Session.AUTO_ACKNOWLEDGE);
088: jconn.sessionOpen(this );
089: }
090: return qs;
091: } else {
092: if (xaqs == null) {
093: xaqs = xaqc.createXAQueueSession();
094: if (currtx != null) {
095: TraceJms.logger.log(BasicLevel.ERROR,
096: "mixed transactions");
097: }
098: currtx = tx;
099: xares = xaqs.getXAResource();
100: try {
101: tx.enlistResource(this .getXAResource());
102: txover = false;
103: } catch (SystemException e) {
104: TraceJms.logger.log(BasicLevel.ERROR,
105: "cannot enlist session:" + e);
106: throw new JMSException(e.toString());
107: } catch (RollbackException e) {
108: TraceJms.logger.log(BasicLevel.ERROR,
109: "transaction rolled back");
110: throw new JMSException(e.toString());
111: }
112: }
113: return xaqs.getQueueSession();
114: }
115: }
116:
117: protected void MOMSessionClose() {
118: try {
119: if (xaqs != null) {
120: xaqs.close();
121: xaqs = null;
122: }
123: if (qs != null) {
124: qs.close();
125: qs = null;
126: jconn.sessionClose(this );
127: }
128: } catch (JMSException e) {
129: TraceJms.logger.log(BasicLevel.ERROR, "exception:" + e);
130: }
131: }
132:
133: // -----------------------------------------------------------------------
134: // QueueSession Implementation
135: // -----------------------------------------------------------------------
136:
137: /**
138: *
139: */
140: public QueueBrowser createBrowser(Queue queue) throws JMSException {
141: TraceJms.logger.log(BasicLevel.DEBUG, "");
142: return getMOMQueueSession().createBrowser(queue);
143: }
144:
145: /**
146: *
147: */
148: public QueueBrowser createBrowser(Queue queue,
149: String messageSelector) throws JMSException {
150: TraceJms.logger.log(BasicLevel.DEBUG, "");
151: return getMOMQueueSession().createBrowser(queue,
152: messageSelector);
153: }
154:
155: /**
156: *
157: */
158: public Queue createQueue(String queueName) throws JMSException {
159: TraceJms.logger.log(BasicLevel.DEBUG, "");
160: return getMOMQueueSession().createQueue(queueName);
161: }
162:
163: /**
164: *
165: */
166: public QueueReceiver createReceiver(Queue queue)
167: throws JMSException {
168: TraceJms.logger.log(BasicLevel.DEBUG, "");
169: return getMOMQueueSession().createReceiver(queue);
170: }
171:
172: /**
173: *
174: */
175: public QueueReceiver createReceiver(Queue queue,
176: String messageSelector) throws JMSException {
177: TraceJms.logger.log(BasicLevel.DEBUG, "");
178: return getMOMQueueSession().createReceiver(queue,
179: messageSelector);
180: }
181:
182: /**
183: *
184: */
185: public QueueSender createSender(Queue queue) throws JMSException {
186: TraceJms.logger.log(BasicLevel.DEBUG, "");
187: return getMOMQueueSession().createSender(queue);
188: }
189:
190: /**
191: *
192: */
193: public TemporaryQueue createTemporaryQueue() throws JMSException {
194: TraceJms.logger.log(BasicLevel.DEBUG, "");
195: return getMOMQueueSession().createTemporaryQueue();
196: }
197:
198: }
|