1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.jms;
  6. /** A <CODE>TopicSession</CODE> object provides methods for creating
  7. * <CODE>TopicPublisher</CODE>, <CODE>TopicSubscriber</CODE>, and
  8. * <CODE>TemporaryTopic</CODE> objects. It also provides a method for
  9. * deleting its client's durable subscribers.
  10. *
  11. * @version 1.0 - 4 August 1998
  12. * @author Mark Hapner
  13. * @author Rich Burridge
  14. *
  15. * @see javax.jms.Session
  16. * @see javax.jms.TopicConnection#createTopicSession(boolean, int)
  17. * @see javax.jms.XATopicSession#getTopicSession()
  18. */
  19. public interface TopicSession extends Session {
  20. /** Creates a topic identity given a <CODE>Topic</CODE> name.
  21. *
  22. * <P>This facility is provided for the rare cases where clients need to
  23. * dynamically manipulate topic identity. This allows the creation of a
  24. * topic identity with a provider-specific name. Clients that depend
  25. * on this ability are not portable.
  26. *
  27. * <P>Note that this method is not for creating the physical topic.
  28. * The physical creation of topics is an administrative task and is not
  29. * to be initiated by the JMS API. The one exception is the
  30. * creation of temporary topics, which is accomplished with the
  31. * <CODE>createTemporaryTopic</CODE> method.
  32. *
  33. * @param topicName the name of this <CODE>Topic</CODE>
  34. *
  35. * @return a <CODE>Topic</CODE> with the given name
  36. *
  37. * @exception JMSException if the session fails to create a topic
  38. * due to some internal error.
  39. */
  40. Topic
  41. createTopic(String topicName) throws JMSException;
  42. /** Creates a nondurable subscriber to the specified topic.
  43. *
  44. * <P>A client uses a <CODE>TopicSubscriber</CODE> object to receive
  45. * messages that have been published to a topic.
  46. *
  47. * <P>Regular <CODE>TopicSubscriber</CODE> objects are not durable.
  48. * They receive only messages that are published while they are active.
  49. *
  50. * <P>In some cases, a connection may both publish and subscribe to a
  51. * topic. The subscriber <CODE>NoLocal</CODE> attribute allows a subscriber
  52. * to inhibit the delivery of messages published by its own connection.
  53. * The default value for this attribute is false.
  54. *
  55. * @param topic the <CODE>Topic</CODE> to subscribe to
  56. *
  57. * @exception JMSException if the session fails to create a subscriber
  58. * due to some internal error.
  59. * @exception InvalidDestinationException if an invalid topic is specified.
  60. */
  61. TopicSubscriber
  62. createSubscriber(Topic topic) throws JMSException;
  63. /** Creates a nondurable subscriber to the specified topic, using a
  64. * message selector or specifying whether messages published by its
  65. * own connection should be delivered to it.
  66. *
  67. * <P>A client uses a <CODE>TopicSubscriber</CODE> object to receive
  68. * messages that have been published to a topic.
  69. *
  70. * <P>Regular <CODE>TopicSubscriber</CODE> objects are not durable.
  71. * They receive only messages that are published while they are active.
  72. *
  73. * <P>Messages filtered out by a subscriber's message selector will
  74. * never be delivered to the subscriber. From the subscriber's
  75. * perspective, they do not exist.
  76. *
  77. * <P>In some cases, a connection may both publish and subscribe to a
  78. * topic. The subscriber <CODE>NoLocal</CODE> attribute allows a subscriber
  79. * to inhibit the delivery of messages published by its own connection.
  80. * The default value for this attribute is false.
  81. *
  82. * @param topic the <CODE>Topic</CODE> to subscribe to
  83. * @param messageSelector only messages with properties matching the
  84. * message selector expression are delivered. A value of null or
  85. * an empty string indicates that there is no message selector
  86. * for the message consumer.
  87. * @param noLocal if set, inhibits the delivery of messages published
  88. * by its own connection
  89. *
  90. * @exception JMSException if the session fails to create a subscriber
  91. * due to some internal error.
  92. * @exception InvalidDestinationException if an invalid topic is specified.
  93. * @exception InvalidSelectorException if the message selector is invalid.
  94. */
  95. TopicSubscriber
  96. createSubscriber(Topic topic,
  97. String messageSelector,
  98. boolean noLocal) throws JMSException;
  99. /** Creates a durable subscriber to the specified topic.
  100. *
  101. * <P>If a client needs to receive all the messages published on a
  102. * topic, including the ones published while the subscriber is inactive,
  103. * it uses a durable <CODE>TopicSubscriber</CODE>. The JMS provider
  104. * retains a record of this
  105. * durable subscription and insures that all messages from the topic's
  106. * publishers are retained until they are acknowledged by this
  107. * durable subscriber or they have expired.
  108. *
  109. * <P>Sessions with durable subscribers must always provide the same
  110. * client identifier. In addition, each client must specify a name that
  111. * uniquely identifies (within client identifier) each durable
  112. * subscription it creates. Only one session at a time can have a
  113. * <CODE>TopicSubscriber</CODE> for a particular durable subscription.
  114. *
  115. * <P>A client can change an existing durable subscription by creating
  116. * a durable <CODE>TopicSubscriber</CODE> with the same name and a new
  117. * topic and/or
  118. * message selector. Changing a durable subscriber is equivalent to
  119. * unsubscribing (deleting) the old one and creating a new one.
  120. *
  121. * <P>In some cases, a connection may both publish and subscribe to a
  122. * topic. The subscriber <CODE>NoLocal</CODE> attribute allows a subscriber
  123. * to inhibit the delivery of messages published by its own connection.
  124. * The default value for this attribute is false.
  125. *
  126. * @param topic the non-temporary <CODE>Topic</CODE> to subscribe to
  127. * @param name the name used to identify this subscription
  128. *
  129. * @exception JMSException if the session fails to create a subscriber
  130. * due to some internal error.
  131. * @exception InvalidDestinationException if an invalid topic is specified.
  132. */
  133. TopicSubscriber
  134. createDurableSubscriber(Topic topic,
  135. String name) throws JMSException;
  136. /** Creates a durable subscriber to the specified topic, using a
  137. * message selector or specifying whether messages published by its
  138. * own connection should be delivered to it.
  139. *
  140. * <P>If a client needs to receive all the messages published on a
  141. * topic, including the ones published while the subscriber is inactive,
  142. * it uses a durable <CODE>TopicSubscriber</CODE>. The JMS provider
  143. * retains a record of this
  144. * durable subscription and insures that all messages from the topic's
  145. * publishers are retained until they are acknowledged by this
  146. * durable subscriber or they have expired.
  147. *
  148. * <P>Sessions with durable subscribers must always provide the same
  149. * client identifier. In addition, each client must specify a name which
  150. * uniquely identifies (within client identifier) each durable
  151. * subscription it creates. Only one session at a time can have a
  152. * <CODE>TopicSubscriber</CODE> for a particular durable subscription.
  153. * An inactive durable subscriber is one that exists but
  154. * does not currently have a message consumer associated with it.
  155. *
  156. * <P>A client can change an existing durable subscription by creating
  157. * a durable <CODE>TopicSubscriber</CODE> with the same name and a new
  158. * topic and/or
  159. * message selector. Changing a durable subscriber is equivalent to
  160. * unsubscribing (deleting) the old one and creating a new one.
  161. *
  162. * @param topic the non-temporary <CODE>Topic</CODE> to subscribe to
  163. * @param name the name used to identify this subscription
  164. * @param messageSelector only messages with properties matching the
  165. * message selector expression are delivered. A value of null or
  166. * an empty string indicates that there is no message selector
  167. * for the message consumer.
  168. * @param noLocal if set, inhibits the delivery of messages published
  169. * by its own connection
  170. *
  171. * @exception JMSException if the session fails to create a subscriber
  172. * due to some internal error.
  173. * @exception InvalidDestinationException if an invalid topic is specified.
  174. * @exception InvalidSelectorException if the message selector is invalid.
  175. */
  176. TopicSubscriber
  177. createDurableSubscriber(Topic topic,
  178. String name,
  179. String messageSelector,
  180. boolean noLocal) throws JMSException;
  181. /** Creates a publisher for the specified topic.
  182. *
  183. * <P>A client uses a <CODE>TopicPublisher</CODE> object to publish
  184. * messages on a topic.
  185. * Each time a client creates a <CODE>TopicPublisher</CODE> on a topic, it
  186. * defines a
  187. * new sequence of messages that have no ordering relationship with the
  188. * messages it has previously sent.
  189. *
  190. * @param topic the <CODE>Topic</CODE> to publish to, or null if this is an
  191. * unidentified producer
  192. *
  193. * @exception JMSException if the session fails to create a publisher
  194. * due to some internal error.
  195. * @exception InvalidDestinationException if an invalid topic is specified.
  196. */
  197. TopicPublisher
  198. createPublisher(Topic topic) throws JMSException;
  199. /** Creates a <CODE>TemporaryTopic</CODE> object. Its lifetime will be that
  200. * of the <CODE>TopicConnection</CODE> unless it is deleted earlier.
  201. *
  202. * @return a temporary topic identity
  203. *
  204. * @exception JMSException if the session fails to create a temporary
  205. * topic due to some internal error.
  206. */
  207. TemporaryTopic
  208. createTemporaryTopic() throws JMSException;
  209. /** Unsubscribes a durable subscription that has been created by a client.
  210. *
  211. * <P>This method deletes the state being maintained on behalf of the
  212. * subscriber by its provider.
  213. *
  214. * <P>It is erroneous for a client to delete a durable subscription
  215. * while there is an active <CODE>TopicSubscriber</CODE> for the
  216. * subscription, or while a consumed message is part of a pending
  217. * transaction or has not been acknowledged in the session.
  218. *
  219. * @param name the name used to identify this subscription
  220. *
  221. * @exception JMSException if the session fails to unsubscribe to the
  222. * durable subscription due to some internal error.
  223. * @exception InvalidDestinationException if an invalid subscription name
  224. * is specified.
  225. */
  226. void
  227. unsubscribe(String name) throws JMSException;
  228. }