diff --git a/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java b/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java index b55367fd9f..95f23f7104 100644 --- a/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java +++ b/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java @@ -130,7 +130,7 @@ public class PooledConnectionFactory implements ConnectionFactory, Service { public ConnectionPool makeObject(ConnectionKey key) throws Exception { ActiveMQConnection delegate = createConnection(key); - ConnectionPool connection = new ConnectionPool(delegate); + ConnectionPool connection = createConnectionPool(delegate); connection.setIdleTimeout(getIdleTimeout()); connection.setExpiryTimeout(getExpiryTimeout()); connection.setMaximumActiveSessionPerConnection(getMaximumActiveSessionPerConnection()); @@ -484,4 +484,16 @@ public class PooledConnectionFactory implements ConnectionFactory, Service { */ public void setPoolFactory(ObjectPoolFactory factory) { } + + /** + * Delegate that creates each instance of an ConnectionPool object. Subclasses can override + * this method to customize the type of connection pool returned. + * + * @param connection + * + * @return instance of a new ConnectionPool. + */ + protected ConnectionPool createConnectionPool(ActiveMQConnection connection) { + return new ConnectionPool(connection); + } } diff --git a/activemq-pool/src/main/java/org/apache/activemq/pool/XaPooledConnectionFactory.java b/activemq-pool/src/main/java/org/apache/activemq/pool/XaPooledConnectionFactory.java index bb34730867..dcf6ac2213 100644 --- a/activemq-pool/src/main/java/org/apache/activemq/pool/XaPooledConnectionFactory.java +++ b/activemq-pool/src/main/java/org/apache/activemq/pool/XaPooledConnectionFactory.java @@ -49,6 +49,7 @@ public class XaPooledConnectionFactory extends PooledConnectionFactory { this.transactionManager = transactionManager; } + @Override protected ConnectionPool createConnectionPool(ActiveMQConnection connection) { return new XaConnectionPool(connection, getTransactionManager()); } diff --git a/activemq-pool/src/test/java/org/apache/activemq/pool/XAConnectionPoolTest.java b/activemq-pool/src/test/java/org/apache/activemq/pool/XAConnectionPoolTest.java index 4d29bebb78..f9486df310 100644 --- a/activemq-pool/src/test/java/org/apache/activemq/pool/XAConnectionPoolTest.java +++ b/activemq-pool/src/test/java/org/apache/activemq/pool/XAConnectionPoolTest.java @@ -33,6 +33,7 @@ import javax.transaction.Transaction; import javax.transaction.TransactionManager; import javax.transaction.xa.XAResource; import org.apache.activemq.ActiveMQXAConnectionFactory; +import org.apache.activemq.ActiveMQXASession; import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.test.TestSupport; @@ -122,6 +123,11 @@ public class XAConnectionPoolTest extends TestSupport { TopicConnection connection = (TopicConnection) pcf.createConnection(); TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + + assertTrue(session instanceof PooledSession); + PooledSession pooledSession = (PooledSession) session; + assertTrue(pooledSession.getInternalSession() instanceof ActiveMQXASession); + TopicPublisher publisher = session.createPublisher(topic); publisher.publish(session.createMessage());