KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > presumo > jms > client > JmsTopicSession


1 /**
2  * This file is part of Presumo.
3  *
4  * Presumo is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Presumo is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Presumo; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  *
19  * Copyright 2001 Dan Greff
20  */

21 package com.presumo.jms.client;
22
23 import com.presumo.jms.resources.Resources;
24 import com.presumo.jms.router.Router;
25 import com.presumo.util.log.Logger;
26 import com.presumo.util.log.LoggerFactory;
27
28 import javax.jms.InvalidDestinationException JavaDoc;
29 import javax.jms.JMSException JavaDoc;
30 import javax.jms.Topic JavaDoc;
31 import javax.jms.TopicSession JavaDoc;
32 import javax.jms.TopicSubscriber JavaDoc;
33 import javax.jms.TopicPublisher JavaDoc;
34 import javax.jms.TemporaryTopic JavaDoc;
35
36
37 /**
38  * Implementation of the interface <code>javax.jms.TopicSession</code>.
39  *
40  * @author Dan Greff
41  */

42 public final class JmsTopicSession extends JmsSession
43   implements TopicSession JavaDoc
44 {
45
46     /////////////////////////////////////////////////////////////////////////
47
// Constructors //
48
/////////////////////////////////////////////////////////////////////////
49

50   public JmsTopicSession(Router router,
51                          boolean transacted,
52                          int acknowledgeMode,
53                          JmsConnection connx)
54       throws JMSException JavaDoc
55   {
56     super(router, transacted, acknowledgeMode, connx);
57     
58     logger.entry("JmsTopicSession");
59     logger.exit("JmsTopicSession");
60   }
61     
62
63
64     /////////////////////////////////////////////////////////////////////////
65
// Public Methods //
66
/////////////////////////////////////////////////////////////////////////
67

68      
69   /**
70    * Creates a topic from the given string. The topic name
71    * can contain a wildcard represented by a "*".
72    */

73   public Topic JavaDoc createTopic(String JavaDoc topicName) throws JMSException JavaDoc
74   {
75     logger.entry("createTopic");
76     
77     JmsTopic retval = new JmsTopic(topicName);
78  
79     logger.exit("createTopic");
80     return retval;
81   }
82
83    
84   public TopicSubscriber JavaDoc createSubscriber(Topic JavaDoc topic)
85     throws JMSException JavaDoc
86   {
87     logger.entry("createSubscriber", topic);
88     
89     TopicSubscriber JavaDoc sub = createSubscriber(topic, null, false);
90
91     logger.exit("createSubscriber", sub);
92     return sub;
93   }
94   
95   /**
96    *
97    */

98   public TopicSubscriber JavaDoc createSubscriber(Topic JavaDoc topic,
99                                           String JavaDoc messageSelector,
100                                           boolean noLocal)
101     throws JMSException JavaDoc
102   {
103     logger.entry("createSubscriber", new Object JavaDoc []
104                  {topic, messageSelector, new Boolean JavaDoc(noLocal)});
105     
106     JmsTopicSubscriber subscriber = null;
107
108     if (! (topic instanceof JmsTopic)) throw new
109         InvalidDestinationException JavaDoc("Topic must be from this implementation");
110     if (closed) throw new
111         IllegalStateException JavaDoc("Operation attempted on a closed object");
112     
113     subscriber = new JmsTopicSubscriber(this, messageSelector,
114                                         (JmsTopic) topic, noLocal, null);
115     
116     logger.exit("createSubscriber", subscriber);
117     return subscriber;
118   }
119
120   /**
121    * Not Implemented (yet).
122    */

123   public TopicSubscriber JavaDoc createDurableSubscriber(Topic JavaDoc topic, String JavaDoc name)
124     throws JMSException JavaDoc
125   {
126     logger.entry("createDurableSubscriber", topic, name);
127     
128     TopicSubscriber JavaDoc sub = createDurableSubscriber(topic, name, null, false);
129
130     logger.exit("createDurableSubscriber", sub);
131     return sub;
132   }
133
134
135   /**
136    * Not Implemented (yet).
137    */

138   public TopicSubscriber JavaDoc createDurableSubscriber(Topic JavaDoc topic,
139                                                  String JavaDoc name,
140                                                  String JavaDoc messageSelector,
141                                                  boolean noLocal)
142     throws JMSException JavaDoc
143   {
144     if (logger.isDebugEnabled())
145       logger.entry("createDurableSubscriber", new Object JavaDoc []
146                    {topic, name, messageSelector, new Boolean JavaDoc(noLocal)});
147     
148     JmsTopicSubscriber subscriber = null;
149
150     if (! (topic instanceof JmsTopic)) throw new
151         InvalidDestinationException JavaDoc("Topic must be from this implementation");
152     if (closed) throw new
153         IllegalStateException JavaDoc("Operation attempted on a closed object");
154     if (name == null || name.length() == 0)
155         throw new JMSException JavaDoc("Durable subscriber id can not be null.");
156
157     subscriber = new JmsTopicSubscriber(this, messageSelector,
158                                         (JmsTopic) topic, noLocal, name);
159     
160     logger.exit("createSubscriber", subscriber);
161     return subscriber;
162   }
163
164
165   /**
166    *
167    */

168   public TopicPublisher JavaDoc createPublisher(Topic JavaDoc topic)
169     throws JMSException JavaDoc
170   {
171     logger.entry("createPublisher");
172     
173     if (! (topic instanceof JmsTopic)) throw new
174         InvalidDestinationException JavaDoc("Topic must be from this implementation");
175     if (closed) throw new
176         IllegalStateException JavaDoc("Operation attempted on a closed object");
177
178     TopicPublisher JavaDoc pub = new JmsTopicPublisher(this, (JmsTopic) topic);
179     
180     logger.exit("createPublisher");
181     return pub;
182   }
183
184
185   /**
186    * Not Implemented.
187    */

188   public TemporaryTopic JavaDoc createTemporaryTopic() throws JMSException JavaDoc
189   {
190     throw new JMSException JavaDoc("Operation not implemented");
191   }
192
193
194   /**
195    *
196    */

197   public void unsubscribe(String JavaDoc name) throws JMSException JavaDoc
198   {
199     if (name == null || name.length() == 0)
200       throw new IllegalArgumentException JavaDoc("null or zero length argument");
201     
202     sendQueueRequest(name, null, null, DURABLE_SUBSCRIBER_DELETE);
203   }
204   
205   ////////////////////////////// Misc stuff ////////////////////////////////
206
private static Logger logger =
207     LoggerFactory.getLogger(JmsTopicSession.class, Resources.getBundle());
208   ///////////////////////////////////////////////////////////////////////////
209

210 }
211
212
213
214
215
Popular Tags