1 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 ; 25 import java.io.Serializable ; 26 27 32 public class ActiveMQConnectionRequestInfo implements ConnectionRequestInfo , Serializable , Cloneable { 33 34 private static final long serialVersionUID = -5754338187296859149L; 35 36 private String userName; 37 private String password; 38 private String serverUrl; 39 private String clientid; 40 private Boolean 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 e) { 53 throw new RuntimeException ("Could not clone: " + e, e); 54 } 55 } 56 57 60 public boolean isConnectionFactoryConfigured() { 61 return serverUrl != null || clientid != null || redeliveryPolicy != null || prefetchPolicy != null; 62 } 63 64 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 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 99 public boolean equals(Object 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 120 private boolean notEqual(Object o1, Object o2) { 121 return (o1 == null ^ o2 == null) || (o1 != null && !o1.equals(o2)); 122 } 123 124 127 public String getServerUrl() { 128 return serverUrl; 129 } 130 131 135 public void setServerUrl(String url) { 136 this.serverUrl = url; 137 } 138 139 142 public String getPassword() { 143 return password; 144 } 145 146 150 public void setPassword(String password) { 151 this.password = password; 152 } 153 154 157 public String getUserName() { 158 return userName; 159 } 160 161 165 public void setUserName(String userid) { 166 this.userName = userid; 167 } 168 169 172 public String getClientid() { 173 return clientid; 174 } 175 176 180 public void setClientid(String clientid) { 181 this.clientid = clientid; 182 } 183 184 public String toString() { 185 return "ActiveMQConnectionRequestInfo{ " + "userName = '" + userName + "' " + ", serverUrl = '" + serverUrl + "' " + ", clientid = '" + clientid + "' " 186 + ", userName = '" + userName + "' " + ", useInboundSession = '" + useInboundSession + "' " + " }"; 187 } 188 189 public Boolean getUseInboundSession() { 190 return useInboundSession; 191 } 192 193 public void setUseInboundSession(Boolean useInboundSession) { 194 this.useInboundSession = useInboundSession; 195 } 196 197 public boolean isUseInboundSessionEnabled() { 198 return useInboundSession != null && useInboundSession.booleanValue(); 199 } 200 201 public Short getRedeliveryBackOffMultiplier() { 202 return new Short (redeliveryPolicy().getBackOffMultiplier()); 203 } 204 205 public Long getInitialRedeliveryDelay() { 206 return new Long (redeliveryPolicy().getInitialRedeliveryDelay()); 207 } 208 209 public Integer getMaximumRedeliveries() { 210 return new Integer (redeliveryPolicy().getMaximumRedeliveries()); 211 } 212 213 public Boolean getRedeliveryUseExponentialBackOff() { 214 return new Boolean (redeliveryPolicy().isUseExponentialBackOff()); 215 } 216 217 public void setRedeliveryBackOffMultiplier(Short value) { 218 if (value != null) { 219 redeliveryPolicy().setBackOffMultiplier(value.shortValue()); 220 } 221 } 222 223 public void setInitialRedeliveryDelay(Long value) { 224 if (value != null) { 225 redeliveryPolicy().setInitialRedeliveryDelay(value.longValue()); 226 } 227 } 228 229 public void setMaximumRedeliveries(Integer value) { 230 if (value != null) { 231 redeliveryPolicy().setMaximumRedeliveries(value.intValue()); 232 } 233 } 234 235 public void setRedeliveryUseExponentialBackOff(Boolean value) { 236 if (value != null) { 237 redeliveryPolicy().setUseExponentialBackOff(value.booleanValue()); 238 } 239 } 240 241 public Integer getDurableTopicPrefetch() { 242 return new Integer (prefetchPolicy().getDurableTopicPrefetch()); 243 } 244 245 public Integer getInputStreamPrefetch() { 246 return new Integer (prefetchPolicy().getInputStreamPrefetch()); 247 } 248 249 public Integer getQueueBrowserPrefetch() { 250 return new Integer (prefetchPolicy().getQueueBrowserPrefetch()); 251 } 252 253 public Integer getQueuePrefetch() { 254 return new Integer (prefetchPolicy().getQueuePrefetch()); 255 } 256 257 public Integer getTopicPrefetch() { 258 return new Integer (prefetchPolicy().getTopicPrefetch()); 259 } 260 261 public void setAllPrefetchValues(Integer i) { 262 if (i != null) { 263 prefetchPolicy().setAll(i.intValue()); 264 } 265 } 266 267 public void setDurableTopicPrefetch(Integer durableTopicPrefetch) { 268 if (durableTopicPrefetch != null) { 269 prefetchPolicy().setDurableTopicPrefetch(durableTopicPrefetch.intValue()); 270 } 271 } 272 273 public void setInputStreamPrefetch(Integer inputStreamPrefetch) { 274 if (inputStreamPrefetch != null) { 275 prefetchPolicy().setInputStreamPrefetch(inputStreamPrefetch.intValue()); 276 } 277 } 278 279 public void setQueueBrowserPrefetch(Integer queueBrowserPrefetch) { 280 if (queueBrowserPrefetch != null) { 281 prefetchPolicy().setQueueBrowserPrefetch(queueBrowserPrefetch.intValue()); 282 } 283 } 284 285 public void setQueuePrefetch(Integer queuePrefetch) { 286 if (queuePrefetch != null) { 287 prefetchPolicy().setQueuePrefetch(queuePrefetch.intValue()); 288 } 289 } 290 291 public void setTopicPrefetch(Integer topicPrefetch) { 292 if (topicPrefetch != null) { 293 prefetchPolicy().setTopicPrefetch(topicPrefetch.intValue()); 294 } 295 } 296 297 301 public RedeliveryPolicy redeliveryPolicy() { 302 if (redeliveryPolicy == null) { 303 redeliveryPolicy = new RedeliveryPolicy(); 304 } 305 return redeliveryPolicy; 306 } 307 308 312 public ActiveMQPrefetchPolicy prefetchPolicy() { 313 if (prefetchPolicy == null) { 314 prefetchPolicy = new ActiveMQPrefetchPolicy(); 315 } 316 return prefetchPolicy; 317 } 318 } 319 | Popular Tags |