commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1051389 [2/3] - in /commons/proper/pool/trunk/src: java/org/apache/commons/pool2/impl/ test/org/apache/commons/pool2/impl/ test/org/apache/commons/pool2/performance/
Date Tue, 21 Dec 2010 06:51:18 GMT
Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java?rev=1051389&r1=1051388&r2=1051389&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java Tue Dec 21 06:51:17 2010
@@ -22,151 +22,22 @@ package org.apache.commons.pool2.impl;
  * @since Pool 2.0
  * @version $Revision$ $Date$
  */
-public class GenericObjectPoolConfig {
-
-    /**
-     * 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
-     * @see #setMaxActive
-     */
-    public static final int DEFAULT_MAX_ACTIVE  = 8;
-
-    /**
-     * The default "when exhausted action" for the pool.
-     *
-     * @see WhenExhaustedAction#BLOCK
-     * @see WhenExhaustedAction#FAIL
-     * @see WhenExhaustedAction#GROW
-     * @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 #getLifo
-     * @see #setLifo
-     */
-    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;
+public final class GenericObjectPoolConfig {
 
     /**
      * The cap on the number of idle instances in the pool.
-     *
-     * @see #getMaxIdle
-     * @see #setMaxIdle
      */
-    private int maxIdle = DEFAULT_MAX_IDLE;
+    private final int maxIdle;
 
     /**
      * The cap on the minimum number of idle instances in the pool.
-     *
-     * @see #getMinIdle
-     * @see #setMinIdle
      */
-    private int minIdle = DEFAULT_MIN_IDLE;
+    private final int minIdle;
 
     /**
      * The cap on the total number of active instances from the pool.
-     *
-     * @see #getMaxActive
-     * @see #setMaxActive
      */
-    private int maxActive = DEFAULT_MAX_ACTIVE;
+    private final int maxTotal;
 
     /**
      * The maximum amount of time (in millis) the
@@ -177,28 +48,15 @@ public class GenericObjectPoolConfig {
      *
      * When less than or equal to 0, the {@link org.apache.commons.pool2.ObjectPool#borrowObject} method
      * may block indefinitely.
-     *
-     * @see #getMaxWait
-     * @see #setMaxWait
-     * @see WhenExhaustedAction#BLOCK
-     * @see #getWhenExhaustedAction
-     * @see #setWhenExhaustedAction
      */
-    private long maxWait = DEFAULT_MAX_WAIT;
+    private final long maxWait;
 
     /**
      * The action to take when the {@link org.apache.commons.pool2.ObjectPool#borrowObject} method
      * is invoked when the pool is exhausted (the maximum number
      * of "active" objects has been reached).
-     *
-     * @see WHEN_EXHAUSTED_ACTION#BLOCK
-     * @see WHEN_EXHAUSTED_ACTION#FAIL
-     * @see WHEN_EXHAUSTED_ACTION#GROW
-     * @see DEFAULT_WHEN_EXHAUSTED_ACTION
-     * @see #getWhenExhaustedAction
-     * @see #setWhenExhaustedAction
      */
-    private WhenExhaustedAction whenExhaustedAction = DEFAULT_WHEN_EXHAUSTED_ACTION;
+    private final WhenExhaustedAction whenExhaustedAction;
 
     /**
      * When <tt>true</tt>, objects will be
@@ -207,46 +65,32 @@ public class GenericObjectPoolConfig {
      * method.  If the object fails to validate,
      * it will be dropped from the pool, and we will attempt
      * to borrow another.
-     *
-     * @see #getTestOnBorrow
-     * @see #setTestOnBorrow
      */
-    private boolean testOnBorrow = DEFAULT_TEST_ON_BORROW;
+    private final boolean testOnBorrow;
 
     /**
      * When <tt>true</tt>, objects will be
      * {@link org.apache.commons.pool2.ObjectPool#validateObject validated}
      * before being returned to the pool within the
      * {@link #returnObject}.
-     *
-     * @see #getTestOnReturn
-     * @see #setTestOnReturn
      */
-    private boolean testOnReturn = DEFAULT_TEST_ON_RETURN;
+    private final boolean testOnReturn;
 
     /**
      * When <tt>true</tt>, objects will be
      * {@link org.apache.commons.pool2.ObjectPool#validateObject validated}
      * by the idle object evictor (if any).  If an object
      * fails to validate, it will be dropped from the pool.
-     *
-     * @see #setTestWhileIdle
-     * @see #getTestWhileIdle
-     * @see #getTimeBetweenEvictionRunsMillis
-     * @see #setTimeBetweenEvictionRunsMillis
      */
-    private boolean testWhileIdle = DEFAULT_TEST_WHILE_IDLE;
+    private final boolean testWhileIdle;
 
     /**
      * The number of milliseconds to sleep between runs of the
      * idle object evictor thread.
      * When non-positive, no idle object evictor thread will be
      * run.
-     *
-     * @see #setTimeBetweenEvictionRunsMillis
-     * @see #getTimeBetweenEvictionRunsMillis
      */
-    private long timeBetweenEvictionRunsMillis = DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
+    private final long timeBetweenEvictionRunsMillis;
 
     /**
      * The max number of objects to examine during each run of the
@@ -255,13 +99,8 @@ public class GenericObjectPoolConfig {
      * When a negative value is supplied, <tt>ceil({@link #getNumIdle})/abs({@link #getNumTestsPerEvictionRun})</tt>
      * tests will be run.  I.e., when the value is <i>-n</i>, roughly one <i>n</i>th of the
      * idle objects will be tested per run.
-     *
-     * @see #setNumTestsPerEvictionRun
-     * @see #getNumTestsPerEvictionRun
-     * @see #getTimeBetweenEvictionRunsMillis
-     * @see #setTimeBetweenEvictionRunsMillis
      */
-    private int numTestsPerEvictionRun =  DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+    private final int numTestsPerEvictionRun;
 
     /**
      * The minimum amount of time an object may sit idle in the pool
@@ -269,21 +108,13 @@ public class GenericObjectPoolConfig {
      * (if any).
      * When non-positive, no objects will be evicted from the pool
      * due to idle time alone.
-     *
-     * @see #setMinEvictableIdleTimeMillis
-     * @see #getMinEvictableIdleTimeMillis
-     * @see #getTimeBetweenEvictionRunsMillis
-     * @see #setTimeBetweenEvictionRunsMillis
      */
-    private long minEvictableIdleTimeMillis = DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+    private final long minEvictableIdleTimeMillis;
 
     /**
-     * Whether or not the pool behaves as a LIFO queue (last in first out)
-     *
-     * @see #getLifo
-     * @see #setLifo
+     * Whether or not the pool behaves as a LIFO queue (last in first out).
      */
-    private boolean lifo = DEFAULT_LIFO;
+    private final boolean lifo;
 
     /**
      * The minimum amount of time an object may sit idle in the pool
@@ -292,114 +123,404 @@ public class GenericObjectPoolConfig {
      * "minIdle" amount of object remain in the pool.
      * When non-positive, no objects will be evicted from the pool
      * due to idle time alone.
-     *
-     * @see #setSoftMinEvictableIdleTimeMillis
-     * @see #getSoftMinEvictableIdleTimeMillis
      */
-    private long softMinEvictableIdleTimeMillis = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+    private final long softMinEvictableIdleTimeMillis;
 
-    public final int getMaxIdle() {
-        return maxIdle;
-    }
-
-    public final void setMaxIdle(int maxIdle) {
+    /**
+     * TODO please fill me
+     *
+     * @param maxIdle
+     * @param minIdle
+     * @param maxTotal
+     * @param maxWait
+     * @param whenExhaustedAction
+     * @param testOnBorrow
+     * @param testOnReturn
+     * @param testWhileIdle
+     * @param timeBetweenEvictionRunsMillis
+     * @param numTestsPerEvictionRun
+     * @param minEvictableIdleTimeMillis
+     * @param lifo
+     * @param softMinEvictableIdleTimeMillis
+     */
+    private GenericObjectPoolConfig(final int maxIdle,
+            final int minIdle,
+            final int maxTotal,
+            final long maxWait,
+            final WhenExhaustedAction whenExhaustedAction,
+            final boolean testOnBorrow,
+            final boolean testOnReturn,
+            final boolean testWhileIdle,
+            final long timeBetweenEvictionRunsMillis,
+            final int numTestsPerEvictionRun,
+            final long minEvictableIdleTimeMillis,
+            final boolean lifo,
+            final long softMinEvictableIdleTimeMillis) {
         this.maxIdle = maxIdle;
-    }
-
-    public final int getMinIdle() {
-        return minIdle;
-    }
-
-    public final void setMinIdle(int minIdle) {
         this.minIdle = minIdle;
+        this.maxTotal = maxTotal;
+        this.maxWait = maxWait;
+        this.whenExhaustedAction = whenExhaustedAction;
+        this.testOnBorrow = testOnBorrow;
+        this.testOnReturn = testOnReturn;
+        this.testWhileIdle = testWhileIdle;
+        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+        this.numTestsPerEvictionRun = numTestsPerEvictionRun;
+        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+        this.lifo = lifo;
+        this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
     }
 
-    public final int getMaxActive() {
-        return maxActive;
+    public int getMaxIdle() {
+        return maxIdle;
     }
 
-    public final void setMaxActive(int maxActive) {
-        this.maxActive = maxActive;
+    public int getMinIdle() {
+        return minIdle;
     }
 
-    public final long getMaxWait() {
-        return maxWait;
+    public int getMaxTotal() {
+        return maxTotal;
     }
 
-    public final void setMaxWait(long maxWait) {
-        this.maxWait = maxWait;
+    public long getMaxWait() {
+        return maxWait;
     }
 
-    public final WhenExhaustedAction getWhenExhaustedAction() {
+    public WhenExhaustedAction getWhenExhaustedAction() {
         return whenExhaustedAction;
     }
 
-    public final void setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
-        this.whenExhaustedAction = whenExhaustedAction;
-    }
-
-    public final boolean getTestOnBorrow() {
+    public boolean getTestOnBorrow() {
         return testOnBorrow;
     }
 
-    public final void setTestOnBorrow(boolean testOnBorrow) {
-        this.testOnBorrow = testOnBorrow;
-    }
-
-    public final boolean getTestOnReturn() {
+    public boolean getTestOnReturn() {
         return testOnReturn;
     }
 
-    public final void setTestOnReturn(boolean testOnReturn) {
-        this.testOnReturn = testOnReturn;
-    }
-
-    public final boolean getTestWhileIdle() {
+    public boolean getTestWhileIdle() {
         return testWhileIdle;
     }
 
-    public final void setTestWhileIdle(boolean testWhileIdle) {
-        this.testWhileIdle = testWhileIdle;
-    }
-
-    public final long getTimeBetweenEvictionRunsMillis() {
+    public long getTimeBetweenEvictionRunsMillis() {
         return timeBetweenEvictionRunsMillis;
     }
 
-    public final void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
-        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
-    }
-
-    public final int getNumTestsPerEvictionRun() {
+    public int getNumTestsPerEvictionRun() {
         return numTestsPerEvictionRun;
     }
 
-    public final void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
-        this.numTestsPerEvictionRun = numTestsPerEvictionRun;
-    }
-
-    public final long getMinEvictableIdleTimeMillis() {
+    public long getMinEvictableIdleTimeMillis() {
         return minEvictableIdleTimeMillis;
     }
 
-    public final void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
-        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
-    }
-
-    public final boolean getLifo() {
+    public boolean getLifo() {
         return lifo;
     }
 
-    public final void setLifo(boolean lifo) {
-        this.lifo = lifo;
-    }
-
-    public final synchronized long getSoftMinEvictableIdleTimeMillis() {
+    public long getSoftMinEvictableIdleTimeMillis() {
         return softMinEvictableIdleTimeMillis;
     }
 
-    public final synchronized void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {
-        this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+    public static final class Builder {
+
+        /**
+         * The default cap on the number of "sleeping" instances in the pool.
+         */
+        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.
+         */
+        public static final int DEFAULT_MIN_IDLE = 0;
+
+        /**
+         * The default cap on the total number of active instances from the pool.
+         */
+        public static final int DEFAULT_MAX_TOTAL = 8;
+
+        /**
+         * The default "when exhausted action" for the pool.
+         */
+        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.
+         */
+        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}.
+         */
+        public static final long DEFAULT_MAX_WAIT = -1L;
+
+        /**
+         * The default "test on borrow" value.
+         */
+        public static final boolean DEFAULT_TEST_ON_BORROW = false;
+
+        /**
+         * The default "test on return" value.
+         */
+        public static final boolean DEFAULT_TEST_ON_RETURN = false;
+
+        /**
+         * The default "test while idle" value.
+         */
+        public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
+
+        /**
+         * The default "time between eviction runs" value.
+         */
+        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.
+         */
+        public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;
+
+        /**
+         * The default value for {@link #getMinEvictableIdleTimeMillis}.
+         */
+        public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000L * 60L * 30L;
+
+        /**
+         * The default value for {@link #getSoftMinEvictableIdleTimeMillis}.
+         */
+        public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;
+
+        /**
+         * The cap on the number of idle instances in the pool.
+         */
+        private int maxIdle = DEFAULT_MAX_IDLE;
+
+        /**
+         * The cap on the minimum number of idle instances in the pool.
+         *
+         * @see #setMinIdle
+         */
+        private int minIdle = DEFAULT_MIN_IDLE;
+
+        /**
+         * The cap on the total number of active instances from the pool.
+         *
+         * @see #setMaxActive
+         */
+        private int maxTotal = DEFAULT_MAX_TOTAL;
+
+        /**
+         * The maximum amount of time (in millis) the
+         * {@link org.apache.commons.pool2.ObjectPool#borrowObject} method should block before throwing
+         * an exception when the pool is exhausted and the
+         * {@link #getWhenExhaustedAction "when exhausted" action} is
+         * {@link WhenExhaustedAction#BLOCK}.
+         *
+         * When less than or equal to 0, the {@link org.apache.commons.pool2.ObjectPool#borrowObject} method
+         * may block indefinitely.
+         *
+         * @see #setMaxWait
+         * @see WhenExhaustedAction#BLOCK
+         * @see #setWhenExhaustedAction
+         */
+        private long maxWait = DEFAULT_MAX_WAIT;
+
+        /**
+         * The action to take when the {@link org.apache.commons.pool2.ObjectPool#borrowObject} method
+         * is invoked when the pool is exhausted (the maximum number
+         * of "active" objects has been reached).
+         *
+         * @see WHEN_EXHAUSTED_ACTION#BLOCK
+         * @see WHEN_EXHAUSTED_ACTION#FAIL
+         * @see WHEN_EXHAUSTED_ACTION#GROW
+         * @see DEFAULT_WHEN_EXHAUSTED_ACTION
+         * @see #setWhenExhaustedAction
+         */
+        private WhenExhaustedAction whenExhaustedAction = DEFAULT_WHEN_EXHAUSTED_ACTION;
+
+        /**
+         * When <tt>true</tt>, objects will be
+         * {@link org.apache.commons.pool2.PoolableObjectFactory#validateObject validated}
+         * before being returned by the {@link org.apache.commons.pool2.ObjectPool#borrowObject}
+         * method.  If the object fails to validate,
+         * it will be dropped from the pool, and we will attempt
+         * to borrow another.
+         *
+         * @see #setTestOnBorrow
+         */
+        private boolean testOnBorrow = DEFAULT_TEST_ON_BORROW;
+
+        /**
+         * When <tt>true</tt>, objects will be
+         * {@link org.apache.commons.pool2.ObjectPool#validateObject validated}
+         * before being returned to the pool within the
+         * {@link #returnObject}.
+         *
+         * @see #setTestOnReturn
+         */
+        private boolean testOnReturn = DEFAULT_TEST_ON_RETURN;
+
+        /**
+         * When <tt>true</tt>, objects will be
+         * {@link org.apache.commons.pool2.ObjectPool#validateObject validated}
+         * by the idle object evictor (if any).  If an object
+         * fails to validate, it will be dropped from the pool.
+         *
+         * @see #setTestWhileIdle
+         * @see #setTimeBetweenEvictionRunsMillis
+         */
+        private boolean testWhileIdle = DEFAULT_TEST_WHILE_IDLE;
+
+        /**
+         * The number of milliseconds to sleep between runs of the
+         * idle object evictor thread.
+         * When non-positive, no idle object evictor thread will be
+         * run.
+         *
+         * @see #setTimeBetweenEvictionRunsMillis
+         */
+        private long timeBetweenEvictionRunsMillis = DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
+
+        /**
+         * The max number of objects to examine during each run of the
+         * idle object evictor thread (if any).
+         * <p>
+         * When a negative value is supplied, <tt>ceil({@link #getNumIdle})/abs({@link #getNumTestsPerEvictionRun})</tt>
+         * tests will be run.  I.e., when the value is <i>-n</i>, roughly one <i>n</i>th of the
+         * idle objects will be tested per run.
+         *
+         * @see #setNumTestsPerEvictionRun
+         * @see #setTimeBetweenEvictionRunsMillis
+         */
+        private int numTestsPerEvictionRun =  DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+
+        /**
+         * The minimum amount of time an object may sit idle in the pool
+         * before it is eligible for eviction by the idle object evictor
+         * (if any).
+         * When non-positive, no objects will be evicted from the pool
+         * due to idle time alone.
+         *
+         * @see #setMinEvictableIdleTimeMillis
+         * @see #setTimeBetweenEvictionRunsMillis
+         */
+        private long minEvictableIdleTimeMillis = DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+
+        /**
+         * Whether or not the pool behaves as a LIFO queue (last in first out)
+         *
+         * @see #setLifo
+         */
+        private boolean lifo = DEFAULT_LIFO;
+
+        /**
+         * The minimum amount of time an object may sit idle in the pool
+         * before it is eligible for eviction by the idle object evictor
+         * (if any), with the extra condition that at least
+         * "minIdle" amount of object remain in the pool.
+         * When non-positive, no objects will be evicted from the pool
+         * due to idle time alone.
+         *
+         * @see #setSoftMinEvictableIdleTimeMillis
+         */
+        private long softMinEvictableIdleTimeMillis = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+
+        public Builder setMaxIdle(int maxIdle) {
+            this.maxIdle = maxIdle;
+            return this;
+        }
+
+        public Builder setMinIdle(int minIdle) {
+            this.minIdle = minIdle;
+            return this;
+        }
+
+        public Builder setMaxTotal(int maxTotal) {
+            this.maxTotal = maxTotal;
+            return this;
+        }
+
+        public Builder setMaxWait(long maxWait) {
+            this.maxWait = maxWait;
+            return this;
+        }
+
+        public Builder setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
+            this.whenExhaustedAction = whenExhaustedAction;
+            return this;
+        }
+
+        public Builder setTestOnBorrow(boolean testOnBorrow) {
+            this.testOnBorrow = testOnBorrow;
+            return this;
+        }
+
+        public Builder setTestOnReturn(boolean testOnReturn) {
+            this.testOnReturn = testOnReturn;
+            return this;
+        }
+
+        public Builder setTestWhileIdle(boolean testWhileIdle) {
+            this.testWhileIdle = testWhileIdle;
+            return this;
+        }
+
+        public Builder setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
+            this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+            return this;
+        }
+
+        public Builder setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
+            this.numTestsPerEvictionRun = numTestsPerEvictionRun;
+            return this;
+        }
+
+        public Builder setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
+            this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+            return this;
+        }
+
+        public Builder setLifo(boolean lifo) {
+            this.lifo = lifo;
+            return this;
+        }
+
+        public Builder setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {
+            this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+            return this;
+        }
+
+        /**
+         * Creates a {@link GenericObjectPoolConfig} instance.
+         *
+         * @return the created {@link GenericObjectPoolConfig} instance.
+         */
+        public GenericObjectPoolConfig createConfig() {
+            return new GenericObjectPoolConfig(maxIdle,
+                    minIdle,
+                    maxTotal,
+                    maxWait,
+                    whenExhaustedAction,
+                    testOnBorrow,
+                    testOnReturn,
+                    testWhileIdle,
+                    timeBetweenEvictionRunsMillis,
+                    numTestsPerEvictionRun,
+                    minEvictableIdleTimeMillis,
+                    lifo,
+                    softMinEvictableIdleTimeMillis);
+        }
+
     }
 
 }

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolFactory.java?rev=1051389&r1=1051388&r2=1051389&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolFactory.java Tue Dec 21 06:51:17 2010
@@ -39,7 +39,7 @@ public class GenericObjectPoolFactory<T>
      * @see GenericObjectPoolConfig#GenericObjectPool(PoolableObjectFactory)
      */
     public GenericObjectPoolFactory(PoolableObjectFactory<T> factory) {
-        this(factory,new GenericObjectPoolConfig());
+        this(factory,new GenericObjectPoolConfig.Builder().createConfig());
     }
 
     /**
@@ -58,14 +58,40 @@ public class GenericObjectPoolFactory<T>
             throw new IllegalArgumentException("config must not be null");
         }
         this._factory = factory;
-        this.config = config;
+        this.maxIdle = config.getMaxIdle();
+        this.minIdle = config.getMinIdle();
+        this.maxTotal = config.getMaxTotal();
+        this.maxWait = config.getMaxWait();
+        this.whenExhaustedAction = config.getWhenExhaustedAction();
+        this.testOnBorrow = config.getTestOnBorrow();
+        this.testOnReturn = config.getTestOnReturn();
+        this.testWhileIdle = config.getTestWhileIdle();
+        this.timeBetweenEvictionRunsMillis = config.getTimeBetweenEvictionRunsMillis();
+        this.numTestsPerEvictionRun = config.getNumTestsPerEvictionRun();
+        this.minEvictableIdleTimeMillis = config.getMinEvictableIdleTimeMillis();
+        this.lifo = config.getLifo();
+        this.softMinEvictableIdleTimeMillis = config.getSoftMinEvictableIdleTimeMillis();
     }
 
     /**
      * {@inheritDoc}
      */
     public ObjectPool<T> createPool() {
-        return new GenericObjectPool<T>(_factory,this.config);
+        return new GenericObjectPool<T>(_factory,new GenericObjectPoolConfig.Builder()
+                .setMaxIdle(maxIdle)
+                .setMinIdle(minIdle)
+                .setMaxTotal(maxTotal)
+                .setMaxWait(maxWait)
+                .setWhenExhaustedAction(whenExhaustedAction)
+                .setTestOnBorrow(testOnBorrow)
+                .setTestOnReturn(testOnReturn)
+                .setTestWhileIdle(testWhileIdle)
+                .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis)
+                .setNumTestsPerEvictionRun(numTestsPerEvictionRun)
+                .setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis)
+                .setLifo(lifo)
+                .setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis)
+                .createConfig());
     }
 
     /**
@@ -73,7 +99,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized int getMaxIdle() {
-        return this.config.getMaxIdle();
+        return this.maxIdle;
     }
 
     /**
@@ -81,7 +107,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setMaxIdle(int maxIdle) {
-        this.config.setMaxIdle(maxIdle);
+        this.maxIdle = maxIdle;
     }
 
     /**
@@ -89,7 +115,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized int getMinIdle() {
-        return this.config.getMinIdle();
+        return this.minIdle;
     }
 
     /**
@@ -97,23 +123,23 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setMinIdle(int minIdle) {
-        this.config.setMinIdle(minIdle);
+        this.minIdle = minIdle;
     }
 
     /**
-     * @return the {@link GenericObjectPoolConfig#getMaxActive() maxActive} setting for pools created by this factory.
-     * @since 1.5.5
+     * @return the {@link GenericObjectPoolConfig#getMaxTotal() maxTotal} setting for pools created by this factory.
+     * @since 2.0
      */
-    public synchronized int getMaxActive() {
-        return this.config.getMaxActive();
+    public synchronized int getMaxTotal() {
+        return this.maxTotal;
     }
 
     /**
      * @param maxActive the {@link GenericObjectPoolConfig#getMaxActive() maxActive} setting for pools created by this factory.
      * @since 2.0
      */
-    public synchronized void setMaxActive(int maxActive) {
-        this.config.setMaxActive(maxActive);
+    public synchronized void setMaxTotal(int maxTotal) {
+        this.maxTotal = maxTotal;
     }
 
     /**
@@ -121,7 +147,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized long getMaxWait() {
-        return this.config.getMaxWait();
+        return this.maxWait;
     }
 
     /**
@@ -129,7 +155,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setMaxWait(long maxWait) {
-        this.config.setMaxWait(maxWait);
+        this.maxWait = maxWait;
     }
 
     /**
@@ -138,7 +164,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized WhenExhaustedAction getWhenExhaustedAction() {
-        return this.config.getWhenExhaustedAction();
+        return this.whenExhaustedAction;
     }
 
     /**
@@ -147,7 +173,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
-        this.config.setWhenExhaustedAction(whenExhaustedAction);
+        this.whenExhaustedAction = whenExhaustedAction;
     }
 
     /**
@@ -156,7 +182,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized boolean getTestOnBorrow() {
-        return this.config.getTestOnBorrow();
+        return this.testOnBorrow;
     }
 
     /**
@@ -165,7 +191,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setTestOnBorrow(boolean testOnBorrow) {
-        this.config.setTestOnBorrow(testOnBorrow);
+        this.testOnBorrow = testOnBorrow;
     }
 
     /**
@@ -174,7 +200,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized boolean getTestOnReturn() {
-        return this.config.getTestOnReturn();
+        return this.testOnReturn;
     }
 
     /**
@@ -183,7 +209,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setTestOnReturn(boolean testOnReturn) {
-        this.config.setTestOnReturn(testOnReturn);
+        this.testOnReturn = testOnReturn;
     }
 
     /**
@@ -192,7 +218,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized boolean getTestWhileIdle() {
-        return this.config.getTestWhileIdle();
+        return this.testWhileIdle;
     }
 
     /**
@@ -201,7 +227,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setTestWhileIdle(boolean testWhileIdle) {
-        this.config.setTestWhileIdle(testWhileIdle);
+        this.testWhileIdle = testWhileIdle;
     }
 
     /**
@@ -210,7 +236,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized long getTimeBetweenEvictionRunsMillis() {
-        return this.config.getTimeBetweenEvictionRunsMillis();
+        return this.timeBetweenEvictionRunsMillis;
     }
 
     /**
@@ -219,7 +245,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
-        this.config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
+        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
     }
 
     /**
@@ -228,7 +254,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized int getNumTestsPerEvictionRun() {
-        return this.config.getNumTestsPerEvictionRun();
+        return this.numTestsPerEvictionRun;
     }
 
     /**
@@ -237,7 +263,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
-        this.config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
+        this.numTestsPerEvictionRun = numTestsPerEvictionRun;
     }
 
     /**
@@ -246,7 +272,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized long getMinEvictableIdleTimeMillis() {
-        return this.config.getMinEvictableIdleTimeMillis();
+        return this.minEvictableIdleTimeMillis;
     }
 
     /**
@@ -255,7 +281,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
-        this.config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
+        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
     }
 
     /**
@@ -264,7 +290,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized long getSoftMinEvictableIdleTimeMillis() {
-        return this.config.getSoftMinEvictableIdleTimeMillis();
+        return this.softMinEvictableIdleTimeMillis;
     }
 
     /**
@@ -273,7 +299,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {
-        this.config.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
+        this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
     }
 
     /**
@@ -281,7 +307,7 @@ public class GenericObjectPoolFactory<T>
      * @since 1.5.5
      */
     public synchronized boolean getLifo() {
-        return this.config.getLifo();
+        return this.lifo;
     }
 
     /**
@@ -289,7 +315,7 @@ public class GenericObjectPoolFactory<T>
      * @since 2.0
      */
     public synchronized void setLifo(boolean lifo) {
-        this.config.setLifo(lifo);
+        this.lifo = lifo;
     }
 
     /**
@@ -305,8 +331,138 @@ public class GenericObjectPoolFactory<T>
     private final PoolableObjectFactory<T> _factory;
 
     /**
-     * The {@link GenericObjectPoolConfig} used by pools created by this factory.
+     * The cap on the number of idle instances in the pool.
+     */
+    private int maxIdle; // @GuardedBy("this")
+
+    /**
+     * The cap on the minimum number of idle instances in the pool.
+     *
+     * @see #setMinIdle
+     */
+    private int minIdle; // @GuardedBy("this")
+
+    /**
+     * The cap on the total number of active instances from the pool.
+     *
+     * @see #setMaxActive
+     */
+    private int maxTotal; // @GuardedBy("this")
+
+    /**
+     * The maximum amount of time (in millis) the
+     * {@link org.apache.commons.pool2.ObjectPool#borrowObject} method should block before throwing
+     * an exception when the pool is exhausted and the
+     * {@link #getWhenExhaustedAction "when exhausted" action} is
+     * {@link WhenExhaustedAction#BLOCK}.
+     *
+     * When less than or equal to 0, the {@link org.apache.commons.pool2.ObjectPool#borrowObject} method
+     * may block indefinitely.
+     *
+     * @see #setMaxWait
+     * @see WhenExhaustedAction#BLOCK
+     * @see #setWhenExhaustedAction
+     */
+    private long maxWait; // @GuardedBy("this")
+
+    /**
+     * The action to take when the {@link org.apache.commons.pool2.ObjectPool#borrowObject} method
+     * is invoked when the pool is exhausted (the maximum number
+     * of "active" objects has been reached).
+     *
+     * @see WHEN_EXHAUSTED_ACTION#BLOCK
+     * @see WHEN_EXHAUSTED_ACTION#FAIL
+     * @see WHEN_EXHAUSTED_ACTION#GROW
+     * @see DEFAULT_WHEN_EXHAUSTED_ACTION
+     * @see #setWhenExhaustedAction
+     */
+    private WhenExhaustedAction whenExhaustedAction; // @GuardedBy("this")
+
+    /**
+     * When <tt>true</tt>, objects will be
+     * {@link org.apache.commons.pool2.PoolableObjectFactory#validateObject validated}
+     * before being returned by the {@link org.apache.commons.pool2.ObjectPool#borrowObject}
+     * method.  If the object fails to validate,
+     * it will be dropped from the pool, and we will attempt
+     * to borrow another.
+     *
+     * @see #setTestOnBorrow
+     */
+    private boolean testOnBorrow; // @GuardedBy("this")
+
+    /**
+     * When <tt>true</tt>, objects will be
+     * {@link org.apache.commons.pool2.ObjectPool#validateObject validated}
+     * before being returned to the pool within the
+     * {@link #returnObject}.
+     *
+     * @see #setTestOnReturn
+     */
+    private boolean testOnReturn; // @GuardedBy("this")
+
+    /**
+     * When <tt>true</tt>, objects will be
+     * {@link org.apache.commons.pool2.ObjectPool#validateObject validated}
+     * by the idle object evictor (if any).  If an object
+     * fails to validate, it will be dropped from the pool.
+     *
+     * @see #setTestWhileIdle
+     * @see #setTimeBetweenEvictionRunsMillis
+     */
+    private boolean testWhileIdle; // @GuardedBy("this")
+
+    /**
+     * The number of milliseconds to sleep between runs of the
+     * idle object evictor thread.
+     * When non-positive, no idle object evictor thread will be
+     * run.
+     *
+     * @see #setTimeBetweenEvictionRunsMillis
+     */
+    private long timeBetweenEvictionRunsMillis; // @GuardedBy("this")
+
+    /**
+     * The max number of objects to examine during each run of the
+     * idle object evictor thread (if any).
+     * <p>
+     * When a negative value is supplied, <tt>ceil({@link #getNumIdle})/abs({@link #getNumTestsPerEvictionRun})</tt>
+     * tests will be run.  I.e., when the value is <i>-n</i>, roughly one <i>n</i>th of the
+     * idle objects will be tested per run.
+     *
+     * @see #setNumTestsPerEvictionRun
+     * @see #setTimeBetweenEvictionRunsMillis
+     */
+    private int numTestsPerEvictionRun; // @GuardedBy("this")
+
+    /**
+     * The minimum amount of time an object may sit idle in the pool
+     * before it is eligible for eviction by the idle object evictor
+     * (if any).
+     * When non-positive, no objects will be evicted from the pool
+     * due to idle time alone.
+     *
+     * @see #setMinEvictableIdleTimeMillis
+     * @see #setTimeBetweenEvictionRunsMillis
+     */
+    private long minEvictableIdleTimeMillis; // @GuardedBy("this")
+
+    /**
+     * Whether or not the pool behaves as a LIFO queue (last in first out)
+     *
+     * @see #setLifo
+     */
+    private boolean lifo; // @GuardedBy("this")
+
+    /**
+     * The minimum amount of time an object may sit idle in the pool
+     * before it is eligible for eviction by the idle object evictor
+     * (if any), with the extra condition that at least
+     * "minIdle" amount of object remain in the pool.
+     * When non-positive, no objects will be evicted from the pool
+     * due to idle time alone.
+     *
+     * @see #setSoftMinEvictableIdleTimeMillis
      */
-    private final GenericObjectPoolConfig config;
+    private long softMinEvictableIdleTimeMillis; // @GuardedBy("this")
 
 }

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java?rev=1051389&r1=1051388&r2=1051389&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java Tue Dec 21 06:51:17 2010
@@ -65,8 +65,8 @@ public class TestGenericKeyedObjectPool 
                 public void passivateObject(Object key, Object obj) { }
             }
         );
-        pool.setMaxActive(mincapacity);
-        pool.setMaxIdle(mincapacity);
+        pool.setMaxTotalPerKey(mincapacity);
+        pool.setMaxIdlePerKey(mincapacity);
         return pool;
     }
 
@@ -106,7 +106,7 @@ public class TestGenericKeyedObjectPool 
 
     @Test
     public void testNegativeMaxActive() throws Exception {
-        pool.setMaxActive(-1);
+        pool.setMaxTotalPerKey(-1);
         pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
         String obj = pool.borrowObject("");
         assertEquals("0",obj);
@@ -164,9 +164,9 @@ public class TestGenericKeyedObjectPool 
     }
 
     @Test
-    public void testMaxIdle() throws Exception {
-        pool.setMaxActive(100);
-        pool.setMaxIdle(8);
+    public void testMaxIdlePerKey() throws Exception {
+        pool.setMaxTotalPerKey(100);
+        pool.setMaxIdlePerKey(8);
         String[] active = new String[100];
         for(int i=0;i<100;i++) {
             active[i] = pool.borrowObject("");
@@ -200,7 +200,7 @@ public class TestGenericKeyedObjectPool 
 
     @Test
     public void testMaxActive() throws Exception {
-        pool.setMaxActive(3);
+        pool.setMaxTotalPerKey(3);
         pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
 
         pool.borrowObject("");
@@ -216,7 +216,7 @@ public class TestGenericKeyedObjectPool 
 
     @Test
     public void testMaxActiveZero() throws Exception {
-        pool.setMaxActive(0);
+        pool.setMaxTotalPerKey(0);
         pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
 
         try {
@@ -229,7 +229,7 @@ public class TestGenericKeyedObjectPool 
     
     @Test
     public void testWhenExhaustedGrow() throws Exception {
-        pool.setMaxActive(1);
+        pool.setMaxTotalPerKey(1);
         pool.setMaxTotal(1);
         pool.setWhenExhaustedAction(WhenExhaustedAction.GROW);
         for (int i = 0; i < 10; i++) {
@@ -239,7 +239,7 @@ public class TestGenericKeyedObjectPool 
 
     @Test
     public void testMaxTotal() throws Exception {
-        pool.setMaxActive(2);
+        pool.setMaxTotalPerKey(2);
         pool.setMaxTotal(3);
         pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
 
@@ -294,7 +294,7 @@ public class TestGenericKeyedObjectPool 
 
     @Test
     public void testMaxTotalLRU() throws Exception {
-        pool.setMaxActive(2);
+        pool.setMaxTotalPerKey(2);
         pool.setMaxTotal(3);
 //        pool.setWhenExhaustedAction(GenericKeyedObjectPoolConfig.WHEN_EXHAUSTED_GROW);
 
@@ -346,12 +346,12 @@ public class TestGenericKeyedObjectPool 
     public void testSettersAndGetters() throws Exception {
         GenericKeyedObjectPool<String,String> pool = new GenericKeyedObjectPool<String,String>(new SimpleFactory<String>());
         {
-            pool.setMaxActive(123);
-            assertEquals(123,pool.getMaxActive());
+            pool.setMaxTotalPerKey(123);
+            assertEquals(123,pool.getMaxTotalPerKey());
         }
         {
-            pool.setMaxIdle(12);
-            assertEquals(12,pool.getMaxIdle());
+            pool.setMaxIdlePerKey(12);
+            assertEquals(12,pool.getMaxIdlePerKey());
         }
         {
             pool.setMaxWait(1234L);
@@ -399,8 +399,8 @@ public class TestGenericKeyedObjectPool 
 
     @Test
     public void testEviction() throws Exception {
-        pool.setMaxIdle(500);
-        pool.setMaxActive(500);
+        pool.setMaxIdlePerKey(500);
+        pool.setMaxTotalPerKey(500);
         pool.setNumTestsPerEvictionRun(100);
         pool.setMinEvictableIdleTimeMillis(250L);
         pool.setTimeBetweenEvictionRunsMillis(500L);
@@ -449,8 +449,8 @@ public class TestGenericKeyedObjectPool 
 
     @Test
     public void testEviction2() throws Exception {
-        pool.setMaxIdle(500);
-        pool.setMaxActive(500);
+        pool.setMaxIdlePerKey(500);
+        pool.setMaxTotalPerKey(500);
         pool.setNumTestsPerEvictionRun(100);
         pool.setMinEvictableIdleTimeMillis(500L);
         pool.setTimeBetweenEvictionRunsMillis(500L);
@@ -517,8 +517,8 @@ public class TestGenericKeyedObjectPool 
     }
     
     public void testThreaded1() throws Exception {
-        pool.setMaxActive(15);
-        pool.setMaxIdle(15);
+        pool.setMaxTotalPerKey(15);
+        pool.setMaxIdlePerKey(15);
         pool.setMaxWait(1000L);
         runTestThreads(20, 100, 50);
     }
@@ -533,20 +533,20 @@ public class TestGenericKeyedObjectPool 
         SimpleFactory<String> factory = new SimpleFactory<String>();
         factory.setEvenValid(false);     // Every other validation fails
         factory.setDestroyLatency(100);  // Destroy takes 100 ms
-        factory.setMaxActive(maxTotal);  // (makes - destroys) bound
+        factory.setMaxTotalPerKey(maxTotal);  // (makes - destroys) bound
         factory.setValidationEnabled(true);
         pool = new GenericKeyedObjectPool<String,String>(factory);
         pool.setMaxTotal(maxTotal);
-        pool.setMaxIdle(-1);
+        pool.setMaxIdlePerKey(-1);
         pool.setTestOnReturn(true);
         pool.setMaxWait(10000L);
         runTestThreads(5, 10, 50);
     }
 
     public void testMinIdle() throws Exception {
-        pool.setMaxIdle(500);
+        pool.setMaxIdlePerKey(500);
         pool.setMinIdle(5);
-        pool.setMaxActive(10);
+        pool.setMaxTotalPerKey(10);
         pool.setNumTestsPerEvictionRun(0);
         pool.setMinEvictableIdleTimeMillis(50L);
         pool.setTimeBetweenEvictionRunsMillis(100L);
@@ -583,9 +583,9 @@ public class TestGenericKeyedObjectPool 
     }
 
     public void testMinIdleMaxActive() throws Exception {
-        pool.setMaxIdle(500);
+        pool.setMaxIdlePerKey(500);
         pool.setMinIdle(5);
-        pool.setMaxActive(10);
+        pool.setMaxTotalPerKey(10);
         pool.setNumTestsPerEvictionRun(0);
         pool.setMinEvictableIdleTimeMillis(50L);
         pool.setTimeBetweenEvictionRunsMillis(100L);
@@ -635,9 +635,9 @@ public class TestGenericKeyedObjectPool 
     }
 
     public void testMinIdleNoPopulateImmediately() throws Exception {
-        pool.setMaxIdle(500);
+        pool.setMaxIdlePerKey(500);
         pool.setMinIdle(5);
-        pool.setMaxActive(10);
+        pool.setMaxTotalPerKey(10);
         pool.setNumTestsPerEvictionRun(0);
         pool.setMinEvictableIdleTimeMillis(50L);
         pool.setTimeBetweenEvictionRunsMillis(1000L);
@@ -656,9 +656,9 @@ public class TestGenericKeyedObjectPool 
     }
 
     public void testMinIdleNoPreparePool() throws Exception {
-        pool.setMaxIdle(500);
+        pool.setMaxIdlePerKey(500);
         pool.setMinIdle(5);
-        pool.setMaxActive(10);
+        pool.setMaxTotalPerKey(10);
         pool.setNumTestsPerEvictionRun(0);
         pool.setMinEvictableIdleTimeMillis(50L);
         pool.setTimeBetweenEvictionRunsMillis(100L);
@@ -913,7 +913,7 @@ public class TestGenericKeyedObjectPool 
         int[] smallPrimes = {2, 3, 5, 7};
         Random random = new Random();
         random.setSeed(System.currentTimeMillis());
-        pool.setMaxIdle(-1);
+        pool.setMaxIdlePerKey(-1);
         for (int i = 0; i < smallPrimes.length; i++) {
             pool.setNumTestsPerEvictionRun(smallPrimes[i]);
             for (int j = 0; j < 5; j++) {// Try the tests a few times
@@ -996,7 +996,7 @@ public class TestGenericKeyedObjectPool 
     
     public void testConstructors() {
         
-        // Make constructor arguments all different from defaults
+        // Make constructor arguments all different from Builder.DEFAULTs
         int maxActive = 1;
         int maxIdle = 2;
         long maxWait = 3;
@@ -1018,46 +1018,47 @@ public class TestGenericKeyedObjectPool 
             }
         };   
         GenericKeyedObjectPool<Object,Object> pool = new GenericKeyedObjectPool<Object,Object>(factory);
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_ACTIVE, pool.getMaxActive());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE, pool.getMaxIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_WAIT, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_IDLE_PER_KEY, pool.getMaxTotalPerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_IDLE_PER_KEY, pool.getMaxIdlePerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_WAIT, pool.getMaxWait());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_IDLE_PER_KEY, pool.getMinIdlePerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_BORROW,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_ON_BORROW,
                 pool.getTestOnBorrow());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_RETURN,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_ON_RETURN,
                 pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_WHEN_EXHAUSTED_ACTION,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_WHEN_EXHAUSTED_ACTION,
                 pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
-        
-        GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
-        config.setLifo(lifo);
-        config.setMaxActive(maxActive);
-        config.setMaxIdle(maxIdle);
-        config.setMinIdle(minIdle);
-        config.setMaxTotal(maxTotal);
-        config.setMaxWait(maxWait);
-        config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
-        config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
-        config.setTestOnBorrow(testOnBorrow);
-        config.setTestOnReturn(testOnReturn);
-        config.setTestWhileIdle(testWhileIdle);
-        config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
-        config.setWhenExhaustedAction(whenExhaustedAction);
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_LIFO, pool.getLifo());
+
+        GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig.Builder()
+            .setLifo(lifo)
+            .setMaxTotalPerKey(maxActive)
+            .setMaxIdlePerKey(maxIdle)
+            .setMinIdlePerKey(minIdle)
+            .setMaxTotal(maxTotal)
+            .setMaxWait(maxWait)
+            .setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis)
+            .setNumTestsPerEvictionRun(numTestsPerEvictionRun)
+            .setTestOnBorrow(testOnBorrow)
+            .setTestOnReturn(testOnReturn)
+            .setTestWhileIdle(testWhileIdle)
+            .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis)
+            .setWhenExhaustedAction(whenExhaustedAction)
+            .createConfig();
         pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
-        assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(maxIdle, pool.getMaxIdle());
+        assertEquals(maxActive, pool.getMaxTotalPerKey());
+        assertEquals(maxIdle, pool.getMaxIdlePerKey());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(minIdle, pool.getMinIdle());
+        assertEquals(minIdle, pool.getMinIdlePerKey());
         assertEquals(maxTotal, pool.getMaxTotal());
         assertEquals(minEvictableIdleTimeMillis,
                 pool.getMinEvictableIdleTimeMillis());
@@ -1070,149 +1071,155 @@ public class TestGenericKeyedObjectPool 
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
         assertEquals(lifo, pool.getLifo());
 
-        config = new GenericKeyedObjectPoolConfig();
-        config.setMaxActive(maxActive);
+        config = new GenericKeyedObjectPoolConfig.Builder()
+                .setMaxTotalPerKey(maxActive)
+                .createConfig();
         pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
-        assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE, pool.getMaxIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_WAIT, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        assertEquals(maxActive, pool.getMaxTotalPerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_IDLE_PER_KEY, pool.getMaxIdlePerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_WAIT, pool.getMaxWait());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_IDLE_PER_KEY, pool.getMinIdlePerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_BORROW,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_ON_BORROW,
                 pool.getTestOnBorrow());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_RETURN,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_ON_RETURN,
                 pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_WHEN_EXHAUSTED_ACTION,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_WHEN_EXHAUSTED_ACTION,
                 pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_LIFO, pool.getLifo());
 
-        config = new GenericKeyedObjectPoolConfig();
-        config.setMaxActive(maxActive);
-        config.setWhenExhaustedAction(whenExhaustedAction);
-        config.setMaxWait(maxWait);
+        config = new GenericKeyedObjectPoolConfig.Builder()
+            .setMaxTotalPerKey(maxActive)
+            .setWhenExhaustedAction(whenExhaustedAction)
+            .setMaxWait(maxWait)
+            .createConfig();
         pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
-        assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE, pool.getMaxIdle());
+        assertEquals(maxActive, pool.getMaxTotalPerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_IDLE_PER_KEY, pool.getMaxIdlePerKey());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_IDLE_PER_KEY, pool.getMinIdlePerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_BORROW,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_ON_BORROW,
                 pool.getTestOnBorrow());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_RETURN,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_ON_RETURN,
                 pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_LIFO, pool.getLifo());
 
-        config = new GenericKeyedObjectPoolConfig();
-        config.setMaxActive(maxActive);
-        config.setWhenExhaustedAction(whenExhaustedAction);
-        config.setMaxWait(maxWait);
-        config.setTestOnReturn(testOnReturn);
-        config.setTestOnReturn(testOnReturn);
+        config = new GenericKeyedObjectPoolConfig.Builder()
+            .setMaxTotalPerKey(maxActive)
+            .setWhenExhaustedAction(whenExhaustedAction)
+            .setMaxWait(maxWait)
+            .setTestOnReturn(testOnReturn)
+            .setTestOnReturn(testOnReturn)
+            .createConfig();
         pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
-        assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE, pool.getMaxIdle());
+        assertEquals(maxActive, pool.getMaxTotalPerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_IDLE_PER_KEY, pool.getMaxIdlePerKey());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_IDLE_PER_KEY, pool.getMinIdlePerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
         assertEquals(testOnBorrow,pool.getTestOnBorrow());
         assertEquals(testOnReturn,pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_LIFO, pool.getLifo());
 
-        config = new GenericKeyedObjectPoolConfig();
-        config.setMaxActive(maxActive);
-        config.setWhenExhaustedAction(whenExhaustedAction);
-        config.setMaxWait(maxWait);
-        config.setMinIdle(minIdle);
+        config = new GenericKeyedObjectPoolConfig.Builder()
+            .setMaxTotalPerKey(maxActive)
+            .setWhenExhaustedAction(whenExhaustedAction)
+            .setMaxWait(maxWait)
+            .setMinIdlePerKey(minIdle)
+            .createConfig();
         pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
-        assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(maxIdle, pool.getMaxIdle());
+        assertEquals(maxActive, pool.getMaxTotalPerKey());
+        assertEquals(maxIdle, pool.getMaxIdlePerKey());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_IDLE_PER_KEY, pool.getMinIdlePerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_BORROW,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_ON_BORROW,
                 pool.getTestOnBorrow());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_RETURN,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_ON_RETURN,
                 pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_LIFO, pool.getLifo());
 
-        config = new GenericKeyedObjectPoolConfig();
-        config.setMaxActive(maxActive);
-        config.setWhenExhaustedAction(whenExhaustedAction);
-        config.setMaxWait(maxWait);
-        config.setMaxIdle(maxIdle);
-        config.setTestOnBorrow(testOnBorrow);
-        config.setTestOnReturn(testOnReturn);
+        config = new GenericKeyedObjectPoolConfig.Builder()
+            .setMaxTotalPerKey(maxActive)
+            .setWhenExhaustedAction(whenExhaustedAction)
+            .setMaxWait(maxWait)
+            .setMaxIdlePerKey(maxIdle)
+            .setTestOnBorrow(testOnBorrow)
+            .setTestOnReturn(testOnReturn)
+            .createConfig();
         pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
-        assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(maxIdle, pool.getMaxIdle());
+        assertEquals(maxActive, pool.getMaxTotalPerKey());
+        assertEquals(maxIdle, pool.getMaxIdlePerKey());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_IDLE_PER_KEY, pool.getMinIdlePerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
         assertEquals(testOnBorrow, pool.getTestOnBorrow());
         assertEquals(testOnReturn, pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_LIFO, pool.getLifo());
 
-        config = new GenericKeyedObjectPoolConfig();
-        config.setMaxActive(maxActive);
-        config.setWhenExhaustedAction(whenExhaustedAction);
-        config.setMaxWait(maxWait);
-        config.setMaxIdle(maxIdle);
-        config.setTestOnBorrow(testOnBorrow);
-        config.setTestOnReturn(testOnReturn);
-        config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
-        config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
-        config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
-        config.setTestWhileIdle(testWhileIdle);
+        config = new GenericKeyedObjectPoolConfig.Builder()
+            .setMaxTotalPerKey(maxActive)
+            .setWhenExhaustedAction(whenExhaustedAction)
+            .setMaxWait(maxWait)
+            .setMaxIdlePerKey(maxIdle)
+            .setTestOnBorrow(testOnBorrow)
+            .setTestOnReturn(testOnReturn)
+            .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis)
+            .setNumTestsPerEvictionRun(numTestsPerEvictionRun)
+            .setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis)
+            .setTestWhileIdle(testWhileIdle)
+            .createConfig();
         pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
-        assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(maxIdle, pool.getMaxIdle());
+        assertEquals(maxActive, pool.getMaxTotalPerKey());
+        assertEquals(maxIdle, pool.getMaxIdlePerKey());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_IDLE_PER_KEY, pool.getMinIdlePerKey());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
         assertEquals(minEvictableIdleTimeMillis,
                 pool.getMinEvictableIdleTimeMillis());
         assertEquals(numTestsPerEvictionRun,
@@ -1224,25 +1231,26 @@ public class TestGenericKeyedObjectPool 
         assertEquals(timeBetweenEvictionRunsMillis,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_LIFO, pool.getLifo());
 
-        config = new GenericKeyedObjectPoolConfig();
-        config.setMaxActive(maxActive);
-        config.setWhenExhaustedAction(whenExhaustedAction);
-        config.setMaxWait(maxWait);
-        config.setMaxIdle(maxIdle);
-        config.setMaxTotal(maxTotal);
-        config.setTestOnBorrow(testOnBorrow);
-        config.setTestOnReturn(testOnReturn);
-        config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
-        config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
-        config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
-        config.setTestWhileIdle(testWhileIdle);
+        config = new GenericKeyedObjectPoolConfig.Builder()
+            .setMaxTotalPerKey(maxActive)
+            .setWhenExhaustedAction(whenExhaustedAction)
+            .setMaxWait(maxWait)
+            .setMaxIdlePerKey(maxIdle)
+            .setMaxTotal(maxTotal)
+            .setTestOnBorrow(testOnBorrow)
+            .setTestOnReturn(testOnReturn)
+            .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis)
+            .setNumTestsPerEvictionRun(numTestsPerEvictionRun)
+            .setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis)
+            .setTestWhileIdle(testWhileIdle)
+            .createConfig();
         pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
-        assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(maxIdle, pool.getMaxIdle());
+        assertEquals(maxActive, pool.getMaxTotalPerKey());
+        assertEquals(maxIdle, pool.getMaxIdlePerKey());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_MIN_IDLE_PER_KEY, pool.getMinIdlePerKey());
         assertEquals(maxTotal, pool.getMaxTotal());
         assertEquals(minEvictableIdleTimeMillis,
                 pool.getMinEvictableIdleTimeMillis());
@@ -1255,26 +1263,27 @@ public class TestGenericKeyedObjectPool 
         assertEquals(timeBetweenEvictionRunsMillis,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_LIFO, pool.getLifo());
 
-        config = new GenericKeyedObjectPoolConfig();
-        config.setMaxActive(maxActive);
-        config.setWhenExhaustedAction(whenExhaustedAction);
-        config.setMaxWait(maxWait);
-        config.setMaxIdle(maxIdle);
-        config.setMaxTotal(maxTotal);
-        config.setMinIdle(minIdle);
-        config.setTestOnBorrow(testOnBorrow);
-        config.setTestOnReturn(testOnReturn);
-        config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
-        config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
-        config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
-        config.setTestWhileIdle(testWhileIdle);
+        config = new GenericKeyedObjectPoolConfig.Builder()
+            .setMaxTotalPerKey(maxActive)
+            .setWhenExhaustedAction(whenExhaustedAction)
+            .setMaxWait(maxWait)
+            .setMaxIdlePerKey(maxIdle)
+            .setMaxTotal(maxTotal)
+            .setMinIdlePerKey(minIdle)
+            .setTestOnBorrow(testOnBorrow)
+            .setTestOnReturn(testOnReturn)
+            .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis)
+            .setNumTestsPerEvictionRun(numTestsPerEvictionRun)
+            .setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis)
+            .setTestWhileIdle(testWhileIdle)
+            .createConfig();
         pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
-        assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(maxIdle, pool.getMaxIdle());
+        assertEquals(maxActive, pool.getMaxTotalPerKey());
+        assertEquals(maxIdle, pool.getMaxIdlePerKey());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(minIdle, pool.getMinIdle());
+        assertEquals(minIdle, pool.getMinIdlePerKey());
         assertEquals(maxTotal, pool.getMaxTotal());
         assertEquals(minEvictableIdleTimeMillis,
                 pool.getMinEvictableIdleTimeMillis());
@@ -1287,27 +1296,28 @@ public class TestGenericKeyedObjectPool 
         assertEquals(timeBetweenEvictionRunsMillis,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.Builder.DEFAULT_LIFO, pool.getLifo());
 
-        config = new GenericKeyedObjectPoolConfig();
-        config.setMaxActive(maxActive);
-        config.setWhenExhaustedAction(whenExhaustedAction);
-        config.setMaxWait(maxWait);
-        config.setMaxIdle(maxIdle);
-        config.setMaxTotal(maxTotal);
-        config.setMinIdle(minIdle);
-        config.setTestOnBorrow(testOnBorrow);
-        config.setTestOnReturn(testOnReturn);
-        config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
-        config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
-        config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
-        config.setTestWhileIdle(testWhileIdle);
-        config.setLifo(lifo);
+        config = new GenericKeyedObjectPoolConfig.Builder()
+            .setMaxTotalPerKey(maxActive)
+            .setWhenExhaustedAction(whenExhaustedAction)
+            .setMaxWait(maxWait)
+            .setMaxIdlePerKey(maxIdle)
+            .setMaxTotal(maxTotal)
+            .setMinIdlePerKey(minIdle)
+            .setTestOnBorrow(testOnBorrow)
+            .setTestOnReturn(testOnReturn)
+            .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis)
+            .setNumTestsPerEvictionRun(numTestsPerEvictionRun)
+            .setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis)
+            .setTestWhileIdle(testWhileIdle)
+            .setLifo(lifo)
+            .createConfig();
         pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
-        assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(maxIdle, pool.getMaxIdle());
+        assertEquals(maxActive, pool.getMaxTotalPerKey());
+        assertEquals(maxIdle, pool.getMaxIdlePerKey());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(minIdle, pool.getMinIdle());
+        assertEquals(minIdle, pool.getMinIdlePerKey());
         assertEquals(maxTotal, pool.getMaxTotal());
         assertEquals(minEvictableIdleTimeMillis,
                 pool.getMinEvictableIdleTimeMillis());
@@ -1407,7 +1417,7 @@ public class TestGenericKeyedObjectPool 
         GenericKeyedObjectPool<String,String> pool = new GenericKeyedObjectPool<String,String>(factory);
         pool.setWhenExhaustedAction(WhenExhaustedAction.BLOCK);
         pool.setMaxWait(5000);
-        pool.setMaxActive(1);
+        pool.setMaxTotalPerKey(1);
         pool.setMaxTotal(-1);
         pool.borrowObject("one");
         long start = System.currentTimeMillis();
@@ -1451,7 +1461,7 @@ public class TestGenericKeyedObjectPool 
         GenericKeyedObjectPool<String,String> pool = new GenericKeyedObjectPool<String,String>(factory);
         pool.setWhenExhaustedAction(WhenExhaustedAction.BLOCK);
         pool.setMaxWait(maxWait);
-        pool.setMaxActive(threadsPerKey);
+        pool.setMaxTotalPerKey(threadsPerKey);
         // Create enough threads so half the threads will have to wait
         WaitingTestThread wtt[] = new WaitingTestThread[keyCount * threadsPerKey * 2];
         for(int i=0; i < wtt.length; i++){
@@ -1673,7 +1683,7 @@ public class TestGenericKeyedObjectPool 
             }
         }
         
-        public void setMaxActive(int maxActive) {
+        public void setMaxTotalPerKey(int maxActive) {
             this.maxActive = maxActive;
         }
         public void setDestroyLatency(long destroyLatency) {



Mime
View raw message