You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2011/06/13 19:51:04 UTC

svn commit: r1135200 - in /commons/proper/pool/trunk/src: java/org/apache/commons/pool2/impl/GenericObjectPool.java test/org/apache/commons/pool2/impl/TestGenericObjectPool.java

Author: markt
Date: Mon Jun 13 17:51:03 2011
New Revision: 1135200

URL: http://svn.apache.org/viewvc?rev=1135200&view=rev
Log:
Remove old GOP.Config object and old default definitions

Modified:
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java?rev=1135200&r1=1135199&r2=1135200&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java Mon Jun 13 17:51:03 2011
@@ -166,125 +166,6 @@ import org.apache.commons.pool2.Poolable
  */
 public class GenericObjectPool<T> extends BaseObjectPool<T> {
 
-    // --- public constants -------------------------------------------
-
-    /**
-     * The default cap on the number of "sleeping" instances in the pool.
-     * 
-     * @see #getMaxIdle
-     * @see #setMaxIdle
-     */
-    public static final int DEFAULT_MAX_IDLE = 8;
-
-    /**
-     * The default minimum number of "sleeping" instances in the pool before
-     * before the evictor thread (if active) spawns new objects.
-     * 
-     * @see #getMinIdle
-     * @see #setMinIdle
-     */
-    public static final int DEFAULT_MIN_IDLE = 0;
-
-    /**
-     * The default cap on the total number of active instances from the pool.
-     * 
-     * @see #getMaxActive
-     */
-    public static final int DEFAULT_MAX_ACTIVE = 8;
-
-    /**
-     * The default "when exhausted action" for the pool.
-     * 
-     * @see #setWhenExhaustedAction
-     */
-    public static final WhenExhaustedAction DEFAULT_WHEN_EXHAUSTED_ACTION =
-        WhenExhaustedAction.BLOCK;
-
-    /**
-     * The default LIFO status. True means that borrowObject returns the most
-     * recently used ("last in") idle object in the pool (if there are idle
-     * instances available). False means that the pool behaves as a FIFO queue -
-     * objects are taken from the idle object pool in the order that they are
-     * returned to the pool.
-     * 
-     * @see #setLifo
-     * @since 1.4
-     */
-    public static final boolean DEFAULT_LIFO = true;
-
-    /**
-     * The default maximum amount of time (in milliseconds) the
-     * {@link #borrowObject} method should block before throwing an exception
-     * when the pool is exhausted and the {@link #getWhenExhaustedAction
-     * "when exhausted" action} is {@link WhenExhaustedAction#BLOCK}.
-     * 
-     * @see #getMaxWait
-     * @see #setMaxWait
-     */
-    public static final long DEFAULT_MAX_WAIT = -1L;
-
-    /**
-     * The default "test on borrow" value.
-     * 
-     * @see #getTestOnBorrow
-     * @see #setTestOnBorrow
-     */
-    public static final boolean DEFAULT_TEST_ON_BORROW = false;
-
-    /**
-     * The default "test on return" value.
-     * 
-     * @see #getTestOnReturn
-     * @see #setTestOnReturn
-     */
-    public static final boolean DEFAULT_TEST_ON_RETURN = false;
-
-    /**
-     * The default "test while idle" value.
-     * 
-     * @see #getTestWhileIdle
-     * @see #setTestWhileIdle
-     * @see #getTimeBetweenEvictionRunsMillis
-     * @see #setTimeBetweenEvictionRunsMillis
-     */
-    public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
-
-    /**
-     * The default "time between eviction runs" value.
-     * 
-     * @see #getTimeBetweenEvictionRunsMillis
-     * @see #setTimeBetweenEvictionRunsMillis
-     */
-    public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
-
-    /**
-     * The default number of objects to examine per run in the idle object
-     * evictor.
-     * 
-     * @see #getNumTestsPerEvictionRun
-     * @see #setNumTestsPerEvictionRun
-     * @see #getTimeBetweenEvictionRunsMillis
-     * @see #setTimeBetweenEvictionRunsMillis
-     */
-    public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;
-
-    /**
-     * The default value for {@link #getMinEvictableIdleTimeMillis}.
-     * 
-     * @see #getMinEvictableIdleTimeMillis
-     * @see #setMinEvictableIdleTimeMillis
-     */
-    public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS =
-            1000L * 60L * 30L;
-
-    /**
-     * The default value for {@link #getSoftMinEvictableIdleTimeMillis}.
-     * 
-     * @see #getSoftMinEvictableIdleTimeMillis
-     * @see #setSoftMinEvictableIdleTimeMillis
-     */
-    public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;
-
     // --- constructors -----------------------------------------------
 
     /**
@@ -714,20 +595,22 @@ public class GenericObjectPool<T> extend
      *            configuration to use.
      * @see GenericObjectPool.Config
      */
-    public void setConfig(GenericObjectPool.Config conf) {
-        setMaxIdle(conf.maxIdle);
-        setMinIdle(conf.minIdle);
-        setMaxActive(conf.maxActive);
-        setMaxWait(conf.maxWait);
-        setWhenExhaustedAction(conf.whenExhaustedAction);
-        setTestOnBorrow(conf.testOnBorrow);
-        setTestOnReturn(conf.testOnReturn);
-        setTestWhileIdle(conf.testWhileIdle);
-        setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun);
-        setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis);
-        setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis);
-        setSoftMinEvictableIdleTimeMillis(conf.softMinEvictableIdleTimeMillis);
-        setLifo(conf.lifo);
+    public void setConfig(GenericObjectPoolConfig<T> conf) {
+        setMaxIdle(conf.getMaxIdle());
+        setMinIdle(conf.getMinIdle());
+        setMaxActive(conf.getMaxTotal());
+        setMaxWait(conf.getMaxWait());
+        setWhenExhaustedAction(conf.getWhenExhaustedAction());
+        setTestOnBorrow(conf.getTestOnBorrow());
+        setTestOnReturn(conf.getTestOnReturn());
+        setTestWhileIdle(conf.getTestWhileIdle());
+        setNumTestsPerEvictionRun(conf.getNumTestsPerEvictionRun());
+        setMinEvictableIdleTimeMillis(conf.getMinEvictableIdleTimeMillis());
+        setTimeBetweenEvictionRunsMillis(
+                conf.getTimeBetweenEvictionRunsMillis());
+        setSoftMinEvictableIdleTimeMillis(
+                conf.getSoftMinEvictableIdleTimeMillis());
+        setLifo(conf.getLifo());
     }
 
     // -- ObjectPool methods ------------------------------------------
@@ -1335,78 +1218,6 @@ public class GenericObjectPool<T> extend
         }
     }
 
-    /**
-     * A simple "struct" encapsulating the configuration information for a
-     * {@link GenericObjectPool}.
-     * 
-     * @see GenericObjectPool#GenericObjectPool(
-     *      org.apache.commons.pool2.PoolableObjectFactory,
-     *      org.apache.commons.pool2.impl.GenericObjectPool.Config)
-     * @see GenericObjectPool#setConfig
-     */
-    public static class Config {
-        // CHECKSTYLE: stop VisibilityModifier
-        /**
-         * @see GenericObjectPool#setMaxIdle
-         */
-        public int maxIdle = GenericObjectPool.DEFAULT_MAX_IDLE;
-        /**
-         * @see GenericObjectPool#setMinIdle
-         */
-        public int minIdle = GenericObjectPool.DEFAULT_MIN_IDLE;
-        /**
-         * @see GenericObjectPool#setMaxActive
-         */
-        public int maxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE;
-        /**
-         * @see GenericObjectPool#setMaxWait
-         */
-        public long maxWait = GenericObjectPool.DEFAULT_MAX_WAIT;
-        /**
-         * @see GenericObjectPool#setWhenExhaustedAction
-         */
-        public WhenExhaustedAction whenExhaustedAction =
-            GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
-        /**
-         * @see GenericObjectPool#setTestOnBorrow
-         */
-        public boolean testOnBorrow = GenericObjectPool.DEFAULT_TEST_ON_BORROW;
-        /**
-         * @see GenericObjectPool#setTestOnReturn
-         */
-        public boolean testOnReturn = GenericObjectPool.DEFAULT_TEST_ON_RETURN;
-        /**
-         * @see GenericObjectPool#setTestWhileIdle
-         */
-        public boolean testWhileIdle =
-            GenericObjectPool.DEFAULT_TEST_WHILE_IDLE;
-        /**
-         * @see GenericObjectPool#setTimeBetweenEvictionRunsMillis
-         */
-        public long timeBetweenEvictionRunsMillis =
-            GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
-        /**
-         * @see GenericObjectPool#setNumTestsPerEvictionRun
-         */
-        public int numTestsPerEvictionRun =
-            GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
-        /**
-         * @see GenericObjectPool#setMinEvictableIdleTimeMillis
-         */
-        public long minEvictableIdleTimeMillis =
-            GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
-        /**
-         * @see GenericObjectPool#setSoftMinEvictableIdleTimeMillis
-         */
-        public long softMinEvictableIdleTimeMillis =
-            GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
-        /**
-         * @see GenericObjectPool#setLifo
-         */
-        public boolean lifo = GenericObjectPool.DEFAULT_LIFO;
-        // CHECKSTYLE: resume VisibilityModifier
-    }
-
     // --- private attributes ---------------------------------------
 
     /**
@@ -1415,7 +1226,7 @@ public class GenericObjectPool<T> extend
      * @see #setMaxIdle
      * @see #getMaxIdle
      */
-    private volatile int _maxIdle = DEFAULT_MAX_IDLE;
+    private volatile int _maxIdle = GenericObjectPoolConfig.DEFAULT_MAX_IDLE;
 
     /**
      * The cap on the minimum number of idle instances in the pool.
@@ -1423,7 +1234,7 @@ public class GenericObjectPool<T> extend
      * @see #setMinIdle
      * @see #getMinIdle
      */
-    private volatile int _minIdle = DEFAULT_MIN_IDLE;
+    private volatile int _minIdle = GenericObjectPoolConfig.DEFAULT_MIN_IDLE;
 
     /**
      * The cap on the total number of active instances from the pool.
@@ -1431,7 +1242,8 @@ public class GenericObjectPool<T> extend
      * @see #setMaxActive
      * @see #getMaxActive
      */
-    private volatile int _maxActive = DEFAULT_MAX_ACTIVE;
+    private volatile int _maxActive =
+        GenericObjectPoolConfig.DEFAULT_MAX_TOTAL;
 
     /**
      * The maximum amount of time (in millis) the {@link #borrowObject} method
@@ -1446,7 +1258,7 @@ public class GenericObjectPool<T> extend
      * @see #setWhenExhaustedAction
      * @see #getWhenExhaustedAction
      */
-    private volatile long _maxWait = DEFAULT_MAX_WAIT;
+    private volatile long _maxWait = GenericObjectPoolConfig.DEFAULT_MAX_WAIT;
 
     /**
      * The action to take when the {@link #borrowObject} method is invoked when
@@ -1458,7 +1270,7 @@ public class GenericObjectPool<T> extend
      * @see #getWhenExhaustedAction
      */
     private volatile WhenExhaustedAction _whenExhaustedAction =
-        DEFAULT_WHEN_EXHAUSTED_ACTION;
+        GenericObjectPoolConfig.DEFAULT_WHEN_EXHAUSTED_ACTION;
 
     /**
      * When <tt>true</tt>, objects will be
@@ -1470,7 +1282,8 @@ public class GenericObjectPool<T> extend
      * @see #setTestOnBorrow
      * @see #getTestOnBorrow
      */
-    private volatile boolean _testOnBorrow = DEFAULT_TEST_ON_BORROW;
+    private volatile boolean _testOnBorrow =
+        GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW;
 
     /**
      * When <tt>true</tt>, objects will be
@@ -1480,7 +1293,8 @@ public class GenericObjectPool<T> extend
      * @see #getTestOnReturn
      * @see #setTestOnReturn
      */
-    private volatile boolean _testOnReturn = DEFAULT_TEST_ON_RETURN;
+    private volatile boolean _testOnReturn =
+        GenericObjectPoolConfig.DEFAULT_TEST_ON_RETURN;
 
     /**
      * When <tt>true</tt>, objects will be
@@ -1493,7 +1307,8 @@ public class GenericObjectPool<T> extend
      * @see #getTimeBetweenEvictionRunsMillis
      * @see #setTimeBetweenEvictionRunsMillis
      */
-    private volatile boolean _testWhileIdle = DEFAULT_TEST_WHILE_IDLE;
+    private volatile boolean _testWhileIdle =
+        GenericObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE;
 
     /**
      * The number of milliseconds to sleep between runs of the idle object
@@ -1504,7 +1319,7 @@ public class GenericObjectPool<T> extend
      * @see #getTimeBetweenEvictionRunsMillis
      */
     private volatile long _timeBetweenEvictionRunsMillis =
-        DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
+        GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
 
     /**
      * The max number of objects to examine during each run of the idle object
@@ -1521,7 +1336,7 @@ public class GenericObjectPool<T> extend
      * @see #setTimeBetweenEvictionRunsMillis
      */
     private volatile int _numTestsPerEvictionRun =
-        DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+        GenericObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
 
     /**
      * The minimum amount of time an object may sit idle in the pool before it
@@ -1535,7 +1350,7 @@ public class GenericObjectPool<T> extend
      * @see #setTimeBetweenEvictionRunsMillis
      */
     private volatile long _minEvictableIdleTimeMillis =
-        DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+        GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
 
     /**
      * The minimum amount of time an object may sit idle in the pool before it
@@ -1548,10 +1363,10 @@ public class GenericObjectPool<T> extend
      * @see #getSoftMinEvictableIdleTimeMillis
      */
     private volatile long _softMinEvictableIdleTimeMillis =
-        DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+        GenericObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
 
     /** Whether or not the pool behaves as a LIFO queue (last in first out) */
-    private volatile boolean _lifo = DEFAULT_LIFO;
+    private volatile boolean _lifo = GenericObjectPoolConfig.DEFAULT_LIFO;
 
     /** My {@link PoolableObjectFactory}. */
     private volatile PoolableObjectFactory<T> _factory;

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java?rev=1135200&r1=1135199&r2=1135200&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java Mon Jun 13 17:51:03 2011
@@ -745,37 +745,37 @@ public class TestGenericObjectPool exten
     @Test
     public void testDefaultConfiguration() throws Exception {
         GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-        assertConfiguration(new GenericObjectPool.Config(),pool);
+        assertConfiguration(new GenericObjectPoolConfig(),pool);
     }
 
     @Test
     public void testConstructors() throws Exception {
         {
             GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
-            assertConfiguration(new GenericObjectPool.Config(),pool);
+            assertConfiguration(new GenericObjectPoolConfig(),pool);
         }
         {
             GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
             pool.setFactory(new SimpleFactory());
-            assertConfiguration(new GenericObjectPool.Config(),pool);
+            assertConfiguration(new GenericObjectPoolConfig(),pool);
         }
     }
 
     @Test
     public void testSetConfig() throws Exception {
-        GenericObjectPool.Config expected = new GenericObjectPool.Config();
+        GenericObjectPoolConfig expected = new GenericObjectPoolConfig();
         GenericObjectPool<Object> pool = new GenericObjectPool<Object>();
         assertConfiguration(expected,pool);
-        expected.maxActive = 2;
-        expected.maxIdle = 3;
-        expected.maxWait = 5L;
-        expected.minEvictableIdleTimeMillis = 7L;
-        expected.numTestsPerEvictionRun = 9;
-        expected.testOnBorrow = true;
-        expected.testOnReturn = true;
-        expected.testWhileIdle = true;
-        expected.timeBetweenEvictionRunsMillis = 11L;
-        expected.whenExhaustedAction = WhenExhaustedAction.FAIL;
+        expected.setMaxTotal(2);
+        expected.setMaxIdle(3);
+        expected.setMaxWait(5L);
+        expected.setMinEvictableIdleTimeMillis(7L);
+        expected.setNumTestsPerEvictionRun(9);
+        expected.setTestOnBorrow(true);
+        expected.setTestOnReturn(true);
+        expected.setTestWhileIdle(true);
+        expected.setTimeBetweenEvictionRunsMillis(11L);
+        expected.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
         pool.setConfig(expected);
         assertConfiguration(expected,pool);
     }
@@ -1290,17 +1290,17 @@ public class TestGenericObjectPool exten
     
     protected GenericObjectPool<Object> pool = null;
 
-    private void assertConfiguration(GenericObjectPool.Config expected, GenericObjectPool<?> actual) throws Exception {
-        assertEquals("testOnBorrow",expected.testOnBorrow,actual.getTestOnBorrow());
-        assertEquals("testOnReturn",expected.testOnReturn,actual.getTestOnReturn());
-        assertEquals("testWhileIdle",expected.testWhileIdle,actual.getTestWhileIdle());
-        assertEquals("whenExhaustedAction",expected.whenExhaustedAction,actual.getWhenExhaustedAction());
-        assertEquals("maxActive",expected.maxActive,actual.getMaxActive());
-        assertEquals("maxIdle",expected.maxIdle,actual.getMaxIdle());
-        assertEquals("maxWait",expected.maxWait,actual.getMaxWait());
-        assertEquals("minEvictableIdleTimeMillis",expected.minEvictableIdleTimeMillis,actual.getMinEvictableIdleTimeMillis());
-        assertEquals("numTestsPerEvictionRun",expected.numTestsPerEvictionRun,actual.getNumTestsPerEvictionRun());
-        assertEquals("timeBetweenEvictionRunsMillis",expected.timeBetweenEvictionRunsMillis,actual.getTimeBetweenEvictionRunsMillis());
+    private void assertConfiguration(GenericObjectPoolConfig<?> expected, GenericObjectPool<?> actual) throws Exception {
+        assertEquals("testOnBorrow",expected.getTestOnBorrow(),actual.getTestOnBorrow());
+        assertEquals("testOnReturn",expected.getTestOnReturn(),actual.getTestOnReturn());
+        assertEquals("testWhileIdle",expected.getTestWhileIdle(),actual.getTestWhileIdle());
+        assertEquals("whenExhaustedAction",expected.getWhenExhaustedAction(),actual.getWhenExhaustedAction());
+        assertEquals("maxActive",expected.getMaxTotal(),actual.getMaxActive());
+        assertEquals("maxIdle",expected.getMaxIdle(),actual.getMaxIdle());
+        assertEquals("maxWait",expected.getMaxWait(),actual.getMaxWait());
+        assertEquals("minEvictableIdleTimeMillis",expected.getMinEvictableIdleTimeMillis(),actual.getMinEvictableIdleTimeMillis());
+        assertEquals("numTestsPerEvictionRun",expected.getNumTestsPerEvictionRun(),actual.getNumTestsPerEvictionRun());
+        assertEquals("timeBetweenEvictionRunsMillis",expected.getTimeBetweenEvictionRunsMillis(),actual.getTimeBetweenEvictionRunsMillis());
     }
 
     public class SimpleFactory implements PoolableObjectFactory<Object> {