Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/ActiveMQQueueSender.java


1   /** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  
19  package org.activemq;
20  
21  import javax.jms.JMSException;
22  import javax.jms.Message;
23  import javax.jms.Queue;
24  import javax.jms.QueueSender;
25  
26  import org.activemq.message.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.Session#createProducer(Destination)
73   * @see javax.jms.QueueSession#createSender(Queue)
74   */
75  
76  public class ActiveMQQueueSender extends ActiveMQMessageProducer implements
77          QueueSender {
78  
79      protected ActiveMQQueueSender(ActiveMQSession session,
80                                    ActiveMQDestination destination) throws JMSException {
81          super(session, 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 getQueue() throws JMSException {
93          return (Queue) 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      * @throws MessageFormatException      if an invalid message is specified.
111      * @throws InvalidDestinationException if a client uses this method with an invalid queue.
112      * @see javax.jms.MessageProducer#getDeliveryMode()
113      * @see javax.jms.MessageProducer#getTimeToLive()
114      * @see javax.jms.MessageProducer#getPriority()
115      */
116 
117     public void send(Queue queue, Message message) throws JMSException {
118         super.send(queue, message);
119     }
120 
121     /**
122      * Sends a message to a queue for an unidentified message producer,
123      * specifying delivery mode, priority and time to live.
124      * <p/>
125      * <P>
126      * Typically, a message producer is assigned a queue at creation time;
127      * however, the JMS API also supports unidentified message producers, which
128      * require that the queue be supplied every time a message is sent.
129      *
130      * @param queue        the queue to send this message to
131      * @param message      the message to send
132      * @param deliveryMode the delivery mode to use
133      * @param priority     the priority for this message
134      * @param timeToLive   the message's lifetime (in milliseconds)
135      * @throws JMSException                if the JMS provider fails to send the message due to some
136      *                                     internal error.
137      * @throws MessageFormatException      if an invalid message is specified.
138      * @throws InvalidDestinationException if a client uses this method with an invalid queue.
139      */
140 
141     public void send(Queue queue, Message message, int deliveryMode,
142                      int priority, long timeToLive) throws JMSException {
143         super.send(queue, message, deliveryMode, priority, timeToLive);
144     }
145 }