JQueueSession.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: JQueueSession.java,v 1.7 2004/03/19 14:31:48 sauthieg Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas_jms;
00027 
00028 import javax.jms.JMSException;
00029 import javax.jms.Queue;
00030 import javax.jms.QueueBrowser;
00031 import javax.jms.QueueReceiver;
00032 import javax.jms.QueueSender;
00033 import javax.jms.QueueSession;
00034 import javax.jms.Session;
00035 import javax.jms.TemporaryQueue;
00036 import javax.jms.XAQueueConnection;
00037 import javax.jms.XAQueueSession;
00038 import javax.transaction.RollbackException;
00039 import javax.transaction.SystemException;
00040 import javax.transaction.Transaction;
00041 
00042 import org.objectweb.util.monolog.api.BasicLevel;
00043 
00050 public class JQueueSession extends JSession implements QueueSession {
00051 
00052     // Underlaying Objects
00053     protected XAQueueConnection xaqc;
00054     protected QueueSession qs = null;
00055     protected XAQueueSession xaqs = null;
00056     
00060     public JQueueSession(JConnection jconn, XAQueueConnection xaqc) {
00061         super(jconn);
00062         this.xaqc = xaqc;
00063     }
00064 
00065     // -----------------------------------------------------------------------
00066     // Internal Methods
00067     // -----------------------------------------------------------------------
00068 
00072     protected Session getMOMSession() throws JMSException {
00073         return getMOMQueueSession();
00074     }
00075 
00076     protected QueueSession getMOMQueueSession() throws JMSException {
00077         Transaction tx = null;
00078         try {
00079             tx = tm.getTransaction();
00080         } catch (SystemException e) {
00081             TraceJms.logger.log(BasicLevel.ERROR,"cannot get Transaction");
00082         }
00083         if (tx == null) {
00084             if (qs == null) {
00085                 qs = xaqc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
00086                 jconn.sessionOpen(this);
00087             }
00088             return qs;
00089         } else {
00090             if (xaqs == null) {
00091                 xaqs = xaqc.createXAQueueSession();
00092                 if (currtx != null) {
00093                     TraceJms.logger.log(BasicLevel.ERROR,"mixed transactions");
00094                 }
00095                 currtx = tx;
00096                 xares = xaqs.getXAResource();
00097                 try {
00098                     tx.enlistResource(this.getXAResource());
00099             txover = false;
00100                 } catch (SystemException e) {
00101                     TraceJms.logger.log(BasicLevel.ERROR,"cannot enlist session:"+e);
00102                     throw new JMSException(e.toString());
00103                 } catch (RollbackException e) {
00104                     TraceJms.logger.log(BasicLevel.ERROR,"transaction rolled back");
00105                     throw new JMSException(e.toString());
00106                 }
00107             } 
00108             return xaqs.getQueueSession();
00109         }
00110     }
00111 
00112     protected void MOMSessionClose() {
00113         try {
00114             if (xaqs != null) {
00115                 xaqs.close();
00116                 xaqs = null;
00117             }
00118             if (qs != null) {
00119                 qs.close();
00120                 qs = null;
00121                 jconn.sessionClose(this);
00122             }
00123         } catch (JMSException e) {
00124             TraceJms.logger.log(BasicLevel.ERROR,"exception:"+e);
00125         }
00126     }
00127 
00128     // -----------------------------------------------------------------------
00129     // QueueSession Implementation
00130     // -----------------------------------------------------------------------
00131 
00135     public QueueBrowser createBrowser(Queue queue) throws JMSException {
00136         TraceJms.logger.log(BasicLevel.DEBUG, "");
00137         return getMOMQueueSession().createBrowser(queue);
00138     }
00139 
00143     public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException {
00144         TraceJms.logger.log(BasicLevel.DEBUG, "");
00145         return getMOMQueueSession().createBrowser(queue, messageSelector);
00146     }
00147 
00151     public Queue createQueue(String queueName) throws JMSException {
00152         TraceJms.logger.log(BasicLevel.DEBUG, "");
00153         return getMOMQueueSession().createQueue(queueName);
00154     }
00155 
00159     public QueueReceiver createReceiver(Queue queue) throws JMSException {
00160         TraceJms.logger.log(BasicLevel.DEBUG, "");
00161         return getMOMQueueSession().createReceiver(queue);
00162     }
00163 
00167     public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException {
00168         TraceJms.logger.log(BasicLevel.DEBUG, "");
00169         return getMOMQueueSession().createReceiver(queue, messageSelector);
00170     }
00171     
00175     public QueueSender createSender(Queue queue) throws JMSException {
00176         TraceJms.logger.log(BasicLevel.DEBUG, "");
00177         return getMOMQueueSession().createSender(queue);
00178     }
00179 
00183     public TemporaryQueue createTemporaryQueue() throws JMSException {
00184         TraceJms.logger.log(BasicLevel.DEBUG, "");
00185         return getMOMQueueSession().createTemporaryQueue();
00186     }
00187 
00188 
00189 }

Generated on Tue Feb 15 15:05:50 2005 for JOnAS by  doxygen 1.3.9.1