You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jm...@apache.org on 2002/09/06 01:38:50 UTC
cvs commit: jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool Jdbc2PoolDataSource.java
jmcnally 2002/09/05 16:38:49
Modified: dbcp build.xml
dbcp/src/java/org/apache/commons/dbcp/jdbc2pool
Jdbc2PoolDataSource.java
Log:
1. added jdbc2pool back to build
2. Added ability to close the pools associated the datasource. Original
code is by Randy Speh <rw...@yahoo.com>. I refactored a bit.
3. Added some instrumentation methods to be able to see active and idle
connections. Code by James Taylor <jt...@4lane.com>
Revision Changes Path
1.15 +1 -3 jakarta-commons/dbcp/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/dbcp/build.xml,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- build.xml 13 Aug 2002 20:41:10 -0000 1.14
+++ build.xml 5 Sep 2002 23:38:49 -0000 1.15
@@ -19,7 +19,6 @@
<patternset id="patternset-javadocable-sources">
<include name="**/*"/>
<exclude name="**/Test*.java"/>
- <exclude name="**/jdbc2pool/*.java"/>
</patternset>
<!-- ######################################################### -->
@@ -197,7 +196,6 @@
<include name="**/*.xml"/>
<include name="**/*.properties"/>
<include name="**/package.html"/>
- <exclude name="**/jdbc2pool/*.java"/>
</fileset>
</copy>
</target>
1.2 +122 -1 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java
Index: Jdbc2PoolDataSource.java
===================================================================
RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Jdbc2PoolDataSource.java 5 Aug 2002 06:42:01 -0000 1.1
+++ Jdbc2PoolDataSource.java 5 Sep 2002 23:38:49 -0000 1.2
@@ -217,6 +217,70 @@
}
}
+ /**
+ * Close all pools associated with this class.
+ */
+ public static void closeAll()
+ {
+ //Get iterator to loop over all instances of this datasource.
+ Iterator instanceIterator = dsInstanceMap.entrySet().iterator();
+
+ while (instanceIterator.hasNext())
+ {
+ Map.Entry nextInstance = (Map.Entry) instanceIterator.next();
+ Map nextPoolMap = (Map) nextInstance.getValue();
+ close(nextPoolMap);
+ }
+ dsInstanceMap.clear();
+ }
+
+ /**
+ * Close all pools in the given Map.
+ */
+ private static void close(Map poolMap)
+ {
+ //Get iterator to loop over all pools.
+ Iterator poolIter = poolMap.entrySet().iterator();
+
+ while (poolIter.hasNext())
+ {
+ Map.Entry nextPoolEntry = (Map.Entry) poolIter.next();
+
+ if (nextPoolEntry.getValue() instanceof ObjectPool)
+ {
+ ObjectPool nextPool = (ObjectPool) nextPoolEntry.getValue();
+ try
+ {
+ nextPool.close();
+ }
+ catch (Exception closePoolException)
+ {
+ //ignore and try to close others.
+ }
+ }
+ else
+ {
+ KeyedObjectPool nextPool =
+ (KeyedObjectPool) nextPoolEntry.getValue();
+ try {
+ nextPool.close();
+ }
+ catch (Exception closePoolException)
+ {
+ //ignore and try to close others.
+ }
+ }
+ }
+ }
+
+ /**
+ * Close pool(s) being maintained by this datasource.
+ */
+ public void close()
+ {
+ close((Map)dsInstanceMap.get(instanceKey));
+ }
+
// -------------------------------------------------------------------
// Properties
@@ -864,6 +928,63 @@
if (!testPositionSet)
{
setTestOnBorrow(true);
+ }
+ }
+
+ // ----------------------------------------------------------------------
+ // Instrumentation Methods
+
+ /**
+ * Get the number of active connections in the default pool.
+ */
+ public int getNumActive()
+ {
+ return getNumActive( null, null );
+ }
+
+ /**
+ * Get the number of active connections in the pool for a given user.
+ */
+ public int getNumActive( String username, String password )
+ {
+ PoolKey key = getPoolKey( username );
+
+ Object pool = ( ( Map ) dsInstanceMap.get( instanceKey ) ).get( key );
+
+ if ( pool instanceof ObjectPool )
+ {
+ return ( ( ObjectPool ) pool ).getNumActive();
+ }
+ else
+ {
+ return ( ( KeyedObjectPool ) pool ).getNumActive();
+ }
+ }
+
+ /**
+ * Get the number of idle connections in the default pool.
+ */
+ public int getNumIdle()
+ {
+ return getNumIdle( null, null );
+ }
+
+ /**
+ * Get the number of idle connections in the pool for a given user.
+ */
+ public int getNumIdle( String username, String password )
+ {
+ PoolKey key = getPoolKey( username );
+
+ Object pool = ( ( Map ) dsInstanceMap.get( instanceKey ) ).get( key );
+
+ if ( pool instanceof ObjectPool )
+ {
+ return ( ( ObjectPool ) pool ).getNumIdle();
+ }
+ else
+ {
+ return ( ( KeyedObjectPool ) pool ).getNumIdle();
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>