get rid of closeListener, it turns into spaghetti code
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 11 Dec 2008 03:40:13 +0000 (03:40 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 11 Dec 2008 03:40:13 +0000 (03:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@725564 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java

index 00c9a57..c4eaa99 100644 (file)
@@ -58,18 +58,12 @@ import javax.management.ObjectName;
  */
 
 public class ConnectionPool {
-    public static interface CloseListener {
-        void poolClosed(ConnectionPool pool);
-    }
-
     //logger
     protected static Log log = LogFactory.getLog(ConnectionPool.class);
 
     //===============================================================================
     //         INSTANCE/QUICK ACCESS VARIABLE
     //===============================================================================
-    protected ConcurrentLinkedQueue<CloseListener> listeners = new ConcurrentLinkedQueue<CloseListener>();
-    
     /**
      * All the information about the connection pool
      */
@@ -259,14 +253,6 @@ public class ConnectionPool {
         close(true);
     }
 
-    public void addCloseListener(CloseListener listener) {
-        listeners.add(listener);
-    }
-    
-    public void removeCloseListener(CloseListener listener) {
-        listeners.remove(listener);
-    }
-    
     /**
      * Closes the pool and all disconnects all idle connections
      * Active connections will be closed upon the {@link java.sql.Connection#close close} method is called
@@ -306,10 +292,6 @@ public class ConnectionPool {
         size.set(0);
         if (this.getPoolProperties().isJmxEnabled()) stopJmx();
         
-        while (listeners.size()>0) {
-            CloseListener listener = listeners.poll();
-            if (listener!=null) listener.poolClosed(this);
-        }
     } //closePool
 
 
index 57a0d1b..dbf4992 100644 (file)
@@ -54,7 +54,7 @@ public class PoolProperties {
     protected int removeAbandonedTimeout = 60;
     protected boolean logAbandoned = false;
     protected int loginTimeout = 10000;
-    protected String name = "Tomcat Connection Pool["+(poolCounter.addAndGet(1))+"]";
+    protected String name = "Tomcat Connection Pool["+(poolCounter.addAndGet(1))+","+System.identityHashCode(PoolProperties.class)+"]";
     protected String password;
     protected String username;
     protected long validationInterval = 30000;
index 7288f0d..d79e7de 100644 (file)
@@ -117,7 +117,7 @@ public class PooledConnection {
 
 
 //============================================================================
-//             com.filip.util.IPoolObject methods
+//             
 //============================================================================
 
     public long getAbandonTimeout() {
index e3e5045..15357b7 100644 (file)
@@ -42,13 +42,14 @@ import org.apache.tomcat.jdbc.pool.PooledConnection;
  * @author Filip Hanik
  * @version 1.0
  */
-public class SlowQueryReport extends AbstractCreateStatementInterceptor implements ConnectionPool.CloseListener {
+public class SlowQueryReport extends AbstractCreateStatementInterceptor  {
     //logger
     protected static Log log = LogFactory.getLog(SlowQueryReport.class);
     /**
      * the constructors that are used to create statement proxies 
      */
-    protected static final Constructor[] constructors = new Constructor[AbstractCreateStatementInterceptor.statements.length];
+    protected static final Constructor[] constructors = 
+        new Constructor[AbstractCreateStatementInterceptor.statements.length];
     /**
      * we will be keeping track of query stats on a per pool basis, do we want this, or global?
      */
@@ -112,7 +113,13 @@ public class SlowQueryReport extends AbstractCreateStatementInterceptor implemen
      */
     @Override
     public void closeInvoked() {
-        queries = null;
+        try {
+            queries = null;
+            finalize();
+            pool = null;
+        }catch (Exception x) {
+            log.debug(x);
+        }
         
     }
     
@@ -184,22 +191,13 @@ public class SlowQueryReport extends AbstractCreateStatementInterceptor implemen
 
             };
             perPoolStats.put(parent, queries);
-            //add ourselves to the pool listener, so we can cleanup
-            parent.addCloseListener(this);
         }
         this.pool = parent;
     }
     
     public void finalize() {
-        if (pool!=null) pool.removeCloseListener(this);
     }
 
-    
-    public void poolClosed(ConnectionPool pool) {
-        //clean up after ourselves.
-        perPoolStats.remove(pool);
-    }
-    
     public CompositeData[] getSlowQueriesCD() {
         return null;
     }