View Javadoc

1   /***
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Exoffice Technologies.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Exoffice Technologies. Exolab is a registered
23   *    trademark of Exoffice Technologies.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 2000-2005 (C) Exoffice Technologies Inc. All Rights Reserved.
42   *
43   * $Id: JmsTopicSession.java,v 1.2 2005/03/18 03:36:37 tanderson Exp $
44   */
45  package org.exolab.jms.client;
46  
47  import javax.jms.JMSException;
48  import javax.jms.Queue;
49  import javax.jms.QueueBrowser;
50  import javax.jms.TemporaryQueue;
51  import javax.jms.Topic;
52  import javax.jms.TopicPublisher;
53  import javax.jms.TopicSession;
54  import javax.jms.TopicSubscriber;
55  
56  
57  /***
58   * Client implementation of the <code>javax.jms.TopicSession</code> interface.
59   *
60   * @author <a href="mailto:jima@comware.com.au">Jim Alateras</a>
61   * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
62   * @version $Revision: 1.2 $ $Date: 2005/03/18 03:36:37 $
63   */
64  class JmsTopicSession
65          extends JmsSession
66          implements TopicSession {
67  
68      /***
69       * Construct a new <code>JmsTopicSession</code>.
70       *
71       * @param connection the owner of the session
72       * @param transacted if <code>true</code>, the session is transacted.
73       * @param ackMode    indicates whether the consumer or the client will
74       *                   acknowledge any messages it receives. This parameter
75       *                   will be ignored if the session is transacted. Legal
76       *                   values are <code>Session.AUTO_ACKNOWLEDGE</code>,
77       *                   <code>Session.CLIENT_ACKNOWLEDGE</code> and
78       *                   <code>Session.DUPS_OK_ACKNOWLEDGE</code>.
79       * @throws JMSException if the session cannot be created
80       */
81      public JmsTopicSession(JmsTopicConnection connection, boolean transacted,
82                             int ackMode) throws JMSException {
83          super(connection, transacted, ackMode);
84      }
85  
86      /***
87       * Create a non-durable subscriber for the specified topic.
88       *
89       * @param topic the topic to subscriber to
90       * @return the new subscriber
91       * @throws JMSException if the subscriber cannot be created
92       */
93      public TopicSubscriber createSubscriber(Topic topic) throws JMSException {
94          return createSubscriber(topic, null, false);
95      }
96  
97      /***
98       * Create a non-durable subscriber for the specified topic.
99       *
100      * @param topic    the topic to subscriber to
101      * @param selector the message selector to filter messages. May be
102      *                 <code>null</code>
103      * @param noLocal  if <code>true</code>, inhibits the delivery of messages
104      *                 published by its own connection
105      * @return the new subscriber
106      * @throws JMSException if the subscriber cannot be created
107      */
108     public synchronized TopicSubscriber createSubscriber(Topic topic,
109                                                          String selector,
110                                                          boolean noLocal)
111             throws JMSException {
112         long consumerId = allocateConsumer(topic, selector, noLocal);
113         JmsTopicSubscriber subscriber = new JmsTopicSubscriber(this,
114                                                                consumerId,
115                                                                topic, selector,
116                                                                noLocal);
117         addConsumer(subscriber);
118         return subscriber;
119     }
120 
121     /***
122      * Create a publisher for the specified topic.
123      *
124      * @param topic the topic to publish to, or <code>null</code> if this is an
125      *              unidentified producer
126      * @return the new publisher
127      * @throws JMSException if the publisher can't be created
128      */
129     public synchronized TopicPublisher createPublisher(Topic topic)
130             throws JMSException {
131 
132         ensureOpen();
133 
134         if (topic != null && ((JmsTopic) topic).isWildCard()) {
135             throw new JMSException(
136                     "Cannot create a publisher using a wildcard topic");
137         }
138 
139         JmsTopicPublisher publisher =
140                 new JmsTopicPublisher(this, (JmsTopic) topic);
141         addProducer(publisher);
142 
143         return publisher;
144     }
145 
146     /***
147      * This implementation always throws <code>IllegalStateException</code>, as
148      * per section 4.11 of the JMS specification.
149      *
150      * @throws IllegalStateException if invoked
151      */
152     public QueueBrowser createBrowser(Queue queue, String messageSelector)
153             throws JMSException {
154         throw new IllegalStateException("Invalid operation for TopicSession");
155     }
156 
157     /***
158      * This implementation always throws <code>IllegalStateException</code>, as
159      * per section 4.11 of the JMS specification
160      *
161      * @throws IllegalStateException if invoked.
162      */
163     public TemporaryQueue createTemporaryQueue() throws JMSException {
164         throw new IllegalStateException("Invalid operation for TopicSession");
165     }
166 
167     /***
168      * This implementation always throws <code>IllegalStateException</code>, as
169      * per section 4.11 of the JMS specification
170      *
171      * @throws IllegalStateException if invoked.
172      */
173     public Queue createQueue(String queueName) throws JMSException {
174         throw new IllegalStateException("Invalid operation for TopicSession");
175     }
176 
177 }
178