KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ra > ActiveMQConnectionRequestInfo


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.ra;
19
20 import org.apache.activemq.ActiveMQPrefetchPolicy;
21 import org.apache.activemq.RedeliveryPolicy;
22 import org.apache.activemq.ActiveMQConnectionFactory;
23
24 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
25 import java.io.Serializable JavaDoc;
26
27 /**
28  * @version $Revision$
29  *
30  * Must override equals and hashCode (JCA spec 16.4)
31  */

32 public class ActiveMQConnectionRequestInfo implements ConnectionRequestInfo JavaDoc, Serializable JavaDoc, Cloneable JavaDoc {
33
34     private static final long serialVersionUID = -5754338187296859149L;
35
36     private String JavaDoc userName;
37     private String JavaDoc password;
38     private String JavaDoc serverUrl;
39     private String JavaDoc clientid;
40     private Boolean JavaDoc useInboundSession;
41     private RedeliveryPolicy redeliveryPolicy;
42     private ActiveMQPrefetchPolicy prefetchPolicy;
43
44     public ActiveMQConnectionRequestInfo copy() {
45         try {
46             ActiveMQConnectionRequestInfo answer = (ActiveMQConnectionRequestInfo) clone();
47             if (redeliveryPolicy != null) {
48                 answer.redeliveryPolicy = redeliveryPolicy.copy();
49             }
50             return answer;
51         }
52         catch (CloneNotSupportedException JavaDoc e) {
53             throw new RuntimeException JavaDoc("Could not clone: " + e, e);
54         }
55     }
56
57     /**
58      * Returns true if this object will configure an ActiveMQConnectionFactory in any way
59      */

60     public boolean isConnectionFactoryConfigured() {
61         return serverUrl != null || clientid != null || redeliveryPolicy != null || prefetchPolicy != null;
62     }
63
64     /**
65      * Configures the given connection factory
66      */

67     public void configure(ActiveMQConnectionFactory factory) {
68         if (serverUrl != null) {
69             factory.setBrokerURL(serverUrl);
70         }
71         if (clientid != null) {
72             factory.setClientID(clientid);
73         }
74         if (redeliveryPolicy != null) {
75             factory.setRedeliveryPolicy(redeliveryPolicy);
76         }
77         if (prefetchPolicy != null) {
78             factory.setPrefetchPolicy(prefetchPolicy);
79         }
80     }
81     
82     /**
83      * @see javax.resource.spi.ConnectionRequestInfo#hashCode()
84      */

85     public int hashCode() {
86         int rc = 0;
87         if (useInboundSession != null) {
88             rc ^= useInboundSession.hashCode();
89         }
90         if (serverUrl != null) {
91             rc ^= serverUrl.hashCode();
92         }
93         return rc;
94     }
95
96     /**
97      * @see javax.resource.spi.ConnectionRequestInfo#equals(java.lang.Object)
98      */

99     public boolean equals(Object JavaDoc o) {
100         if (o == null) {
101             return false;
102         }
103         if (!getClass().equals(o.getClass())) {
104             return false;
105         }
106         ActiveMQConnectionRequestInfo i = (ActiveMQConnectionRequestInfo) o;
107         if (notEqual(serverUrl, i.serverUrl)) {
108             return false;
109         }
110         if (notEqual(useInboundSession, i.useInboundSession)) {
111             return false;
112         }
113         return true;
114     }
115
116     /**
117      * @param i
118      * @return
119      */

120     private boolean notEqual(Object JavaDoc o1, Object JavaDoc o2) {
121         return (o1 == null ^ o2 == null) || (o1 != null && !o1.equals(o2));
122     }
123
124     /**
125      * @return Returns the url.
126      */

127     public String JavaDoc getServerUrl() {
128         return serverUrl;
129     }
130
131     /**
132      * @param url
133      * The url to set.
134      */

135     public void setServerUrl(String JavaDoc url) {
136         this.serverUrl = url;
137     }
138
139     /**
140      * @return Returns the password.
141      */

142     public String JavaDoc getPassword() {
143         return password;
144     }
145
146     /**
147      * @param password
148      * The password to set.
149      */

150     public void setPassword(String JavaDoc password) {
151         this.password = password;
152     }
153
154     /**
155      * @return Returns the userid.
156      */

157     public String JavaDoc getUserName() {
158         return userName;
159     }
160
161     /**
162      * @param userid
163      * The userid to set.
164      */

165     public void setUserName(String JavaDoc userid) {
166         this.userName = userid;
167     }
168
169     /**
170      * @return Returns the clientid.
171      */

172     public String JavaDoc getClientid() {
173         return clientid;
174     }
175
176     /**
177      * @param clientid
178      * The clientid to set.
179      */

180     public void setClientid(String JavaDoc clientid) {
181         this.clientid = clientid;
182     }
183
184     public String JavaDoc toString() {
185         return "ActiveMQConnectionRequestInfo{ " + "userName = '" + userName + "' " + ", serverUrl = '" + serverUrl + "' " + ", clientid = '" + clientid + "' "
186                 + ", userName = '" + userName + "' " + ", useInboundSession = '" + useInboundSession + "' " + " }";
187     }
188
189     public Boolean JavaDoc getUseInboundSession() {
190         return useInboundSession;
191     }
192
193     public void setUseInboundSession(Boolean JavaDoc useInboundSession) {
194         this.useInboundSession = useInboundSession;
195     }
196
197     public boolean isUseInboundSessionEnabled() {
198         return useInboundSession != null && useInboundSession.booleanValue();
199     }
200
201     public Short JavaDoc getRedeliveryBackOffMultiplier() {
202         return new Short JavaDoc(redeliveryPolicy().getBackOffMultiplier());
203     }
204
205     public Long JavaDoc getInitialRedeliveryDelay() {
206         return new Long JavaDoc(redeliveryPolicy().getInitialRedeliveryDelay());
207     }
208
209     public Integer JavaDoc getMaximumRedeliveries() {
210         return new Integer JavaDoc(redeliveryPolicy().getMaximumRedeliveries());
211     }
212
213     public Boolean JavaDoc getRedeliveryUseExponentialBackOff() {
214         return new Boolean JavaDoc(redeliveryPolicy().isUseExponentialBackOff());
215     }
216
217     public void setRedeliveryBackOffMultiplier(Short JavaDoc value) {
218         if (value != null) {
219             redeliveryPolicy().setBackOffMultiplier(value.shortValue());
220         }
221     }
222
223     public void setInitialRedeliveryDelay(Long JavaDoc value) {
224         if (value != null) {
225             redeliveryPolicy().setInitialRedeliveryDelay(value.longValue());
226         }
227     }
228
229     public void setMaximumRedeliveries(Integer JavaDoc value) {
230         if (value != null) {
231             redeliveryPolicy().setMaximumRedeliveries(value.intValue());
232         }
233     }
234
235     public void setRedeliveryUseExponentialBackOff(Boolean JavaDoc value) {
236         if (value != null) {
237             redeliveryPolicy().setUseExponentialBackOff(value.booleanValue());
238         }
239     }
240
241     public Integer JavaDoc getDurableTopicPrefetch() {
242         return new Integer JavaDoc(prefetchPolicy().getDurableTopicPrefetch());
243     }
244
245     public Integer JavaDoc getInputStreamPrefetch() {
246         return new Integer JavaDoc(prefetchPolicy().getInputStreamPrefetch());
247     }
248
249     public Integer JavaDoc getQueueBrowserPrefetch() {
250         return new Integer JavaDoc(prefetchPolicy().getQueueBrowserPrefetch());
251     }
252
253     public Integer JavaDoc getQueuePrefetch() {
254         return new Integer JavaDoc(prefetchPolicy().getQueuePrefetch());
255     }
256
257     public Integer JavaDoc getTopicPrefetch() {
258         return new Integer JavaDoc(prefetchPolicy().getTopicPrefetch());
259     }
260
261     public void setAllPrefetchValues(Integer JavaDoc i) {
262         if (i != null) {
263             prefetchPolicy().setAll(i.intValue());
264         }
265     }
266
267     public void setDurableTopicPrefetch(Integer JavaDoc durableTopicPrefetch) {
268         if (durableTopicPrefetch != null) {
269             prefetchPolicy().setDurableTopicPrefetch(durableTopicPrefetch.intValue());
270         }
271     }
272
273     public void setInputStreamPrefetch(Integer JavaDoc inputStreamPrefetch) {
274         if (inputStreamPrefetch != null) {
275             prefetchPolicy().setInputStreamPrefetch(inputStreamPrefetch.intValue());
276         }
277     }
278
279     public void setQueueBrowserPrefetch(Integer JavaDoc queueBrowserPrefetch) {
280         if (queueBrowserPrefetch != null) {
281             prefetchPolicy().setQueueBrowserPrefetch(queueBrowserPrefetch.intValue());
282         }
283     }
284
285     public void setQueuePrefetch(Integer JavaDoc queuePrefetch) {
286         if (queuePrefetch != null) {
287             prefetchPolicy().setQueuePrefetch(queuePrefetch.intValue());
288         }
289     }
290
291     public void setTopicPrefetch(Integer JavaDoc topicPrefetch) {
292         if (topicPrefetch != null) {
293             prefetchPolicy().setTopicPrefetch(topicPrefetch.intValue());
294         }
295     }
296
297     /**
298      * Returns the redelivery policy; not using bean properties to avoid
299      * breaking compatibility with JCA configuration in J2EE
300      */

301     public RedeliveryPolicy redeliveryPolicy() {
302         if (redeliveryPolicy == null) {
303             redeliveryPolicy = new RedeliveryPolicy();
304         }
305         return redeliveryPolicy;
306     }
307
308     /**
309      * Returns the prefetch policy; not using bean properties to avoid
310      * breaking compatibility with JCA configuration in J2EE
311      */

312     public ActiveMQPrefetchPolicy prefetchPolicy() {
313         if (prefetchPolicy == null) {
314             prefetchPolicy = new ActiveMQPrefetchPolicy();
315         }
316         return prefetchPolicy;
317     }
318 }
319
Popular Tags