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 tma@netspace.net.au.
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 2001-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: MessagingBehaviour.java,v 1.5 2004/01/31 13:44:24 tanderson Exp $
44 */
45 package org.exolab.jmscts.core;
46
47 import javax.jms.DeliveryMode;
48 import javax.jms.Message;
49
50
51 /***
52 * Determines the behaviour for sending and receiving messages
53 *
54 * @version $Revision: 1.5 $ $Date: 2004/01/31 13:44:24 $
55 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
56 * @see DeliveryType
57 * @see TestContext
58 */
59 public class MessagingBehaviour {
60
61 /***
62 * The delivery mode on send. This can be one of DeliveryMode.PERSISTENT
63 * or DeliveryMode.NON_PERSISTENT
64 */
65 private int _deliveryMode = Message.DEFAULT_DELIVERY_MODE;
66
67 /***
68 * If true, destinations are administered, otherwise they are temporary
69 */
70 private boolean _administered = true;
71
72 /***
73 * The type of message receipt to use
74 */
75 private ReceiptType _receipt = ReceiptType.SYNCHRONOUS;
76
77 /***
78 * If true, topic subscribers are durable
79 */
80 private boolean _durable = false;
81
82 /***
83 * The message priority on send
84 */
85 private int _priority = Message.DEFAULT_PRIORITY;
86
87 /***
88 * The time to wait for messages in milliseconds when listening/receiving
89 */
90 private long _timeout = DEFAULT_TIMEOUT;
91
92 /***
93 * The default timeout
94 */
95 private static final long DEFAULT_TIMEOUT;
96
97
98 /***
99 * Construct a new instance, with default values
100 */
101 public MessagingBehaviour() {
102 }
103
104 /***
105 * Construct a new instance, specifying the delivery type.
106 *
107 * @param type the type of delivery when sending and receiving messages
108 */
109 public MessagingBehaviour(DeliveryType type) {
110 if (type == null) {
111 throw new IllegalArgumentException("Argument 'type' is null");
112 }
113 _deliveryMode = type.getDeliveryMode();
114 _administered = type.getAdministered();
115 _receipt = type.getReceiptType();
116 }
117
118 /***
119 * Construct a new instance, copying from an existing behaviour
120 *
121 * @param behaviour behaviour the behaviour to copy
122 */
123 public MessagingBehaviour(MessagingBehaviour behaviour) {
124 if (behaviour == null) {
125 throw new IllegalArgumentException("Argument 'behaviour' is null");
126 }
127 _deliveryMode = behaviour.getDeliveryMode();
128 _administered = behaviour.getAdministered();
129 _receipt = behaviour.getReceiptType();
130 _durable = behaviour.getDurable();
131 _priority = behaviour.getPriority();
132 _timeout = behaviour.getTimeout();
133 }
134
135 /***
136 * Set the message delivery mode. This can be one of
137 * DeliveryMode.PERSISTENT or DeliveryMode.NON_PERSISTENT
138 *
139 * @param mode the message delivery mode when sending messages
140 */
141 public void setDeliveryMode(int mode) {
142 _deliveryMode = mode;
143 }
144
145 /***
146 * Get the message delivery mode
147 *
148 * @return the delivery mode used when sending messages
149 */
150 public int getDeliveryMode() {
151 return _deliveryMode;
152 }
153
154 /***
155 * Set the destination type (administered/temporary)
156 *
157 * @param type if true, destinations are administered
158 */
159 public void setAdministered(boolean type) {
160 _administered = type;
161 }
162
163 /***
164 * Determines if destinations are administered or temporary
165 *
166 * @return <code>true</code> if destinations are administered,
167 * <code>false</code> if they are temporary.
168 */
169 public boolean getAdministered() {
170 return _administered;
171 }
172
173 /***
174 * Set the message receipt behaviour
175 *
176 * @param receipt the message receipt behaviour
177 */
178 public void setReceiptType(ReceiptType receipt) {
179 _receipt = receipt;
180 }
181
182 /***
183 * Returns the message receipt behaviour
184 *
185 * @return the message receipt behaviour. May be <code>null</code>
186 */
187 public ReceiptType getReceiptType() {
188 return _receipt;
189 }
190
191 /***
192 * Set the topic subscriber behaviour
193 *
194 * @param durable if true topic subscribers are durable
195 */
196 public void setDurable(boolean durable) {
197 _durable = durable;
198 }
199
200 /***
201 * Returns true if topic subscribers are durable.
202 *
203 * @return true if topic subscribers are durable.
204 */
205 public boolean getDurable() {
206 return _durable;
207 }
208
209 /***
210 * Set the priority of messages.
211 *
212 * @param priority the priority set on a message when it is sent
213 */
214 public void setPriority(int priority) {
215 _priority = priority;
216 }
217
218 /***
219 * Get the message priority used when sending messages
220 *
221 * @return the priority of messages set when they are sent
222 */
223 public int getPriority() {
224 return _priority;
225 }
226
227 /***
228 * Set the time to wait when listening or receiving messages, before
229 * timing out
230 *
231 * @param timeout the time to wait, in milliseconds
232 */
233 public void setTimeout(long timeout) {
234 _timeout = timeout;
235 }
236
237 /***
238 * Get the time to wait when listening or receiving messages
239 *
240 * @return the time to wait, in milliseconds
241 */
242 public long getTimeout() {
243 return _timeout;
244 }
245
246 /***
247 * Returns a string representation of the messaging behaviour
248 *
249 * @return a string representation of this
250 */
251 public String toString() {
252 StringBuffer result = new StringBuffer("delivery mode=");
253 result.append((_deliveryMode == DeliveryMode.PERSISTENT)
254 ? "PERSISTENT" : "NON_PERSISTENT");
255 if (_receipt != null) {
256 result.append(", message consumer type=");
257 result.append(_receipt);
258 }
259 result.append(", destination type=");
260 result.append((_administered) ? "administered" : "temporary");
261 if (_durable) {
262 result.append(", using durable subscriber");
263 }
264 return result.toString();
265 }
266
267 static {
268 final int timeout = 2000;
269 DEFAULT_TIMEOUT = TestProperties.getLong(
270 MessagingBehaviour.class, "timeout", timeout);
271 }
272
273 }
This page was automatically generated by Maven