1 18 package org.apache.activemq.ra; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 23 import javax.jms.Connection ; 24 import javax.jms.ConnectionFactory ; 25 import javax.jms.JMSException ; 26 import javax.jms.QueueConnectionFactory ; 27 import javax.jms.QueueConnection ; 28 import javax.jms.TopicConnectionFactory ; 29 import javax.jms.TopicConnection ; 30 import javax.naming.Reference ; 31 import javax.resource.Referenceable ; 32 import javax.resource.ResourceException ; 33 import javax.resource.spi.ConnectionManager ; 34 import java.io.Serializable ; 35 36 37 40 public class ActiveMQConnectionFactory implements ConnectionFactory , QueueConnectionFactory , TopicConnectionFactory , Referenceable , Serializable { 41 42 private static final long serialVersionUID = -5754338187296859149L; 43 44 private static final Log log = LogFactory.getLog(ActiveMQConnectionFactory.class); 45 private ConnectionManager manager; 46 transient private ActiveMQManagedConnectionFactory factory; 47 private Reference reference; 48 private final ActiveMQConnectionRequestInfo info; 49 50 51 56 public ActiveMQConnectionFactory(ActiveMQManagedConnectionFactory factory, ConnectionManager manager, ActiveMQConnectionRequestInfo info) { 57 this.factory = factory; 58 this.manager = manager; 59 this.info = info; 60 } 61 62 65 public Connection createConnection() throws JMSException { 66 return createConnection(info.copy()); 67 } 68 69 72 public Connection createConnection(String userName, String password) throws JMSException { 73 ActiveMQConnectionRequestInfo i = info.copy(); 74 i.setUserName(userName); 75 i.setPassword(password); 76 return createConnection(i); 77 } 78 79 84 private Connection createConnection(ActiveMQConnectionRequestInfo info) throws JMSException { 85 try { 86 if( info.isUseInboundSessionEnabled() ) { 87 return new InboundConnectionProxy(); 88 } 89 if (manager == null) { 90 throw new JMSException ("No JCA ConnectionManager configured! Either enable UseInboundSessionEnabled or get your JCA container to configure one."); 91 } 92 return (Connection ) manager.allocateConnection(factory, info); 93 } 94 catch (ResourceException e) { 95 if (e.getCause() instanceof JMSException ) { 97 throw (JMSException ) e.getCause(); 98 } 99 log.debug("Connection could not be created:", e); 100 throw new JMSException (e.getMessage()); 101 } 102 } 103 104 107 public Reference getReference() { 108 return reference; 109 } 110 111 114 public void setReference(Reference reference) { 115 this.reference = reference; 116 } 117 118 public QueueConnection createQueueConnection() throws JMSException { 119 return (QueueConnection ) createConnection(); 120 } 121 122 public QueueConnection createQueueConnection(String userName, String password) throws JMSException { 123 return (QueueConnection ) createConnection(userName, password); 124 } 125 126 public TopicConnection createTopicConnection() throws JMSException { 127 return (TopicConnection ) createConnection(); 128 } 129 130 public TopicConnection createTopicConnection(String userName, String password) throws JMSException { 131 return (TopicConnection ) createConnection(userName, password); 132 } 133 } 134 | Popular Tags |