001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.activemq.ra; 018 019 import java.io.Serializable; 020 021 import javax.resource.spi.ConnectionRequestInfo; 022 023 import org.apache.activemq.ActiveMQConnectionFactory; 024 import org.apache.activemq.ActiveMQPrefetchPolicy; 025 import org.apache.activemq.RedeliveryPolicy; 026 027 /** 028 * @version $Revision$ Must override equals and hashCode (JCA spec 16.4) 029 */ 030 public class ActiveMQConnectionRequestInfo implements ConnectionRequestInfo, Serializable, Cloneable { 031 032 private static final long serialVersionUID = -5754338187296859149L; 033 034 private String userName; 035 private String password; 036 private String serverUrl; 037 private String clientid; 038 private Boolean useInboundSession; 039 private RedeliveryPolicy redeliveryPolicy; 040 private ActiveMQPrefetchPolicy prefetchPolicy; 041 042 public ActiveMQConnectionRequestInfo copy() { 043 try { 044 ActiveMQConnectionRequestInfo answer = (ActiveMQConnectionRequestInfo)clone(); 045 if (redeliveryPolicy != null) { 046 answer.redeliveryPolicy = redeliveryPolicy.copy(); 047 } 048 return answer; 049 } catch (CloneNotSupportedException e) { 050 throw new RuntimeException("Could not clone: " + e, e); 051 } 052 } 053 054 /** 055 * Returns true if this object will configure an ActiveMQConnectionFactory 056 * in any way 057 */ 058 public boolean isConnectionFactoryConfigured() { 059 return serverUrl != null || clientid != null || redeliveryPolicy != null || prefetchPolicy != null; 060 } 061 062 /** 063 * Configures the given connection factory 064 */ 065 public void configure(ActiveMQConnectionFactory factory) { 066 if (serverUrl != null) { 067 factory.setBrokerURL(serverUrl); 068 } 069 if (clientid != null) { 070 factory.setClientID(clientid); 071 } 072 if (redeliveryPolicy != null) { 073 factory.setRedeliveryPolicy(redeliveryPolicy); 074 } 075 if (prefetchPolicy != null) { 076 factory.setPrefetchPolicy(prefetchPolicy); 077 } 078 } 079 080 /** 081 * @see javax.resource.spi.ConnectionRequestInfo#hashCode() 082 */ 083 public int hashCode() { 084 int rc = 0; 085 if (useInboundSession != null) { 086 rc ^= useInboundSession.hashCode(); 087 } 088 if (serverUrl != null) { 089 rc ^= serverUrl.hashCode(); 090 } 091 return rc; 092 } 093 094 /** 095 * @see javax.resource.spi.ConnectionRequestInfo#equals(java.lang.Object) 096 */ 097 public boolean equals(Object o) { 098 if (o == null) { 099 return false; 100 } 101 if (!getClass().equals(o.getClass())) { 102 return false; 103 } 104 ActiveMQConnectionRequestInfo i = (ActiveMQConnectionRequestInfo)o; 105 if (notEqual(serverUrl, i.serverUrl)) { 106 return false; 107 } 108 if (notEqual(useInboundSession, i.useInboundSession)) { 109 return false; 110 } 111 return true; 112 } 113 114 /** 115 * @param i 116 * @return 117 */ 118 private boolean notEqual(Object o1, Object o2) { 119 return (o1 == null ^ o2 == null) || (o1 != null && !o1.equals(o2)); 120 } 121 122 /** 123 * @return Returns the url. 124 */ 125 public String getServerUrl() { 126 return serverUrl; 127 } 128 129 /** 130 * @param url The url to set. 131 */ 132 public void setServerUrl(String url) { 133 this.serverUrl = url; 134 } 135 136 /** 137 * @return Returns the password. 138 */ 139 public String getPassword() { 140 return password; 141 } 142 143 /** 144 * @param password The password to set. 145 */ 146 public void setPassword(String password) { 147 this.password = password; 148 } 149 150 /** 151 * @return Returns the userid. 152 */ 153 public String getUserName() { 154 return userName; 155 } 156 157 /** 158 * @param userid The userid to set. 159 */ 160 public void setUserName(String userid) { 161 this.userName = userid; 162 } 163 164 /** 165 * @return Returns the clientid. 166 */ 167 public String getClientid() { 168 return clientid; 169 } 170 171 /** 172 * @param clientid The clientid to set. 173 */ 174 public void setClientid(String clientid) { 175 this.clientid = clientid; 176 } 177 178 @Override 179 public String toString() { 180 return new StringBuffer("ActiveMQConnectionRequestInfo{ userName = '").append(userName).append("' ") 181 .append(", serverUrl = '").append(serverUrl).append("' ") 182 .append(", clientid = '").append(clientid).append("' ") 183 .append(", userName = '").append(userName).append("' ") 184 .append(", useInboundSession = '").append(useInboundSession).append("' }") 185 .toString(); 186 } 187 188 public Boolean getUseInboundSession() { 189 return useInboundSession; 190 } 191 192 public void setUseInboundSession(Boolean useInboundSession) { 193 this.useInboundSession = useInboundSession; 194 } 195 196 public boolean isUseInboundSessionEnabled() { 197 return useInboundSession != null && useInboundSession.booleanValue(); 198 } 199 200 public Double getRedeliveryBackOffMultiplier() { 201 return Double.valueOf(redeliveryPolicy().getBackOffMultiplier()); 202 } 203 204 public Long getInitialRedeliveryDelay() { 205 return Long.valueOf(redeliveryPolicy().getInitialRedeliveryDelay()); 206 } 207 208 public Integer getMaximumRedeliveries() { 209 return Integer.valueOf(redeliveryPolicy().getMaximumRedeliveries()); 210 } 211 212 public Boolean getRedeliveryUseExponentialBackOff() { 213 return Boolean.valueOf(redeliveryPolicy().isUseExponentialBackOff()); 214 } 215 216 public void setRedeliveryBackOffMultiplier(Short value) { 217 if (value != null) { 218 redeliveryPolicy().setBackOffMultiplier(value.shortValue()); 219 } 220 } 221 222 public void setInitialRedeliveryDelay(Long value) { 223 if (value != null) { 224 redeliveryPolicy().setInitialRedeliveryDelay(value.longValue()); 225 } 226 } 227 228 public void setMaximumRedeliveries(Integer value) { 229 if (value != null) { 230 redeliveryPolicy().setMaximumRedeliveries(value.intValue()); 231 } 232 } 233 234 public void setRedeliveryUseExponentialBackOff(Boolean value) { 235 if (value != null) { 236 redeliveryPolicy().setUseExponentialBackOff(value.booleanValue()); 237 } 238 } 239 240 public Integer getDurableTopicPrefetch() { 241 return Integer.valueOf(prefetchPolicy().getDurableTopicPrefetch()); 242 } 243 244 public Integer getInputStreamPrefetch() { 245 return Integer.valueOf(prefetchPolicy().getInputStreamPrefetch()); 246 } 247 248 public Integer getQueueBrowserPrefetch() { 249 return Integer.valueOf(prefetchPolicy().getQueueBrowserPrefetch()); 250 } 251 252 public Integer getQueuePrefetch() { 253 return Integer.valueOf(prefetchPolicy().getQueuePrefetch()); 254 } 255 256 public Integer getTopicPrefetch() { 257 return Integer.valueOf(prefetchPolicy().getTopicPrefetch()); 258 } 259 260 public void setAllPrefetchValues(Integer i) { 261 if (i != null) { 262 prefetchPolicy().setAll(i.intValue()); 263 } 264 } 265 266 public void setDurableTopicPrefetch(Integer durableTopicPrefetch) { 267 if (durableTopicPrefetch != null) { 268 prefetchPolicy().setDurableTopicPrefetch(durableTopicPrefetch.intValue()); 269 } 270 } 271 272 public void setInputStreamPrefetch(Integer inputStreamPrefetch) { 273 if (inputStreamPrefetch != null) { 274 prefetchPolicy().setInputStreamPrefetch(inputStreamPrefetch.intValue()); 275 } 276 } 277 278 public void setQueueBrowserPrefetch(Integer queueBrowserPrefetch) { 279 if (queueBrowserPrefetch != null) { 280 prefetchPolicy().setQueueBrowserPrefetch(queueBrowserPrefetch.intValue()); 281 } 282 } 283 284 public void setQueuePrefetch(Integer queuePrefetch) { 285 if (queuePrefetch != null) { 286 prefetchPolicy().setQueuePrefetch(queuePrefetch.intValue()); 287 } 288 } 289 290 public void setTopicPrefetch(Integer topicPrefetch) { 291 if (topicPrefetch != null) { 292 prefetchPolicy().setTopicPrefetch(topicPrefetch.intValue()); 293 } 294 } 295 296 /** 297 * Returns the redelivery policy; not using bean properties to avoid 298 * breaking compatibility with JCA configuration in J2EE 299 */ 300 public RedeliveryPolicy redeliveryPolicy() { 301 if (redeliveryPolicy == null) { 302 redeliveryPolicy = new RedeliveryPolicy(); 303 } 304 return redeliveryPolicy; 305 } 306 307 /** 308 * Returns the prefetch policy; not using bean properties to avoid breaking 309 * compatibility with JCA configuration in J2EE 310 */ 311 public ActiveMQPrefetchPolicy prefetchPolicy() { 312 if (prefetchPolicy == null) { 313 prefetchPolicy = new ActiveMQPrefetchPolicy(); 314 } 315 return prefetchPolicy; 316 } 317 }