activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r669510 - /activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java
Date Thu, 19 Jun 2008 15:35:18 GMT
Author: rajdavies
Date: Thu Jun 19 08:35:18 2008
New Revision: 669510

URL: http://svn.apache.org/viewvc?rev=669510&view=rev
Log:
Apply fix for https://issues.apache.org/activemq/browse/AMQ-1810

Modified:
    activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java

Modified: activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java?rev=669510&r1=669509&r2=669510&view=diff
==============================================================================
--- activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java
(original)
+++ activemq/trunk/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactory.java
Thu Jun 19 08:35:18 2008
@@ -20,6 +20,7 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
@@ -30,6 +31,8 @@
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.Service;
 import org.apache.activemq.util.IOExceptionSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.pool.ObjectPoolFactory;
 import org.apache.commons.pool.impl.GenericObjectPoolFactory;
 
@@ -46,12 +49,14 @@
  * @version $Revision: 1.1 $
  */
 public class PooledConnectionFactory implements ConnectionFactory, Service {
+    private static final transient Log LOG = LogFactory.getLog(PooledConnectionFactory.class);
     private ConnectionFactory connectionFactory;
     private Map<ConnectionKey, LinkedList<ConnectionPool>> cache = new HashMap<ConnectionKey,
LinkedList<ConnectionPool>>();
     private ObjectPoolFactory poolFactory;
     private int maximumActive = 500;
     private int maxConnections = 1;
     private int idleTimeout = 30 * 1000;
+    private AtomicBoolean stopped = new AtomicBoolean(false);
 
     public PooledConnectionFactory() {
         this(new ActiveMQConnectionFactory());
@@ -78,6 +83,11 @@
     }
 
     public synchronized Connection createConnection(String userName, String password) throws
JMSException {
+        if (stopped.get()) {
+            LOG.debug("PooledConnectionFactory is stopped, skip create new connection.");
+            return null;
+        }
+        
         ConnectionKey key = new ConnectionKey(userName, password);
         LinkedList<ConnectionPool> pools = cache.get(key);
 
@@ -124,18 +134,26 @@
      */
     public void start() {
         try {
+            stopped.set(false);
             createConnection();
         } catch (JMSException e) {
+            LOG.warn("Create pooled connection during start failed.", e);
             IOExceptionSupport.create(e);
         }
     }
 
-    public void stop() throws Exception {
+    public void stop() {
+        LOG.debug("Stop the PooledConnectionFactory, number of connections in cache: "+cache.size());
+        stopped.set(true);
         for (Iterator<LinkedList<ConnectionPool>> iter = cache.values().iterator();
iter.hasNext();) {
             LinkedList list = iter.next();
             for (Iterator i = list.iterator(); i.hasNext();) {
                 ConnectionPool connection = (ConnectionPool) i.next();
-                connection.close();
+                try {
+                    connection.close();
+                }catch(Exception e) {
+                    LOG.warn("Close connection failed",e);
+                }
             }
         }
         cache.clear();



Mime
View raw message