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>MessageProducer</CODE> object to send messages to a
  7. * destination. A <CODE>MessageProducer</CODE> object is created by passing a
  8. * <CODE>Destination</CODE> object to a message-producer creation method
  9. * supplied by a session.
  10. *
  11. * <P><CODE>MessageProducer</CODE> is the parent interface for all message
  12. * producers.
  13. *
  14. * <P>A client also has the option of creating a message producer without
  15. * supplying a destination. In this case, a destination must be provided with
  16. * every send operation. A typical use for this kind of message producer is
  17. * to send replies to requests using the request's <CODE>JMSReplyTo</CODE>
  18. * destination.
  19. *
  20. * <P>A client can specify a default delivery mode, priority, and time to live
  21. * for messages sent by a message producer. It can also specify the delivery
  22. * mode, priority, and time to live for an individual message.
  23. *
  24. * <P>A client can specify a time-to-live value in milliseconds for each
  25. * message it sends. This value defines a message expiration time that
  26. * is the sum of the message's time-to-live and the GMT when it is sent (for
  27. * transacted sends, this is the time the client sends the message, not
  28. * the time the transaction is committed).
  29. *
  30. * <P>A JMS provider should do its best to expire messages accurately;
  31. * however, the JMS API does not define the accuracy provided.
  32. *
  33. * @version 1.0 - 3 August 1998
  34. * @author Mark Hapner
  35. * @author Rich Burridge
  36. *
  37. * @see javax.jms.TopicPublisher
  38. * @see javax.jms.QueueSender
  39. * @see javax.jms.Session
  40. */
  41. public interface MessageProducer {
  42. /** Sets whether message IDs are disabled.
  43. *
  44. * <P>Since message IDs take some effort to create and increase a
  45. * message's size, some JMS providers may be able to optimize message
  46. * overhead if they are given a hint that the message ID is not used by
  47. * an application. By calling the <CODE>setDisableMessageID</CODE>
  48. * method on this message producer, a JMS client enables this potential
  49. * optimization for all messages sent by this message producer. If the JMS
  50. * provider accepts this hint,
  51. * these messages must have the message ID set to null; if the provider
  52. * ignores the hint, the message ID must be set to its normal unique value.
  53. *
  54. * <P>Message IDs are enabled by default.
  55. *
  56. * @param value indicates if message IDs are disabled
  57. *
  58. * @exception JMSException if the JMS provider fails to set message ID to
  59. * disabled due to some internal error.
  60. */
  61. void
  62. setDisableMessageID(boolean value) throws JMSException;
  63. /** Gets an indication of whether message IDs are disabled.
  64. *
  65. * @return an indication of whether message IDs are disabled
  66. *
  67. * @exception JMSException if the JMS provider fails to determine if
  68. * message IDs are disabled due to some internal
  69. * error.
  70. */
  71. boolean
  72. getDisableMessageID() throws JMSException;
  73. /** Sets whether message timestamps are disabled.
  74. *
  75. * <P>Since timestamps take some effort to create and increase a
  76. * message's size, some JMS providers may be able to optimize message
  77. * overhead if they are given a hint that the timestamp is not used by an
  78. * application. By calling the <CODE>setDisableMessageTimestamp</CODE>
  79. * method on this message producer, a JMS client enables this potential
  80. * optimization for all messages sent by this message producer. If the
  81. * JMS provider accepts this hint,
  82. * these messages must have the timestamp set to zero; if the provider
  83. * ignores the hint, the timestamp must be set to its normal value.
  84. *
  85. * <P>Message timestamps are enabled by default.
  86. *
  87. * @param value indicates if message timestamps are disabled
  88. *
  89. * @exception JMSException if the JMS provider fails to set timestamps to
  90. * disabled due to some internal error.
  91. */
  92. void
  93. setDisableMessageTimestamp(boolean value) throws JMSException;
  94. /** Gets an indication of whether message timestamps are disabled.
  95. *
  96. * @return an indication of whether message timestamps are disabled
  97. *
  98. * @exception JMSException if the JMS provider fails to determine if
  99. * timestamps are disabled due to some internal
  100. * error.
  101. */
  102. boolean
  103. getDisableMessageTimestamp() throws JMSException;
  104. /** Sets the producer's default delivery mode.
  105. *
  106. * <P>Delivery mode is set to <CODE>PERSISTENT</CODE> by default.
  107. *
  108. * @param deliveryMode the message delivery mode for this message
  109. * producer; legal values are <code>DeliveryMode.NON_PERSISTENT</code>
  110. * and <code>DeliveryMode.PERSISTENT</code>
  111. *
  112. * @exception JMSException if the JMS provider fails to set the delivery
  113. * mode due to some internal error.
  114. *
  115. * @see javax.jms.MessageProducer#getDeliveryMode
  116. * @see javax.jms.DeliveryMode#NON_PERSISTENT
  117. * @see javax.jms.DeliveryMode#PERSISTENT
  118. * @see javax.jms.Message#DEFAULT_DELIVERY_MODE
  119. */
  120. void
  121. setDeliveryMode(int deliveryMode) throws JMSException;
  122. /** Gets the producer's default delivery mode.
  123. *
  124. * @return the message delivery mode for this message producer
  125. *
  126. * @exception JMSException if the JMS provider fails to get the delivery
  127. * mode due to some internal error.
  128. *
  129. * @see javax.jms.MessageProducer#setDeliveryMode
  130. */
  131. int
  132. getDeliveryMode() throws JMSException;
  133. /** Sets the producer's default priority.
  134. *
  135. * <P>The JMS API defines ten levels of priority value, with 0 as the
  136. * lowest priority and 9 as the highest. Clients should consider priorities
  137. * 0-4 as gradations of normal priority and priorities 5-9 as gradations
  138. * of expedited priority. Priority is set to 4 by default.
  139. *
  140. * @param defaultPriority the message priority for this message producer;
  141. * must be a value between 0 and 9
  142. *
  143. *
  144. * @exception JMSException if the JMS provider fails to set the priority
  145. * due to some internal error.
  146. *
  147. * @see javax.jms.MessageProducer#getPriority
  148. * @see javax.jms.Message#DEFAULT_PRIORITY
  149. */
  150. void
  151. setPriority(int defaultPriority) throws JMSException;
  152. /** Gets the producer's default priority.
  153. *
  154. * @return the message priority for this message producer
  155. *
  156. * @exception JMSException if the JMS provider fails to get the priority
  157. * due to some internal error.
  158. *
  159. * @see javax.jms.MessageProducer#setPriority
  160. */
  161. int
  162. getPriority() throws JMSException;
  163. /** Sets the default length of time in milliseconds from its dispatch time
  164. * that a produced message should be retained by the message system.
  165. *
  166. * <P>Time to live is set to zero by default.
  167. *
  168. * @param timeToLive the message time to live in milliseconds; zero is
  169. * unlimited
  170. *
  171. * @exception JMSException if the JMS provider fails to set the time to
  172. * live due to some internal error.
  173. *
  174. * @see javax.jms.MessageProducer#getTimeToLive
  175. * @see javax.jms.Message#DEFAULT_TIME_TO_LIVE
  176. */
  177. void
  178. setTimeToLive(long timeToLive) throws JMSException;
  179. /** Gets the default length of time in milliseconds from its dispatch time
  180. * that a produced message should be retained by the message system.
  181. *
  182. * @return the message time to live in milliseconds; zero is unlimited
  183. *
  184. * @exception JMSException if the JMS provider fails to get the time to
  185. * live due to some internal error.
  186. *
  187. * @see javax.jms.MessageProducer#setTimeToLive
  188. */
  189. long
  190. getTimeToLive() throws JMSException;
  191. /** Closes the message producer.
  192. *
  193. * <P>Since a provider may allocate some resources on behalf of a
  194. * <CODE>MessageProducer</CODE> outside the Java virtual machine, clients
  195. * should close them when they
  196. * are not needed. Relying on garbage collection to eventually reclaim
  197. * these resources may not be timely enough.
  198. *
  199. * @exception JMSException if the JMS provider fails to close the producer
  200. * due to some internal error.
  201. */
  202. void
  203. close() throws JMSException;
  204. }