git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1158694 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2011-08-17 13:29:35 +00:00
parent 5daeb53cc4
commit 320d87cfce
3 changed files with 36 additions and 7 deletions

View File

@ -144,6 +144,12 @@ public class ConnectionPool {
lastUsed = System.currentTimeMillis(); lastUsed = System.currentTimeMillis();
if (referenceCount == 0) { if (referenceCount == 0) {
expiredCheck(); expiredCheck();
// only clean up temp destinations when all users
// of this connection have called close
if (getConnection() != null) {
getConnection().cleanUpTempDestinations();
}
} }
} }

View File

@ -16,9 +16,6 @@
*/ */
package org.apache.activemq.pool; package org.apache.activemq.pool;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.ConnectionConsumer; import javax.jms.ConnectionConsumer;
import javax.jms.ConnectionMetaData; import javax.jms.ConnectionMetaData;
@ -39,7 +36,6 @@ import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.AlreadyClosedException; import org.apache.activemq.AlreadyClosedException;
import org.apache.activemq.EnhancedConnection; import org.apache.activemq.EnhancedConnection;
import org.apache.activemq.advisory.DestinationSource; import org.apache.activemq.advisory.DestinationSource;
import org.apache.activemq.command.ActiveMQTempDestination;
/** /**
* Represents a proxy {@link Connection} which is-a {@link TopicConnection} and * 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 { public void close() throws JMSException {
if (this.pool != null) { if (this.pool != null) {
this.pool.decrementReferenceCount(); this.pool.decrementReferenceCount();
if (this.pool.getConnection() != null) {
this.pool.getConnection().cleanUpTempDestinations();
}
this.pool = null; this.pool = null;
} }
} }

View File

@ -53,6 +53,36 @@ public class PooledConnectionFactoryWithTemporaryDestinationsTest extends TestSu
broker.stop(); 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 { public void testTemporaryQueueLeakAfterConnectionClose() throws Exception {
Connection pooledConnection = null; Connection pooledConnection = null;
Session session = null; Session session = null;