KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ActiveMQQueueSender


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.activemq;
20
21 import javax.jms.JMSException JavaDoc;
22 import javax.jms.Message JavaDoc;
23 import javax.jms.Queue JavaDoc;
24 import javax.jms.QueueSender JavaDoc;
25
26 import org.apache.activemq.command.ActiveMQDestination;
27
28 /**
29  * A client uses a <CODE>QueueSender</CODE> object to send messages to a
30  * queue.
31  * <p/>
32  * <P>
33  * Normally, the <CODE>Queue</CODE> is specified when a <CODE>QueueSender
34  * </CODE> is created. In this case, an attempt to use the <CODE>send</CODE>
35  * methods for an unidentified <CODE>QueueSender</CODE> will throw a <CODE>
36  * java.lang.UnsupportedOperationException</CODE>.
37  * <p/>
38  * <P>
39  * If the <CODE>QueueSender</CODE> is created with an unidentified <CODE>
40  * Queue</CODE>, an attempt to use the <CODE>send</CODE> methods that
41  * assume that the <CODE>Queue</CODE> has been identified will throw a <CODE>
42  * java.lang.UnsupportedOperationException</CODE>.
43  * <p/>
44  * <P>
45  * During the execution of its <CODE>send</CODE> method, a message must not
46  * be changed by other threads within the client. If the message is modified,
47  * the result of the <CODE>send</CODE> is undefined.
48  * <p/>
49  * <P>
50  * After sending a message, a client may retain and modify it without affecting
51  * the message that has been sent. The same message object may be sent multiple
52  * times.
53  * <p/>
54  * <P>
55  * The following message headers are set as part of sending a message: <code>JMSDestination</code>,
56  * <code>JMSDeliveryMode</code>,<code>JMSExpiration</code>,<code>JMSPriority</code>,
57  * <code>JMSMessageID</code> and <code>JMSTimeStamp</code>. When the
58  * message is sent, the values of these headers are ignored. After the
59  * completion of the <CODE>send</CODE>, the headers hold the values
60  * specified by the method sending the message. It is possible for the <code>send</code>
61  * method not to set <code>JMSMessageID</code> and <code>JMSTimeStamp</code>
62  * if the setting of these headers is explicitly disabled by the <code>MessageProducer.setDisableMessageID</code>
63  * or <code>MessageProducer.setDisableMessageTimestamp</code> method.
64  * <p/>
65  * <P>
66  * Creating a <CODE>MessageProducer</CODE> provides the same features as
67  * creating a <CODE>QueueSender</CODE>. A <CODE>MessageProducer</CODE>
68  * object is recommended when creating new code. The <CODE>QueueSender</CODE>
69  * is provided to support existing code.
70  *
71  * @see javax.jms.MessageProducer
72  * @see javax.jms.QueueSession#createSender(Queue)
73  */

74
75 public class ActiveMQQueueSender extends ActiveMQMessageProducer implements QueueSender JavaDoc {
76
77     protected ActiveMQQueueSender(ActiveMQSession session, ActiveMQDestination destination)
78             throws JMSException JavaDoc {
79         super(session,
80               session.getNextProducerId(),
81               destination);
82     }
83
84     /**
85      * Gets the queue associated with this <CODE>QueueSender</CODE>.
86      *
87      * @return this sender's queue
88      * @throws JMSException if the JMS provider fails to get the queue for this
89      * <CODE>QueueSender</CODE> due to some internal error.
90      */

91
92     public Queue JavaDoc getQueue() throws JMSException JavaDoc {
93         return (Queue JavaDoc) super.getDestination();
94     }
95
96     /**
97      * Sends a message to a queue for an unidentified message producer. Uses
98      * the <CODE>QueueSender</CODE>'s default delivery mode, priority, and
99      * time to live.
100      * <p/>
101      * <P>
102      * Typically, a message producer is assigned a queue at creation time;
103      * however, the JMS API also supports unidentified message producers, which
104      * require that the queue be supplied every time a message is sent.
105      *
106      * @param queue the queue to send this message to
107      * @param message the message to send
108      * @throws JMSException if the JMS provider fails to send the message due to some
109      * internal error.
110      * @see javax.jms.MessageProducer#getDeliveryMode()
111      * @see javax.jms.MessageProducer#getTimeToLive()
112      * @see javax.jms.MessageProducer#getPriority()
113      */

114
115     public void send(Queue JavaDoc queue, Message message) throws JMSException JavaDoc {
116         super.send(queue, message);
117     }
118
119     /**
120      * Sends a message to a queue for an unidentified message producer,
121      * specifying delivery mode, priority and time to live.
122      * <p/>
123      * <P>
124      * Typically, a message producer is assigned a queue at creation time;
125      * however, the JMS API also supports unidentified message producers, which
126      * require that the queue be supplied every time a message is sent.
127      *
128      * @param queue the queue to send this message to
129      * @param message the message to send
130      * @param deliveryMode the delivery mode to use
131      * @param priority the priority for this message
132      * @param timeToLive the message's lifetime (in milliseconds)
133      * @throws JMSException if the JMS provider fails to send the message due to some
134      * internal error.
135      */

136
137     public void send(Queue JavaDoc queue, Message message, int deliveryMode, int priority, long timeToLive)
138             throws JMSException JavaDoc {
139         super.send(queue,
140                    message,
141                    deliveryMode,
142                    priority,
143                    timeToLive);
144     }
145 }
146
Popular Tags