1 18 package org.apache.activemq.ra; 19 20 import java.io.PrintWriter ; 21 import java.util.Iterator ; 22 import java.util.Set ; 23 24 import javax.jms.JMSException ; 25 import javax.resource.ResourceException ; 26 import javax.resource.spi.ConnectionManager ; 27 import javax.resource.spi.ConnectionRequestInfo ; 28 import javax.resource.spi.ManagedConnection ; 29 import javax.resource.spi.ManagedConnectionFactory ; 30 import javax.resource.spi.ResourceAdapter ; 31 import javax.resource.spi.ResourceAdapterAssociation ; 32 import javax.security.auth.Subject ; 33 34 41 public class ActiveMQManagedConnectionFactory implements ManagedConnectionFactory , ResourceAdapterAssociation { 42 43 private static final long serialVersionUID = 6196921962230582875L; 44 45 private MessageResourceAdapter adapter; 46 private PrintWriter logWriter; 47 private ActiveMQConnectionRequestInfo info = new ActiveMQConnectionRequestInfo(); 48 49 52 public void setResourceAdapter(ResourceAdapter adapter) throws ResourceException { 53 if (!(adapter instanceof MessageResourceAdapter)) { 54 throw new ResourceException ("ResourceAdapter is not of type: " + MessageResourceAdapter.class.getName()); 55 } 56 this.adapter = (MessageResourceAdapter) adapter; 57 ActiveMQConnectionRequestInfo baseInfo = this.adapter.getInfo().copy(); 58 if (info.getClientid() == null) 59 info.setClientid(baseInfo.getClientid()); 60 if (info.getPassword() == null) 61 info.setPassword(baseInfo.getPassword()); 62 if (info.getServerUrl() == null) 63 info.setServerUrl(baseInfo.getServerUrl()); 64 if (info.getUseInboundSession() == null) 65 info.setUseInboundSession(baseInfo.getUseInboundSession()); 66 if (info.getUserName() == null) 67 info.setUserName(baseInfo.getUserName()); 68 } 69 70 73 @Override 74 public boolean equals(Object object) { 75 if( object == null || object.getClass()!=ActiveMQManagedConnectionFactory.class ) { 76 return false; 77 } 78 return ((ActiveMQManagedConnectionFactory)object).info.equals(info); 79 } 80 81 84 @Override 85 public int hashCode() { 86 return info.hashCode(); 87 } 88 89 90 93 public ResourceAdapter getResourceAdapter() { 94 return adapter; 95 } 96 97 100 public Object createConnectionFactory(ConnectionManager manager) throws ResourceException { 101 return new ActiveMQConnectionFactory(this, manager, info); 102 } 103 104 112 public Object createConnectionFactory() throws ResourceException { 113 return new ActiveMQConnectionFactory(this, new SimpleConnectionManager(), info); 114 } 115 116 120 public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo info) throws ResourceException { 121 try { 122 if( info == null ) { 123 info = this.info; 124 } 125 ActiveMQConnectionRequestInfo amqInfo = (ActiveMQConnectionRequestInfo) info; 126 return new ActiveMQManagedConnection(subject, adapter.makeConnection(amqInfo), amqInfo); 127 } 128 catch (JMSException e) { 129 throw new ResourceException ("Could not create connection.", e); 130 } 131 } 132 133 138 public ManagedConnection matchManagedConnections(Set connections, Subject subject, ConnectionRequestInfo info) throws ResourceException { 139 Iterator iterator = connections.iterator(); 140 while (iterator.hasNext()) { 141 ActiveMQManagedConnection c = (ActiveMQManagedConnection) iterator.next(); 142 if (c.matches(subject, info)) { 143 try { 144 c.associate(subject, (ActiveMQConnectionRequestInfo) info); 145 return c; 146 } 147 catch (JMSException e) { 148 throw new ResourceException (e); 149 } 150 } 151 } 152 return null; 153 } 154 155 158 public void setLogWriter(PrintWriter logWriter) throws ResourceException { 159 this.logWriter = logWriter; 160 } 161 162 165 public PrintWriter getLogWriter() throws ResourceException { 166 return logWriter; 167 } 168 169 175 178 public String getClientid() { 179 return info.getClientid(); 180 } 181 182 185 public String getPassword() { 186 return info.getPassword(); 187 } 188 189 192 public String getUserName() { 193 return info.getUserName(); 194 } 195 196 199 public void setClientid(String clientid) { 200 info.setClientid(clientid); 201 } 202 203 206 public void setPassword(String password) { 207 info.setPassword(password); 208 } 209 210 213 public void setUserName(String userid) { 214 info.setUserName(userid); 215 } 216 217 220 223 public Boolean getUseInboundSession() { 224 return info.getUseInboundSession(); 225 } 226 227 230 public void setUseInboundSession(Boolean useInboundSession) { 231 info.setUseInboundSession(useInboundSession); 232 } 233 234 237 public boolean isUseInboundSessionEnabled() { 238 return info.isUseInboundSessionEnabled(); 239 } 240 241 245 public Long getInitialRedeliveryDelay() { 246 return info.getInitialRedeliveryDelay(); 247 } 248 249 252 public Integer getMaximumRedeliveries() { 253 return info.getMaximumRedeliveries(); 254 } 255 256 259 public Short getRedeliveryBackOffMultiplier() { 260 return info.getRedeliveryBackOffMultiplier(); 261 } 262 263 266 public Boolean getRedeliveryUseExponentialBackOff() { 267 return info.getRedeliveryUseExponentialBackOff(); 268 } 269 270 273 public void setInitialRedeliveryDelay(Long value) { 274 info.setInitialRedeliveryDelay(value); 275 } 276 277 280 public void setMaximumRedeliveries(Integer value) { 281 info.setMaximumRedeliveries(value); 282 } 283 284 287 public void setRedeliveryBackOffMultiplier(Short value) { 288 info.setRedeliveryBackOffMultiplier(value); 289 } 290 291 294 public void setRedeliveryUseExponentialBackOff(Boolean value) { 295 info.setRedeliveryUseExponentialBackOff(value); 296 } 297 298 299 303 public Integer getDurableTopicPrefetch() { 304 return info.getDurableTopicPrefetch(); 305 } 306 307 310 public Integer getInputStreamPrefetch() { 311 return info.getInputStreamPrefetch(); 312 } 313 314 317 public Integer getQueueBrowserPrefetch() { 318 return info.getQueueBrowserPrefetch(); 319 } 320 321 324 public Integer getQueuePrefetch() { 325 return info.getQueuePrefetch(); 326 } 327 328 331 public Integer getTopicPrefetch() { 332 return info.getTopicPrefetch(); 333 } 334 335 338 public void setAllPrefetchValues(Integer i) { 339 info.setAllPrefetchValues(i); 340 } 341 342 345 public void setDurableTopicPrefetch(Integer durableTopicPrefetch) { 346 info.setDurableTopicPrefetch(durableTopicPrefetch); 347 } 348 349 352 public void setInputStreamPrefetch(Integer inputStreamPrefetch) { 353 info.setInputStreamPrefetch(inputStreamPrefetch); 354 } 355 356 359 public void setQueueBrowserPrefetch(Integer queueBrowserPrefetch) { 360 info.setQueueBrowserPrefetch(queueBrowserPrefetch); 361 } 362 363 366 public void setQueuePrefetch(Integer queuePrefetch) { 367 info.setQueuePrefetch(queuePrefetch); 368 } 369 370 373 public void setTopicPrefetch(Integer topicPrefetch) { 374 info.setTopicPrefetch(topicPrefetch); 375 } 376 } 377 | Popular Tags |