commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1564431 - in /commons/proper/dbcp/trunk/src: changes/ main/java/org/apache/commons/dbcp2/ main/java/org/apache/commons/dbcp2/datasources/
Date Tue, 04 Feb 2014 19:23:22 GMT
Author: markt
Date: Tue Feb  4 19:23:22 2014
New Revision: 1564431

URL: http://svn.apache.org/r1564431
Log:
Fix DBCP-368
Expose the new Pool 2 property evictionPolicyClassName to enable more sophisticated eviction
strategies to be used.

Modified:
    commons/proper/dbcp/trunk/src/changes/changes.xml
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java

Modified: commons/proper/dbcp/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/changes/changes.xml?rev=1564431&r1=1564430&r2=1564431&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbcp/trunk/src/changes/changes.xml Tue Feb  4 19:23:22 2014
@@ -122,6 +122,10 @@ The <action> type attribute can be add,u
         part of the internal API) to allow classes extending this implementation
         to access the innermost delegate when required.
       </action>
+      <action dev="markt" issue="DBCP-368" type="add">
+        Expose the new Pool 2 property evictionPolicyClassName to enable more
+        sophisticated eviction strategies to be used.
+      </action>
     </release>
     <release version="1.5.1" date="TBD" description="TBD">
       <action dev="markt" issue="DBCP-400" type="fix">

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java?rev=1564431&r1=1564430&r2=1564431&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
Tue Feb  4 19:23:22 2014
@@ -47,6 +47,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.commons.pool2.PooledObject;
 import org.apache.commons.pool2.UsageTracking;
 import org.apache.commons.pool2.impl.AbandonedConfig;
+import org.apache.commons.pool2.impl.BaseObjectPoolConfig;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
 import org.apache.commons.pool2.impl.GenericObjectPool;
 import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
@@ -856,6 +857,34 @@ public class BasicDataSource
         return softMinEvictableIdleTimeMillis;
     }
 
+    private String evictionPolicyClassName =
+            BaseObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME;
+
+    /**
+     * Gets the EvictionPolicy implementation in use with this connection pool.
+     *
+     * @since 2.0
+     */
+    public synchronized String getEvictionPolicyClassName() {
+        return evictionPolicyClassName;
+    }
+
+    /**
+     * Sets the EvictionPolicy implementation to use with this connection pool.
+     *
+     * @param evictionPolicyClassName   The fully qualified class name of the
+     *                                  EvictionPolicy implementation
+     *
+     * @since 2.0
+     */
+    public synchronized void setEvictionPolicyClassName(
+            String evictionPolicyClassName) {
+        if (connectionPool != null) {
+            connectionPool.setEvictionPolicyClassName(evictionPolicyClassName);
+        }
+        this.evictionPolicyClassName = evictionPolicyClassName;
+    }
+
     /**
      * The indication of whether objects will be validated by the idle object
      * evictor (if any).  If an object fails to validate, it will be dropped

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java?rev=1564431&r1=1564430&r2=1564431&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/BasicDataSourceFactory.java
Tue Feb  4 19:23:22 2014
@@ -69,6 +69,7 @@ public class BasicDataSourceFactory impl
     private final static String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun";
     private final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
     private final static String PROP_SOFTMINEVICTABLEIDLETIMEMILLIS = "softMinEvictableIdleTimeMillis";
+    private final static String PROP_EVICTIONPOLICYCLASSNAME = "evictionPolicyClassName";
     private final static String PROP_TESTWHILEIDLE = "testWhileIdle";
     private final static String PROP_PASSWORD = "password";
     private final static String PROP_URL = "url";
@@ -112,6 +113,7 @@ public class BasicDataSourceFactory impl
         PROP_NUMTESTSPEREVICTIONRUN,
         PROP_MINEVICTABLEIDLETIMEMILLIS,
         PROP_SOFTMINEVICTABLEIDLETIMEMILLIS,
+        PROP_EVICTIONPOLICYCLASSNAME,
         PROP_TESTWHILEIDLE,
         PROP_PASSWORD,
         PROP_URL,
@@ -301,6 +303,11 @@ public class BasicDataSourceFactory impl
             dataSource.setSoftMinEvictableIdleTimeMillis(Long.parseLong(value));
         }
 
+        value = properties.getProperty(PROP_EVICTIONPOLICYCLASSNAME);
+        if (value != null) {
+            dataSource.setEvictionPolicyClassName(value);
+        }
+
         value = properties.getProperty(PROP_TESTWHILEIDLE);
         if (value != null) {
             dataSource.setTestWhileIdle(Boolean.valueOf(value).booleanValue());

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java?rev=1564431&r1=1564430&r2=1564431&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
Tue Feb  4 19:23:22 2014
@@ -126,19 +126,21 @@ public abstract class InstanceKeyDataSou
 
     // Pool properties
     private boolean _testOnBorrow =
-        GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW;
+            GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW;
     private boolean _testOnReturn =
-        GenericObjectPoolConfig.DEFAULT_TEST_ON_RETURN;
+            GenericObjectPoolConfig.DEFAULT_TEST_ON_RETURN;
     private int _timeBetweenEvictionRunsMillis = (int)
-        Math.min(Integer.MAX_VALUE,
-                 GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
+            Math.min(Integer.MAX_VALUE,
+                     GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
     private int _numTestsPerEvictionRun =
-        GenericObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+            GenericObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
     private int _minEvictableIdleTimeMillis = (int)
-    Math.min(Integer.MAX_VALUE,
-            GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
+            Math.min(Integer.MAX_VALUE,
+                    GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
+    private String evictionPolicyClassName =
+            GenericObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME;
     private boolean _testWhileIdle =
-        GenericObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE;
+            GenericObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE;
     private String validationQuery = null;
     private boolean rollbackAfterValidation = false;
     private long maxConnLifetimeMillis = -1;
@@ -614,6 +616,29 @@ public abstract class InstanceKeyDataSou
     }
 
     /**
+     * Gets the EvictionPolicy implementation in use with this connection pool.
+     *
+     * @since 2.0
+     */
+    public synchronized String getEvictionPolicyClassName() {
+        return evictionPolicyClassName;
+    }
+
+    /**
+     * Sets the EvictionPolicy implementation to use with this connection pool.
+     *
+     * @param evictionPolicyClassName   The fully qualified class name of the
+     *                                  EvictionPolicy implementation
+     *
+     * @since 2.0
+     */
+    public synchronized void setEvictionPolicyClassName(
+            String evictionPolicyClassName) {
+        assertInitializationAllowed();
+        this.evictionPolicyClassName = evictionPolicyClassName;
+    }
+
+    /**
      * @see #getTestWhileIdle
      */
     public final boolean isTestWhileIdle() {

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java?rev=1564431&r1=1564430&r2=1564431&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
Tue Feb  4 19:23:22 2014
@@ -608,6 +608,7 @@ public class PerUserPoolDataSource exten
             getTimeBetweenEvictionRunsMillis());
         pool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
         pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
+        pool.setEvictionPolicyClassName(getEvictionPolicyClassName());
         pool.setTestWhileIdle(getTestWhileIdle());
         pool.setSwallowedExceptionListener(new SwallowedExceptionLogger(log));
 

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java?rev=1564431&r1=1564430&r2=1564431&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java
Tue Feb  4 19:23:22 2014
@@ -235,6 +235,7 @@ public class SharedPoolDataSource
             getTimeBetweenEvictionRunsMillis());
         config.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
         config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
+        config.setEvictionPolicyClassName(getEvictionPolicyClassName());
         config.setTestWhileIdle(getTestWhileIdle());
         KeyedObjectPool<UserPassKey,PooledConnectionAndInfo> tmpPool =
                 new GenericKeyedObjectPool<>(factory, config);



Mime
View raw message