KickJava   Java API By Example, From Geeks To Geeks.

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


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  * --------------------------------------------------------------------------
23  * $Id: JTopicSession.java,v 1.7 2004/03/19 14:31:48 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_jms;
28
29 import javax.jms.InvalidDestinationException JavaDoc;
30 import javax.jms.JMSException JavaDoc;
31 import javax.jms.Session JavaDoc;
32 import javax.jms.TemporaryTopic JavaDoc;
33 import javax.jms.Topic JavaDoc;
34 import javax.jms.TopicPublisher JavaDoc;
35 import javax.jms.TopicSession JavaDoc;
36 import javax.jms.TopicSubscriber JavaDoc;
37 import javax.jms.XATopicConnection JavaDoc;
38 import javax.jms.XATopicSession JavaDoc;
39 import javax.transaction.RollbackException JavaDoc;
40 import javax.transaction.SystemException JavaDoc;
41 import javax.transaction.Transaction JavaDoc;
42
43 import org.objectweb.util.monolog.api.BasicLevel;
44 /**
45  * @author Laurent Chauvirey, Frederic Maistre, Nicolas Tachker
46  * Contributor(s):
47  * Philippe Durieux
48  * Philippe Coq
49  */

50
51 public class JTopicSession extends JSession implements TopicSession JavaDoc {
52
53     // Underlaying Objects
54
protected XATopicConnection JavaDoc xatc;
55     protected TopicSession JavaDoc ts = null;
56     protected XATopicSession JavaDoc xats = null;
57
58     /**
59      * Constructor
60      */

61     public JTopicSession(JConnection jconn, XATopicConnection JavaDoc xatc) {
62     super(jconn);
63     this.xatc = xatc;
64     }
65
66     // -----------------------------------------------------------------------
67
// Internal Methods
68
// -----------------------------------------------------------------------
69

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

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

133     /**
134      *
135      */

136     public Topic JavaDoc createTopic(String JavaDoc topicName) throws JMSException JavaDoc {
137     TraceJms.logger.log(BasicLevel.DEBUG, "");
138     return getMOMTopicSession().createTopic(topicName);
139     }
140
141     /**
142      *
143      */

144     public TopicSubscriber JavaDoc createSubscriber(Topic JavaDoc topic)
145     throws JMSException JavaDoc{
146     TraceJms.logger.log(BasicLevel.DEBUG, "");
147     return getMOMTopicSession().createSubscriber(topic);
148     }
149     
150     /**
151      *
152      */

153     public TopicSubscriber JavaDoc createSubscriber(Topic JavaDoc topic,
154                         String JavaDoc messageSelector,
155                         boolean noLocal) throws JMSException JavaDoc {
156     TraceJms.logger.log(BasicLevel.DEBUG, "");
157     return getMOMTopicSession().createSubscriber(topic, messageSelector, noLocal);
158     }
159
160     /**
161      *
162      */

163     public TopicSubscriber JavaDoc createDurableSubscriber(Topic JavaDoc topic,
164                            String JavaDoc name) throws JMSException JavaDoc {
165     TraceJms.logger.log(BasicLevel.DEBUG, "");
166     return getMOMTopicSession().createDurableSubscriber(topic, name);
167     }
168  
169     /**
170      *
171      */

172     public TopicSubscriber JavaDoc createDurableSubscriber(Topic JavaDoc topic,
173                            String JavaDoc name,
174                            String JavaDoc messageSelector,
175                            boolean noLocal) throws JMSException JavaDoc{
176     TraceJms.logger.log(BasicLevel.DEBUG, "");
177     return getMOMTopicSession().createDurableSubscriber(topic, name, messageSelector, noLocal);
178     }
179    
180     /**
181      *
182      */

183     public TopicPublisher JavaDoc createPublisher(Topic JavaDoc topic) throws JMSException JavaDoc {
184     TraceJms.logger.log(BasicLevel.DEBUG, "");
185     return getMOMTopicSession().createPublisher(topic);
186     }
187
188     /**
189      *
190      */

191     public TemporaryTopic JavaDoc createTemporaryTopic() throws JMSException JavaDoc {
192     TraceJms.logger.log(BasicLevel.DEBUG, "");
193     return getMOMTopicSession().createTemporaryTopic();
194     }
195   
196     /**
197      *
198      */

199     public void unsubscribe(java.lang.String JavaDoc name) throws JMSException JavaDoc, InvalidDestinationException JavaDoc {
200     TraceJms.logger.log(BasicLevel.DEBUG, "");
201     getMOMTopicSession().unsubscribe(name);
202     }
203 }
204
Popular Tags