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: AckType.java,v 1.4 2004/01/31 13:44:24 tanderson Exp $
44 */
45 package org.exolab.jmscts.core;
46
47 import javax.jms.Session;
48
49
50 /***
51 * Helper class used to indicate what message acknowledgement type should be
52 * used to run a particular test case against
53 *
54 * @version $Revision: 1.4 $ $Date: 2004/01/31 13:44:24 $
55 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
56 * @see AckTypes
57 * @see SessionTestCase
58 * @see SessionTestRunner
59 */
60 public final class AckType {
61
62 /***
63 * Transacted session
64 */
65 public static final AckType TRANSACTED;
66
67 /***
68 * Non-transacted session, session automatically acknowledges messages
69 */
70 public static final AckType AUTO_ACKNOWLEDGE;
71
72 /***
73 * Non-transacted session, client ackwnowledges messages
74 */
75 public static final AckType CLIENT_ACKNOWLEDGE;
76
77 /***
78 * Non-transacted session, messages are lazily acknowledged
79 */
80 public static final AckType DUPS_OK_ACKNOWLEDGE;
81
82
83 /***
84 * If true, the messages should be acknowledged by a transacted session
85 */
86 private final boolean _transacted;
87
88 /***
89 * The acknowledgement mode, for non-transacted sessions
90 */
91 private final int _acknowledgeMode;
92
93 /***
94 * Create an instance for a transacted session
95 */
96 private AckType() {
97 _transacted = true;
98 _acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
99 }
100
101 /***
102 * Create an instance for a non-transacted session
103 *
104 * @param acknowledgeMode indicates whether the consumer or the client
105 * will acknowledge any messages it receives. Legal values are
106 * <code>Session.AUTO_ACKNOWLEDGE</code>,
107 * <code>Session.CLIENT_ACKNOWLEDGE</code> and
108 * <code>Session.DUPS_OK_ACKNOWLEDGE</code>.
109 */
110 private AckType(int acknowledgeMode) {
111 _transacted = false;
112 _acknowledgeMode = acknowledgeMode;
113 }
114
115 /***
116 * Returns if the session should be transactional
117 *
118 * @return true if the session should be transactional
119 */
120 public boolean getTransacted() {
121 return _transacted;
122 }
123
124 /***
125 * Returns the acknowledgement mode. This is only applicable for
126 * non-transacted sessions.
127 *
128 * @return the session acknowledgement mode
129 */
130 public int getAcknowledgeMode() {
131 return _acknowledgeMode;
132 }
133
134 /***
135 * Determines if this acknowledgement mode is equal to another object
136 *
137 * @param obj the object to compare
138 * @return <code>true</code> if equal, otherwise <code>false</code>
139 */
140 public boolean equals(Object obj) {
141 boolean equal = false;
142 if (obj instanceof AckType) {
143 AckType type = (AckType) obj;
144 if (_transacted == type._transacted
145 && _acknowledgeMode == type._acknowledgeMode) {
146 equal = true;
147 }
148 }
149 return equal;
150 }
151
152 /***
153 * Returns a hash code value for the object
154 *
155 * @return a hash code value for the object
156 */
157 public int hashCode() {
158 return toString().hashCode();
159 }
160
161 /***
162 * Returns a string representation of the acknowledgement type
163 *
164 * @return a string representation of this
165 */
166 public String toString() {
167 String result = null;
168 if (_transacted) {
169 result = "TRANSACTED";
170 } else {
171 switch (_acknowledgeMode) {
172 case Session.AUTO_ACKNOWLEDGE:
173 result = "AUTO_ACKNOWLEDGE";
174 break;
175 case Session.CLIENT_ACKNOWLEDGE:
176 result = "CLIENT_ACKNOWLEDGE";
177 break;
178 default:
179 result = "DUPS_OK_ACKNOWLEDGE";
180 }
181 }
182 return result;
183 }
184
185 /***
186 * Helper to convert a stringified acknowledgement type to a
187 * <code>AckType</code> instance
188 *
189 * @param type the acknowledgement type
190 * @return an instance corresponding to <code>type</code>
191 */
192 public static AckType fromString(String type) {
193 AckType result = null;
194 if (type.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) {
195 result = AUTO_ACKNOWLEDGE;
196 } else if (type.equalsIgnoreCase("CLIENT_ACKNOWLEDGE")) {
197 result = CLIENT_ACKNOWLEDGE;
198 } else if (type.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) {
199 result = DUPS_OK_ACKNOWLEDGE;
200 } else if (type.equalsIgnoreCase("TRANSACTED")) {
201 result = TRANSACTED;
202 } else {
203 throw new IllegalArgumentException("Invalid ack type: " + type);
204 }
205 return result;
206 }
207
208 static {
209 TRANSACTED = new AckType();
210 AUTO_ACKNOWLEDGE = new AckType(Session.AUTO_ACKNOWLEDGE);
211 CLIENT_ACKNOWLEDGE = new AckType(Session.CLIENT_ACKNOWLEDGE);
212 DUPS_OK_ACKNOWLEDGE = new AckType(Session.DUPS_OK_ACKNOWLEDGE);
213 }
214
215 }
This page was automatically generated by Maven