1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2000-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License ("CDDL") (collectively, the "License"). You may
9 * not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or mq/legal/LICENSE.txt. See the License for the specific language
12 * governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at mq/legal/LICENSE.txt. Sun designates
16 * this particular file as subject to the "Classpath" exception as provided by
17 * Sun in the GPL Version 2 section of the License file that accompanied this
18 * code. If applicable, add the following below the License Header, with the
19 * fields enclosed by brackets [] replaced by your own identifying information:
20 * "Portions Copyrighted [year] [name of copyright owner]"
21 *
22 * Contributor(s):
23 *
24 * If you wish your version of this file to be governed by only the CDDL or
25 * only the GPL Version 2, indicate your decision by adding "[Contributor]
26 * elects to include this software in this distribution under the [CDDL or GPL
27 * Version 2] license." If you don't indicate a single choice of license, a
28 * recipient has the option to distribute your version of this file under
29 * either the CDDL, the GPL Version 2 or to extend the choice of license to
30 * its licensees as provided above. However, if you add GPL Version 2 code
31 * and therefore, elected the GPL Version 2 license, then the option applies
32 * only if the new code is made subject to such option by the copyright holder.
33 */
34
35 /*
36 * @(#)QueueSender.java 1.31 07/02/07
37 */
38
39 package javax.jms;
40
41 /** A client uses a <CODE>QueueSender</CODE> object to send messages to a queue.
42 *
43 * <P>Normally, the <CODE>Queue</CODE> is specified when a
44 * <CODE>QueueSender</CODE> is created. In this case, an attempt to use
45 * the <CODE>send</CODE> methods for an unidentified
46 * <CODE>QueueSender</CODE> will throw a
47 * <CODE>java.lang.UnsupportedOperationException</CODE>.
48 *
49 * <P>If the <CODE>QueueSender</CODE> is created with an unidentified
50 * <CODE>Queue</CODE>, an attempt to use the <CODE>send</CODE> methods that
51 * assume that the <CODE>Queue</CODE> has been identified will throw a
52 * <CODE>java.lang.UnsupportedOperationException</CODE>.
53 *
54 * <P>During the execution of its <CODE>send</CODE> method, a message
55 * must not be changed by other threads within the client.
56 * If the message is modified, the result of the <CODE>send</CODE> is
57 * undefined.
58 *
59 * <P>After sending a message, a client may retain and modify it
60 * without affecting the message that has been sent. The same message
61 * object may be sent multiple times.
62 *
63 * <P>The following message headers are set as part of sending a
64 * message: <code>JMSDestination</code>, <code>JMSDeliveryMode</code>,
65 * <code>JMSExpiration</code>, <code>JMSPriority</code>,
66 * <code>JMSMessageID</code> and <code>JMSTimeStamp</code>.
67 * When the message is sent, the values of these headers are ignored.
68 * After the completion of the <CODE>send</CODE>, the headers hold the values
69 * specified by the method sending the message. It is possible for the
70 * <code>send</code> method not to set <code>JMSMessageID</code> and
71 * <code>JMSTimeStamp</code> if the
72 * setting of these headers is explicitly disabled by the
73 * <code>MessageProducer.setDisableMessageID</code> or
74 * <code>MessageProducer.setDisableMessageTimestamp</code> method.
75 *
76 * <P>Creating a <CODE>MessageProducer</CODE> provides the same features as
77 * creating a <CODE>QueueSender</CODE>. A <CODE>MessageProducer</CODE> object is
78 * recommended when creating new code. The <CODE>QueueSender</CODE> is
79 * provided to support existing code.
80 *
81 * @see javax.jms.MessageProducer
82 * @see javax.jms.Session#createProducer(Destination)
83 * @see javax.jms.QueueSession#createSender(Queue)
84 */
85
86 public interface QueueSender extends MessageProducer {
87
88 /** Gets the queue associated with this <CODE>QueueSender</CODE>.
89 *
90 * @return this sender's queue
91 *
92 * @exception JMSException if the JMS provider fails to get the queue for
93 * this <CODE>QueueSender</CODE>
94 * due to some internal error.
95 */
96
97 Queue
98 getQueue() throws JMSException;
99
100
101 /** Sends a message to the queue. Uses the <CODE>QueueSender</CODE>'s
102 * default delivery mode, priority, and time to live.
103 *
104 * @param message the message to send
105 *
106 * @exception JMSException if the JMS provider fails to send the message
107 * due to some internal error.
108 * @exception MessageFormatException if an invalid message is specified.
109 * @exception InvalidDestinationException if a client uses
110 * this method with a <CODE>QueueSender</CODE> with
111 * an invalid queue.
112 * @exception java.lang.UnsupportedOperationException if a client uses this
113 * method with a <CODE>QueueSender</CODE> that did
114 * not specify a queue at creation time.
115 *
116 * @see javax.jms.MessageProducer#getDeliveryMode()
117 * @see javax.jms.MessageProducer#getTimeToLive()
118 * @see javax.jms.MessageProducer#getPriority()
119 */
120
121 void
122 send(Message message) throws JMSException;
123
124
125 /** Sends a message to the queue, specifying delivery mode, priority, and
126 * time to live.
127 *
128 * @param message the message to send
129 * @param deliveryMode the delivery mode to use
130 * @param priority the priority for this message
131 * @param timeToLive the message's lifetime (in milliseconds)
132 *
133 * @exception JMSException if the JMS provider fails to send the message
134 * due to some internal error.
135 * @exception MessageFormatException if an invalid message is specified.
136 * @exception InvalidDestinationException if a client uses
137 * this method with a <CODE>QueueSender</CODE> with
138 * an invalid queue.
139 * @exception java.lang.UnsupportedOperationException if a client uses this
140 * method with a <CODE>QueueSender</CODE> that did
141 * not specify a queue at creation time.
142 */
143
144 void
145 send(Message message,
146 int deliveryMode,
147 int priority,
148 long timeToLive) throws JMSException;
149
150
151 /** Sends a message to a queue for an unidentified message producer.
152 * Uses the <CODE>QueueSender</CODE>'s default delivery mode, priority,
153 * and time to live.
154 *
155 * <P>Typically, a message producer is assigned a queue at creation
156 * time; however, the JMS API also supports unidentified message producers,
157 * which require that the queue be supplied every time a message is
158 * sent.
159 *
160 * @param queue the queue to send this message to
161 * @param message the message to send
162 *
163 * @exception JMSException if the JMS provider fails to send the message
164 * due to some internal error.
165 * @exception MessageFormatException if an invalid message is specified.
166 * @exception InvalidDestinationException if a client uses
167 * this method with an invalid queue.
168 *
169 * @see javax.jms.MessageProducer#getDeliveryMode()
170 * @see javax.jms.MessageProducer#getTimeToLive()
171 * @see javax.jms.MessageProducer#getPriority()
172 */
173
174 void
175 send(Queue queue, Message message) throws JMSException;
176
177
178 /** Sends a message to a queue for an unidentified message producer,
179 * specifying delivery mode, priority and time to live.
180 *
181 * <P>Typically, a message producer is assigned a queue at creation
182 * time; however, the JMS API also supports unidentified message producers,
183 * which require that the queue be supplied every time a message is
184 * sent.
185 *
186 * @param queue the queue to send this message to
187 * @param message the message to send
188 * @param deliveryMode the delivery mode to use
189 * @param priority the priority for this message
190 * @param timeToLive the message's lifetime (in milliseconds)
191 *
192 * @exception JMSException if the JMS provider fails to send the message
193 * due to some internal error.
194 * @exception MessageFormatException if an invalid message is specified.
195 * @exception InvalidDestinationException if a client uses
196 * this method with an invalid queue.
197 */
198
199 void
200 send(Queue queue,
201 Message message,
202 int deliveryMode,
203 int priority,
204 long timeToLive) throws JMSException;
205 }