JTopicSession.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  * --------------------------------------------------------------------------
00023  * $Id: JTopicSession.java,v 1.7 2004/03/19 14:31:48 sauthieg Exp $
00024  * --------------------------------------------------------------------------
00025  */
00026 
00027 package org.objectweb.jonas_jms;
00028 
00029 import javax.jms.InvalidDestinationException;
00030 import javax.jms.JMSException;
00031 import javax.jms.Session;
00032 import javax.jms.TemporaryTopic;
00033 import javax.jms.Topic;
00034 import javax.jms.TopicPublisher;
00035 import javax.jms.TopicSession;
00036 import javax.jms.TopicSubscriber;
00037 import javax.jms.XATopicConnection;
00038 import javax.jms.XATopicSession;
00039 import javax.transaction.RollbackException;
00040 import javax.transaction.SystemException;
00041 import javax.transaction.Transaction;
00042 
00043 import org.objectweb.util.monolog.api.BasicLevel;
00051 public class JTopicSession extends JSession implements TopicSession {
00052 
00053     // Underlaying Objects
00054     protected XATopicConnection xatc;
00055     protected TopicSession ts = null;
00056     protected XATopicSession xats = null;
00057 
00061     public JTopicSession(JConnection jconn, XATopicConnection xatc) {
00062         super(jconn);
00063         this.xatc = xatc;
00064     }
00065 
00066     // -----------------------------------------------------------------------
00067     // Internal Methods
00068     // -----------------------------------------------------------------------
00069 
00073     protected Session getMOMSession() throws JMSException {
00074         return getMOMTopicSession();
00075     }
00076 
00077     protected TopicSession getMOMTopicSession() throws JMSException {
00078         Transaction tx = null;
00079         try {
00080             tx = tm.getTransaction();
00081         } catch (SystemException e) {
00082             TraceJms.logger.log(BasicLevel.ERROR,"cannot get Transaction");
00083         }
00084         if (tx == null) {
00085             if (ts == null) {
00086                 ts = xatc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
00087                 jconn.sessionOpen(this);
00088             }
00089             return ts;
00090         } else {
00091             if (xats == null) {
00092                 xats = xatc.createXATopicSession();
00093                 if (currtx != null) {
00094                     TraceJms.logger.log(BasicLevel.ERROR,"mixed transactions");
00095                 }
00096                 currtx = tx;
00097                 xares = xats.getXAResource();
00098                 try {
00099                     tx.enlistResource(this.getXAResource());
00100             txover = false;
00101                 } catch (SystemException e) {
00102                     TraceJms.logger.log(BasicLevel.ERROR,"cannot enlist session:"+e);
00103                     throw new JMSException(e.toString());
00104                 } catch (RollbackException e) {
00105                     TraceJms.logger.log(BasicLevel.DEBUG,"transaction rolled back");
00106                     throw new JMSException(e.toString());
00107                 }
00108             } 
00109             return xats.getTopicSession();
00110         }
00111     }
00112 
00113     protected void MOMSessionClose() {
00114         try {
00115             if (xats != null) {
00116                 xats.close();
00117                 xats = null;
00118             }
00119             if (ts != null) {
00120                 ts.close();
00121                 ts = null;
00122                 jconn.sessionClose(this);
00123             }
00124         } catch (JMSException e) {
00125             TraceJms.logger.log(BasicLevel.ERROR,"exception:"+e);
00126         }
00127     }
00128 
00129     // -----------------------------------------------------------------------
00130     // TopicSession Implementation
00131     // -----------------------------------------------------------------------
00132 
00136     public Topic createTopic(String topicName) throws JMSException {
00137         TraceJms.logger.log(BasicLevel.DEBUG, "");
00138         return getMOMTopicSession().createTopic(topicName);
00139     }
00140 
00144     public TopicSubscriber createSubscriber(Topic topic) 
00145         throws JMSException{
00146         TraceJms.logger.log(BasicLevel.DEBUG, "");
00147         return getMOMTopicSession().createSubscriber(topic);
00148     }
00149     
00153     public TopicSubscriber createSubscriber(Topic topic, 
00154                                             String messageSelector, 
00155                                             boolean noLocal) throws JMSException {
00156         TraceJms.logger.log(BasicLevel.DEBUG, "");
00157         return getMOMTopicSession().createSubscriber(topic, messageSelector, noLocal);
00158     }
00159 
00163     public TopicSubscriber createDurableSubscriber(Topic topic, 
00164                                                    String name) throws JMSException {
00165         TraceJms.logger.log(BasicLevel.DEBUG, "");
00166         return getMOMTopicSession().createDurableSubscriber(topic, name);
00167     }
00168  
00172     public TopicSubscriber createDurableSubscriber(Topic topic, 
00173                                                    String name, 
00174                                                    String messageSelector, 
00175                                                    boolean noLocal) throws JMSException{ 
00176         TraceJms.logger.log(BasicLevel.DEBUG, "");
00177         return getMOMTopicSession().createDurableSubscriber(topic, name, messageSelector, noLocal);
00178     }
00179    
00183     public TopicPublisher createPublisher(Topic topic) throws JMSException {
00184         TraceJms.logger.log(BasicLevel.DEBUG, "");
00185         return getMOMTopicSession().createPublisher(topic);
00186     }
00187 
00191     public TemporaryTopic createTemporaryTopic() throws JMSException {
00192         TraceJms.logger.log(BasicLevel.DEBUG, "");
00193         return getMOMTopicSession().createTemporaryTopic();
00194     }
00195   
00199     public void unsubscribe(java.lang.String name) throws JMSException, InvalidDestinationException {
00200         TraceJms.logger.log(BasicLevel.DEBUG, "");
00201         getMOMTopicSession().unsubscribe(name);
00202     }
00203 }

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