001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.activemq;
019    
020    import javax.jms.JMSException;
021    import javax.jms.Message;
022    import javax.jms.Queue;
023    import javax.jms.QueueSender;
024    
025    import org.apache.activemq.command.ActiveMQDestination;
026    
027    /**
028     * A client uses a <CODE>QueueSender</CODE> object to send messages to a
029     * queue. <p/>
030     * <P>
031     * Normally, the <CODE>Queue</CODE> is specified when a <CODE>QueueSender
032     * </CODE>
033     * is created. In this case, an attempt to use the <CODE>send</CODE> methods
034     * for an unidentified <CODE>QueueSender</CODE> will throw a <CODE>
035     * java.lang.UnsupportedOperationException</CODE>.
036     * <p/>
037     * <P>
038     * If the <CODE>QueueSender</CODE> is created with an unidentified <CODE>
039     * Queue</CODE>,
040     * an attempt to use the <CODE>send</CODE> methods that assume that the
041     * <CODE>Queue</CODE> has been identified will throw a <CODE>
042     * java.lang.UnsupportedOperationException</CODE>.
043     * <p/>
044     * <P>
045     * During the execution of its <CODE>send</CODE> method, a message must not be
046     * changed by other threads within the client. If the message is modified, the
047     * result of the <CODE>send</CODE> is undefined. <p/>
048     * <P>
049     * After sending a message, a client may retain and modify it without affecting
050     * the message that has been sent. The same message object may be sent multiple
051     * times. <p/>
052     * <P>
053     * The following message headers are set as part of sending a message:
054     * <code>JMSDestination</code>, <code>JMSDeliveryMode</code>,<code>JMSExpiration</code>,<code>JMSPriority</code>,
055     * <code>JMSMessageID</code> and <code>JMSTimeStamp</code>. When the
056     * message is sent, the values of these headers are ignored. After the
057     * completion of the <CODE>send</CODE>, the headers hold the values specified
058     * by the method sending the message. It is possible for the <code>send</code>
059     * method not to set <code>JMSMessageID</code> and <code>JMSTimeStamp</code>
060     * if the setting of these headers is explicitly disabled by the
061     * <code>MessageProducer.setDisableMessageID</code> or
062     * <code>MessageProducer.setDisableMessageTimestamp</code> method. <p/>
063     * <P>
064     * Creating a <CODE>MessageProducer</CODE> provides the same features as
065     * creating a <CODE>QueueSender</CODE>. A <CODE>MessageProducer</CODE>
066     * object is recommended when creating new code. The <CODE>QueueSender</CODE>
067     * is provided to support existing code.
068     * 
069     * @see javax.jms.MessageProducer
070     * @see javax.jms.QueueSession#createSender(Queue)
071     */
072    
073    public class ActiveMQQueueSender extends ActiveMQMessageProducer implements QueueSender {
074    
075        protected ActiveMQQueueSender(ActiveMQSession session, ActiveMQDestination destination,int sendTimeout)
076            throws JMSException {
077            super(session, session.getNextProducerId(), destination,sendTimeout);
078        }
079    
080        /**
081         * Gets the queue associated with this <CODE>QueueSender</CODE>.
082         * 
083         * @return this sender's queue
084         * @throws JMSException if the JMS provider fails to get the queue for this
085         *                 <CODE>QueueSender</CODE> due to some internal error.
086         */
087    
088        public Queue getQueue() throws JMSException {
089            return (Queue)super.getDestination();
090        }
091    
092        /**
093         * Sends a message to a queue for an unidentified message producer. Uses the
094         * <CODE>QueueSender</CODE>'s default delivery mode, priority, and time
095         * to live. <p/>
096         * <P>
097         * Typically, a message producer is assigned a queue at creation time;
098         * however, the JMS API also supports unidentified message producers, which
099         * require that the queue be supplied every time a message is sent.
100         * 
101         * @param queue the queue to send this message to
102         * @param message the message to send
103         * @throws JMSException if the JMS provider fails to send the message due to
104         *                 some internal error.
105         * @see javax.jms.MessageProducer#getDeliveryMode()
106         * @see javax.jms.MessageProducer#getTimeToLive()
107         * @see javax.jms.MessageProducer#getPriority()
108         */
109    
110        public void send(Queue queue, Message message) throws JMSException {
111            super.send(queue, message);
112        }
113    
114        /**
115         * Sends a message to a queue for an unidentified message producer,
116         * specifying delivery mode, priority and time to live. <p/>
117         * <P>
118         * Typically, a message producer is assigned a queue at creation time;
119         * however, the JMS API also supports unidentified message producers, which
120         * require that the queue be supplied every time a message is sent.
121         * 
122         * @param queue the queue to send this message to
123         * @param message the message to send
124         * @param deliveryMode the delivery mode to use
125         * @param priority the priority for this message
126         * @param timeToLive the message's lifetime (in milliseconds)
127         * @throws JMSException if the JMS provider fails to send the message due to
128         *                 some internal error.
129         */
130    
131        public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive)
132            throws JMSException {
133            super.send(queue, message, deliveryMode, priority, timeToLive);
134        }
135    }