Return-Path: X-Original-To: apmail-incubator-connectors-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-connectors-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A58719970 for ; Thu, 10 May 2012 10:39:32 +0000 (UTC) Received: (qmail 99137 invoked by uid 500); 10 May 2012 10:39:32 -0000 Delivered-To: apmail-incubator-connectors-commits-archive@incubator.apache.org Received: (qmail 99030 invoked by uid 500); 10 May 2012 10:39:30 -0000 Mailing-List: contact connectors-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: connectors-dev@incubator.apache.org Delivered-To: mailing list connectors-commits@incubator.apache.org Received: (qmail 99008 invoked by uid 99); 10 May 2012 10:39:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 May 2012 10:39:29 +0000 X-ASF-Spam-Status: No, hits=-1999.6 required=5.0 tests=ALL_TRUSTED,FILL_THIS_FORM_FRAUD_PHISH,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 May 2012 10:39:27 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 313EA23888CD; Thu, 10 May 2012 10:39:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1336587 - in /incubator/lcf/branches/CONNECTORS-96: ./ framework/ framework/core/src/main/java/org/apache/manifoldcf/core/database/ Date: Thu, 10 May 2012 10:39:06 -0000 To: connectors-commits@incubator.apache.org From: kwright@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120510103907.313EA23888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kwright Date: Thu May 10 10:39:06 2012 New Revision: 1336587 URL: http://svn.apache.org/viewvc?rev=1336587&view=rev Log: Use the new pool stuff rather than bitstream everywhere. Modified: incubator/lcf/branches/CONNECTORS-96/build.xml incubator/lcf/branches/CONNECTORS-96/framework/build.xml incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java Modified: incubator/lcf/branches/CONNECTORS-96/build.xml URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-96/build.xml?rev=1336587&r1=1336586&r2=1336587&view=diff ============================================================================== --- incubator/lcf/branches/CONNECTORS-96/build.xml (original) +++ incubator/lcf/branches/CONNECTORS-96/build.xml Thu May 10 10:39:06 2012 @@ -3134,14 +3134,6 @@ Use Apache Forrest version forrest-0.9-d - - - - - - - - @@ -3394,7 +3386,7 @@ Use Apache Forrest version forrest-0.9-d - + Modified: incubator/lcf/branches/CONNECTORS-96/framework/build.xml URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-96/framework/build.xml?rev=1336587&r1=1336586&r2=1336587&view=diff ============================================================================== --- incubator/lcf/branches/CONNECTORS-96/framework/build.xml (original) +++ incubator/lcf/branches/CONNECTORS-96/framework/build.xml Thu May 10 10:39:06 2012 @@ -45,7 +45,6 @@ - @@ -254,7 +253,6 @@ - @@ -290,7 +288,6 @@ - @@ -331,7 +328,6 @@ - @@ -368,7 +364,6 @@ - @@ -411,7 +406,6 @@ - @@ -456,7 +450,6 @@ - @@ -559,7 +552,6 @@ - @@ -598,7 +590,6 @@ - @@ -750,7 +741,6 @@ - @@ -821,8 +811,7 @@ - - + @@ -877,7 +866,6 @@ - @@ -953,8 +941,7 @@ - - + Modified: incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java?rev=1336587&r1=1336586&r2=1336587&view=diff ============================================================================== --- incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java (original) +++ incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/database/ConnectionFactory.java Thu May 10 10:39:06 2012 @@ -19,6 +19,7 @@ package org.apache.manifoldcf.core.database; import org.apache.manifoldcf.core.interfaces.*; +import org.apache.manifoldcf.core.jdbcpool.*; import org.apache.manifoldcf.core.system.Logging; import org.apache.manifoldcf.core.system.ManifoldCF; @@ -27,8 +28,6 @@ import java.sql.*; import javax.naming.*; import javax.sql.*; -import com.bitmechanic.sql.*; - /** This class creates a connection, and may at our discretion manage * a connection pool someday. */ @@ -48,19 +47,29 @@ public class ConnectionFactory { } - public static Connection getConnection(String jdbcUrl, String jdbcDriver, String database, String userName, String password) + public static WrappedConnection getConnection(String jdbcUrl, String jdbcDriver, String database, String userName, String password) throws ManifoldCFException { + // Make sure database driver is registered + try + { + Class.forName(jdbcDriver); + } + catch (Exception e) + { + throw new ManifoldCFException("Unable to load database driver: "+e.getMessage(),e,ManifoldCFException.SETUP_ERROR); + } - ConnectionPoolManager _pool = poolManager.ensurePoolExists(jdbcDriver); + ConnectionPoolManager cpm = poolManager.createPoolManager(); + try { // Hope for a connection now - Connection rval; + WrappedConnection rval; ConnectionPool cp = null; try { - cp = _pool.getPool(database); + cp = cpm.getPool(database); } catch (Exception e) { @@ -71,61 +80,37 @@ public class ConnectionFactory int maxDBConnections = defaultMaxDBConnections; if (handleMax != null && handleMax.length() > 0) maxDBConnections = Integer.parseInt(handleMax); - String timeoutValueString = ManifoldCF.getProperty(ManifoldCF.databaseHandleTimeoutProperty); - int timeoutValue = defaultTimeoutValue; - if (timeoutValueString != null && timeoutValueString.length() > 0) - timeoutValue = Integer.parseInt(timeoutValueString); + //String timeoutValueString = ManifoldCF.getProperty(ManifoldCF.databaseHandleTimeoutProperty); + //int timeoutValue = defaultTimeoutValue; + //if (timeoutValueString != null && timeoutValueString.length() > 0) + // timeoutValue = Integer.parseInt(timeoutValueString); // Logging.db.debug("adding pool alias [" + database + "]"); // I had to up the timeout from one hour to 3 due to the webconnector keeping some connections open a very long time... //System.out.println("jdbcUrl = '"+jdbcUrl+"', userName='"+userName+"', password='"+password+"'"); - _pool.addAlias(database, jdbcDriver, jdbcUrl, + cpm.addAlias(database, jdbcDriver, jdbcUrl, userName, password, - maxDBConnections, - 300, // Idle timeout: idle time before closing connection: 5 minutes - timeoutValue, // Checkout timeout: Time a thread can have connection checked out: 24 hours - 30, // Number of times you can check out a connection before it gets closed: 30 - false); - cp = _pool.getPool(database); - } - rval = getConnectionWithRetries(ConnectionPoolManager.URL_PREFIX + database, null, null); - //rval = getConnectionWithRetries(ConnectionPoolManager.URL_PREFIX + database, userName, password); - - // Enter it in the pool so we can figure out whether it closed - // synchronized (checkedOutConnections) - // { - // checkedOutConnections.put(rval.toString(),new ConnectionTracker(rval)); - // } - // - // checkConnections(System.currentTimeMillis()); - + maxDBConnections, 300000L); + cp = cpm.getPool(database); + } + rval = new WrappedConnection(cp, getConnectionWithRetries(database, null, null)); return rval; } catch (Exception e) { - throw new ManifoldCFException("Error getting connection",e,ManifoldCFException.DATABASE_ERROR); + throw new ManifoldCFException("Error getting connection: "+e.getMessage(),e,ManifoldCFException.DATABASE_ERROR); } } - public static void releaseConnection(Connection c) + public static void releaseConnection(WrappedConnection c) throws ManifoldCFException { - try - { - c.close(); - // synchronized (checkedOutConnections) - // { - // checkedOutConnections.remove(c.toString()); - // } - } - catch (Exception e) - { - throw new ManifoldCFException("Error releasing connection",e,ManifoldCFException.DATABASE_ERROR); - } + c.release(); } public static void releaseAll() { + //??? if (poolManager != null) poolManager.releaseAll(); } @@ -196,34 +181,14 @@ public class ConnectionFactory { } - public ConnectionPoolManager ensurePoolExists(String jdbcDriver) - throws ManifoldCFException + public ConnectionPoolManager createPoolManager() { synchronized (poolExistenceLock) { if (_pool != null) return _pool; - try - { - Class.forName(jdbcDriver); - } - catch (Exception e) - { - throw new ManifoldCFException("Unable to load database driver: "+e.getMessage(),e,ManifoldCFException.SETUP_ERROR); - } - try - { - String handleMax = ManifoldCF.getProperty(ManifoldCF.databaseHandleMaxcountProperty); - int maxDBConnections = defaultMaxDBConnections; - if (handleMax != null && handleMax.length() > 0) - maxDBConnections = Integer.parseInt(handleMax); - _pool = new ConnectionPoolManager(maxDBConnections); - return _pool; - } - catch (Exception e) - { - throw new ManifoldCFException("Unable to initialize database handle pool: "+e.getMessage(),e,ManifoldCFException.SETUP_ERROR); - } + _pool = new ConnectionPoolManager(100); + return _pool; } } @@ -235,6 +200,14 @@ public class ConnectionFactory return; } + // Cleanup strategy: Some connections are still in use because they are being + // used by non-worker threads that have been interrupted but haven't yet died. + // Cleaning these up is a challenge. For now I won't address this. + + _pool.shutdown(); + } + + /* // Cleanup strategy is to close everything that can easily be closed, but leave around connections that are so busy that they will not close within a certain amount of // time. To do that, we spin up a thread for each connection, which attempts to close that connection, and then wait until either 15 seconds passes, or all the threads // are finished. @@ -244,7 +217,7 @@ public class ConnectionFactory // This is not ideal, but is a compromise designed to permit speedy and relatively clean shutdown even under // difficult conditions. - + Enumeration enumeration = _pool.getPools(); ArrayList connectionShutdownThreads = new ArrayList(); while (enumeration.hasMoreElements()) @@ -305,7 +278,7 @@ public class ConnectionFactory // Some threads may still be running - but that can't be helped. } - + */ // Protected methods and classes @@ -315,6 +288,7 @@ public class ConnectionFactory * will be blocked from proceeding under Tomcat 5.5. Between the two, however, * there's hope that the right things will take place. */ + /* protected void finalize() throws Throwable { @@ -328,8 +302,10 @@ public class ConnectionFactory super.finalize(); } } + */ } + /* protected static class ConnectionCloseThread extends Thread { protected com.bitmechanic.sql.PooledConnection connection; @@ -361,7 +337,8 @@ public class ConnectionFactory } } - + */ + protected static class ConnectionTracker { protected Connection theConnection; Modified: incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java?rev=1336587&r1=1336586&r2=1336587&view=diff ============================================================================== --- incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java (original) +++ incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java Thu May 10 10:39:06 2012 @@ -19,6 +19,7 @@ package org.apache.manifoldcf.core.database; import org.apache.manifoldcf.core.interfaces.*; +import org.apache.manifoldcf.core.jdbcpool.*; import org.apache.manifoldcf.core.system.Logging; import org.apache.manifoldcf.core.system.ManifoldCF; @@ -45,7 +46,7 @@ public abstract class Database protected String userName; protected String password; protected TransactionHandle th = null; - protected Connection connection = null; + protected WrappedConnection connection = null; protected boolean doRollback = false; protected boolean commitDone = false; protected int delayedTransactionDepth = 0; @@ -250,7 +251,7 @@ public abstract class Database try { // Initialize the connection (for HSQLDB) - initializeConnection(connection); + initializeConnection(connection.getConnection()); // Start a transaction startATransaction(); } @@ -705,7 +706,7 @@ public abstract class Database { try { - return executeViaThread(connection,query,params,bResults,maxResults,spec,returnLimit); + return executeViaThread(connection.getConnection(),query,params,bResults,maxResults,spec,returnLimit); } catch (ManifoldCFException e) { @@ -718,12 +719,12 @@ public abstract class Database else { // Grab a connection - Connection tempConnection = ConnectionFactory.getConnection(jdbcUrl,jdbcDriverClass,databaseName,userName,password); + WrappedConnection tempConnection = ConnectionFactory.getConnection(jdbcUrl,jdbcDriverClass,databaseName,userName,password); try { // Initialize the connection (for HSQLDB) - initializeConnection(tempConnection); - return executeViaThread(tempConnection,query,params,bResults,maxResults,spec,returnLimit); + initializeConnection(tempConnection.getConnection()); + return executeViaThread(tempConnection.getConnection(),query,params,bResults,maxResults,spec,returnLimit); } catch (ManifoldCFException e) {