1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2000-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: JmsQueueSender.java,v 1.9 2004/01/20 14:14:21 tanderson Exp $
44 */
45 package org.exolab.jms.client;
46
47
48 import javax.jms.JMSException;
49 import javax.jms.Message;
50 import javax.jms.QueueSender;
51 import javax.jms.Queue;
52
53
54 /***
55 * Client implementation of the <code>javax.jms.QueueSender</code> interface
56 *
57 * @version $Revision: 1.9 $ $Date: 2004/01/20 14:14:21 $
58 * @author <a href="mailto:jima@exoffice.com">Jim Alateras</a>
59 */
60 class JmsQueueSender
61 extends JmsMessageProducer
62 implements QueueSender {
63
64 /***
65 * The destination that messages are delivered to, or <code>null</code>
66 * if this is an unidentified producer
67 */
68 private JmsQueue _queue = null;
69
70
71 /***
72 * Construct a new <code>JmsQueueSender</code>
73 *
74 * @param session the session constructing this object
75 * @param queue the sender's destination. May be <code>null</code>.
76 */
77 public JmsQueueSender(JmsSession session, JmsQueue queue) {
78 super(session);
79 _queue = queue;
80 }
81
82 /***
83 * Returns the queue associated with this sender
84 *
85 * @return the queue associated with this sender, or <code>null</code>
86 * if this is an unidentified producer
87 */
88 public Queue getQueue() {
89 return _queue;
90 }
91
92 /***
93 * Send a message, using the default delivery mode, priority and time to
94 * live.
95 *
96 * @param message the message to send
97 * @throws JMSException if the message can't be sent
98 */
99 public void send(Message message) throws JMSException {
100 send(getQueue(), message, getDeliveryMode(), getPriority(),
101 getTimeToLive());
102 }
103
104 /***
105 * Send a message specifying the default delivery mode, priority and
106 * time to live.
107 *
108 * @param message the message to send
109 * @param deliveryMode the delivery mode to use
110 * @param priority the message priority
111 * @param timeToLive the message's lifetime (in milliseconds).
112 * @throws JMSException if the message can't be sent
113 */
114 public void send(Message message, int deliveryMode, int priority,
115 long timeToLive) throws JMSException {
116 send(getQueue(), message, deliveryMode, priority, timeToLive);
117 }
118
119 /***
120 * Send a message to a queue for an unidentified message producer, using
121 * the default delivery mode, priority and time to live
122 *
123 * @param queue the queue to send the message to
124 * @param message the message to send
125 * @throws JMSException if the message can't be sent
126 */
127 public void send(Queue queue, Message message) throws JMSException {
128 send(queue, message, getDeliveryMode(), getPriority(),
129 getTimeToLive());
130 }
131
132 /***
133 * Send a message to a queue for an unidentified message producer,
134 * specifying the default delivery mode, priority and time to live
135 *
136 * @param queue the queue to send the message to
137 * @param message the message to send
138 * @param deliveryMode the delivery mode to use
139 * @param priority the message priority
140 * @param timeToLive the message's lifetime (in milliseconds).
141 * @throws JMSException if the message can't be sent
142 */
143 public void send(Queue queue, Message message, int deliveryMode,
144 int priority, long timeToLive) throws JMSException {
145 sendMessage(queue, message, deliveryMode, priority, timeToLive);
146 }
147
148 /***
149 * Close the sender
150 *
151 * @throws JMSException if the sender can't be closed
152 */
153 public synchronized void close() throws JMSException {
154 if (!isClosed()) {
155 // unregister this producer from the session before closing.
156 // and then call the base class method.
157 JmsQueueSession session = (JmsQueueSession) getSession();
158 session.removeSender(this);
159 super.close();
160 }
161 }
162
163 /***
164 * Destroy the sender
165 */
166 public void destroy() {
167 super.destroy();
168 _queue = null;
169 }
170 }
This page was automatically generated by Maven