From 320d87cfce4b9b5e6d6f0d0cfb994334b976f934 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Wed, 17 Aug 2011 13:29:35 +0000 Subject: [PATCH] Apply patch for: https://issues.apache.org/jira/browse/AMQ-3457 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1158694 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/activemq/pool/ConnectionPool.java | 6 ++++ .../activemq/pool/PooledConnection.java | 7 ----- ...nFactoryWithTemporaryDestinationsTest.java | 30 +++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/activemq-pool/src/main/java/org/apache/activemq/pool/ConnectionPool.java b/activemq-pool/src/main/java/org/apache/activemq/pool/ConnectionPool.java index 741faac5f8..8695865f4e 100644 --- a/activemq-pool/src/main/java/org/apache/activemq/pool/ConnectionPool.java +++ b/activemq-pool/src/main/java/org/apache/activemq/pool/ConnectionPool.java @@ -144,6 +144,12 @@ public class ConnectionPool { lastUsed = System.currentTimeMillis(); if (referenceCount == 0) { expiredCheck(); + + // only clean up temp destinations when all users + // of this connection have called close + if (getConnection() != null) { + getConnection().cleanUpTempDestinations(); + } } } diff --git a/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnection.java b/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnection.java index a8d79164d4..d657706514 100755 --- a/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnection.java +++ b/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnection.java @@ -16,9 +16,6 @@ */ package org.apache.activemq.pool; -import java.util.Iterator; -import java.util.concurrent.ConcurrentHashMap; - import javax.jms.Connection; import javax.jms.ConnectionConsumer; import javax.jms.ConnectionMetaData; @@ -39,7 +36,6 @@ import org.apache.activemq.ActiveMQSession; import org.apache.activemq.AlreadyClosedException; import org.apache.activemq.EnhancedConnection; import org.apache.activemq.advisory.DestinationSource; -import org.apache.activemq.command.ActiveMQTempDestination; /** * Represents a proxy {@link Connection} which is-a {@link TopicConnection} and @@ -73,9 +69,6 @@ public class PooledConnection implements TopicConnection, QueueConnection, Enhan public void close() throws JMSException { if (this.pool != null) { this.pool.decrementReferenceCount(); - if (this.pool.getConnection() != null) { - this.pool.getConnection().cleanUpTempDestinations(); - } this.pool = null; } } diff --git a/activemq-pool/src/test/java/org/apache/activemq/pool/PooledConnectionFactoryWithTemporaryDestinationsTest.java b/activemq-pool/src/test/java/org/apache/activemq/pool/PooledConnectionFactoryWithTemporaryDestinationsTest.java index 9dacb90365..bd57ba1778 100644 --- a/activemq-pool/src/test/java/org/apache/activemq/pool/PooledConnectionFactoryWithTemporaryDestinationsTest.java +++ b/activemq-pool/src/test/java/org/apache/activemq/pool/PooledConnectionFactoryWithTemporaryDestinationsTest.java @@ -53,6 +53,36 @@ public class PooledConnectionFactoryWithTemporaryDestinationsTest extends TestSu broker.stop(); } + public void testTemporaryQueueWithMultipleConnectionUsers() throws Exception { + Connection pooledConnection = null; + Connection pooledConnection2 = null; + Session session = null; + Session session2 = null; + Queue tempQueue = null; + Queue normalQueue = null; + + pooledConnection = pooledFactory.createConnection(); + session = pooledConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + tempQueue = session.createTemporaryQueue(); + LOG.info("Created queue named: " + tempQueue.getQueueName()); + + assertEquals(1, countBrokerTemporaryQueues()); + + pooledConnection2 = pooledFactory.createConnection(); + session2 = pooledConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE); + normalQueue = session2.createQueue("queue:FOO.TEST"); + LOG.info("Created queue named: " + normalQueue.getQueueName()); + + // didn't create a temp queue on pooledConnection2 so we should still have a temp queue + pooledConnection2.close(); + assertEquals(1, countBrokerTemporaryQueues()); + + // after closing pooledConnection, where we created the temp queue, there should + // be no temp queues left + pooledConnection.close(); + assertEquals(0, countBrokerTemporaryQueues()); + } + public void testTemporaryQueueLeakAfterConnectionClose() throws Exception { Connection pooledConnection = null; Session session = null;