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 client uses a <CODE>TopicPublisher</CODE> object to publish messages on a
  7. * topic. A <CODE>TopicPublisher</CODE> object is the publish-subscribe form
  8. * of a message producer.
  9. *
  10. * <P>Normally, the <CODE>Topic</CODE> is specified when a
  11. * <CODE>TopicPublisher</CODE> is created. In this case, an attempt to use
  12. * the <CODE>publish</CODE> methods for an unidentified
  13. * <CODE>TopicPublisher</CODE> will throw a
  14. * <CODE>java.lang.UnsupportedOperationException</CODE>.
  15. *
  16. * <P>If the <CODE>TopicPublisher</CODE> is created with an unidentified
  17. * <CODE>Topic</CODE>, an attempt to use the <CODE>publish</CODE> methods that
  18. * assume that the <CODE>Topic</CODE> has been identified will throw a
  19. * <CODE>java.lang.UnsupportedOperationException</CODE>.
  20. *
  21. * <P>During the execution of its <CODE>publish</CODE> method,
  22. * a message must not be changed by other threads within the client.
  23. * If the message is modified, the result of the <CODE>publish</CODE> is
  24. * undefined.
  25. *
  26. * <P>After publishing a message, a client may retain and modify it
  27. * without affecting the message that has been published. The same message
  28. * object may be published multiple times.
  29. *
  30. * <P>The following message headers are set as part of publishing a
  31. * message: <code>JMSDestination</code>, <code>JMSDeliveryMode</code>,
  32. * <code>JMSExpiration</code>, <code>JMSPriority</code>,
  33. * <code>JMSMessageID</code> and <code>JMSTimeStamp</code>.
  34. * When the message is published, the values of these headers are ignored.
  35. * After completion of the <CODE>publish</CODE>, the headers hold the values
  36. * specified by the method publishing the message. It is possible for the
  37. * <CODE>publish</CODE> method not to set <code>JMSMessageID</code> and
  38. * <code>JMSTimeStamp</code> if the
  39. * setting of these headers is explicitly disabled by the
  40. * <code>MessageProducer.setDisableMessageID</code> or
  41. * <code>MessageProducer.setDisableMessageTimestamp</code> method.
  42. *
  43. * @version 1.0 - 4 August 1998
  44. * @author Mark Hapner
  45. * @author Rich Burridge
  46. *
  47. * @see TopicSession#createPublisher(Topic)
  48. */
  49. public interface TopicPublisher extends MessageProducer {
  50. /** Gets the topic associated with this <CODE>TopicPublisher</CODE>.
  51. *
  52. * @return this publisher's topic
  53. *
  54. * @exception JMSException if the JMS provider fails to get the topic for
  55. * this <CODE>TopicPublisher</CODE>
  56. * due to some internal error.
  57. */
  58. Topic
  59. getTopic() throws JMSException;
  60. /** Publishes a message to the topic.
  61. * Uses the <CODE>TopicPublisher</CODE>'s default delivery mode, priority,
  62. * and time to live.
  63. *
  64. * @param message the message to publish
  65. *
  66. * @exception JMSException if the JMS provider fails to publish the message
  67. * due to some internal error.
  68. * @exception MessageFormatException if an invalid message is specified.
  69. * @exception InvalidDestinationException if a client uses this method
  70. * with a <CODE>TopicPublisher</CODE> with
  71. * an invalid topic.
  72. * @exception java.lang.UnsupportedOperationException if a client uses this
  73. * method with a <CODE>TopicPublisher</CODE> that
  74. * did not specify a topic at creation time.
  75. *
  76. * @see javax.jms.MessageProducer#getDeliveryMode()
  77. * @see javax.jms.MessageProducer#getTimeToLive()
  78. * @see javax.jms.MessageProducer#getPriority()
  79. */
  80. void
  81. publish(Message message) throws JMSException;
  82. /** Publishes a message to the topic, specifying delivery mode,
  83. * priority, and time to live.
  84. *
  85. * @param message the message to publish
  86. * @param deliveryMode the delivery mode to use
  87. * @param priority the priority for this message
  88. * @param timeToLive the message's lifetime (in milliseconds)
  89. *
  90. * @exception JMSException if the JMS provider fails to publish the message
  91. * due to some internal error.
  92. * @exception MessageFormatException if an invalid message is specified.
  93. * @exception InvalidDestinationException if a client uses this method
  94. * with a <CODE>TopicPublisher</CODE> with
  95. * an invalid topic.
  96. * @exception java.lang.UnsupportedOperationException if a client uses this
  97. * method with a <CODE>TopicPublisher</CODE> that
  98. * did not specify a topic at creation time.
  99. */
  100. void
  101. publish(Message message,
  102. int deliveryMode,
  103. int priority,
  104. long timeToLive) throws JMSException;
  105. /** Publishes a message to a topic for an unidentified message producer.
  106. * Uses the <CODE>TopicPublisher</CODE>'s default delivery mode,
  107. * priority, and time to live.
  108. *
  109. * <P>Typically, a message producer is assigned a topic at creation
  110. * time; however, the JMS API also supports unidentified message producers,
  111. * which require that the topic be supplied every time a message is
  112. * published.
  113. *
  114. * @param topic the topic to publish this message to
  115. * @param message the message to publish
  116. *
  117. * @exception JMSException if the JMS provider fails to publish the message
  118. * due to some internal error.
  119. * @exception MessageFormatException if an invalid message is specified.
  120. * @exception InvalidDestinationException if a client uses
  121. * this method with an invalid topic.
  122. *
  123. * @see javax.jms.MessageProducer#getDeliveryMode()
  124. * @see javax.jms.MessageProducer#getTimeToLive()
  125. * @see javax.jms.MessageProducer#getPriority()
  126. */
  127. void
  128. publish(Topic topic, Message message) throws JMSException;
  129. /** Publishes a message to a topic for an unidentified message
  130. * producer, specifying delivery mode, priority and time to live.
  131. *
  132. * <P>Typically, a message producer is assigned a topic at creation
  133. * time; however, the JMS API also supports unidentified message producers,
  134. * which require that the topic be supplied every time a message is
  135. * published.
  136. *
  137. * @param topic the topic to publish this message to
  138. * @param message the message to publish
  139. * @param deliveryMode the delivery mode to use
  140. * @param priority the priority for this message
  141. * @param timeToLive the message's lifetime (in milliseconds)
  142. *
  143. * @exception JMSException if the JMS provider fails to publish the message
  144. * due to some internal error.
  145. * @exception MessageFormatException if an invalid message is specified.
  146. * @exception InvalidDestinationException if a client uses
  147. * this method with an invalid topic.
  148. */
  149. void
  150. publish(Topic topic,
  151. Message message,
  152. int deliveryMode,
  153. int priority,
  154. long timeToLive) throws JMSException;
  155. }