commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1051389 [1/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
Author: simonetripodi
Date: Tue Dec 21 06:51:17 2010
New Revision: 1051389

URL: http://svn.apache.org/viewvc?rev=1051389&view=rev
Log:
refactored GOP and GKOP Configurations (and related Pool/Factory) according to http://wiki.apache.org/commons/PoolRoadMap

Modified:
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolFactory.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPoolFactory.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericObjectPoolFactory.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/performance/PerformanceTest.java

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1051389&r1=1051388&r2=1051389&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java Tue Dec 21 06:51:17 2010
@@ -209,7 +209,7 @@ public class GenericKeyedObjectPool<K,V>
      * objects if not <code>null</code>
      */
     public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory) {
-        this(factory, new GenericKeyedObjectPoolConfig());
+        this(factory, new GenericKeyedObjectPoolConfig.Builder().createConfig());
     }
 
     /**
@@ -226,12 +226,24 @@ public class GenericKeyedObjectPool<K,V>
             throw new IllegalArgumentException("config must not be null");
         }
         _factory = factory;
-        this.config = config;
+        this.maxIdlePerKey = config.getMaxIdlePerKey();
+        this.minIdlePerKey = config.getMinIdlePerKey();
+        this.maxTotalPerKey = config.getMaxTotalPerKey();
+        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();
 
         _poolMap = new HashMap<K,ObjectQueue>();
         _poolList = new CursorableLinkedList<K>();
 
-        startEvictor(this.config.getTimeBetweenEvictionRunsMillis());
+        startEvictor(this.timeBetweenEvictionRunsMillis);
     }
 
     //--- public methods ---------------------------------------------
@@ -244,21 +256,27 @@ public class GenericKeyedObjectPool<K,V>
      * A negative value indicates no limit.
      *
      * @return the cap on the number of active instances per key.
-     * @see #setMaxActive
+     * @see #setMaxTotalPerKey
+     * @since 2.0
      */
-    public synchronized int getMaxActive() {
-        return this.config.getMaxActive();
+    public synchronized int getMaxTotalPerKey() {
+        return this.maxTotalPerKey;
     }
 
     /**
-     * Sets the cap on the number of object instances managed by the pool per key.
-     * @param maxActive The cap on the number of object instances per key.
-     * Use a negative value for no limit.
+     * Sets the cap on the total number of instances from all pools combined.
+     * When <code>maxTotal</code> is set to a
+     * positive value and {@link #borrowObject borrowObject} is invoked
+     * when at the limit with no idle instances available, an attempt is made to
+     * create room by clearing the oldest 15% of the elements from the keyed
+     * pools.
      *
-     * @see #getMaxActive
+     * @param maxTotal The cap on the total number of instances across pools.
+     * Use a negative value for no limit.
+     * @see #getMaxTotal
      */
-    public synchronized void setMaxActive(int maxActive) {
-        this.config.setMaxActive(maxActive);
+    public synchronized void setMaxTotalPerKey(int maxTotalPerKey) {
+        this.maxTotalPerKey = maxTotalPerKey;
         allocate();
     }
 
@@ -269,7 +287,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #setMaxTotal
      */
     public synchronized int getMaxTotal() {
-        return this.config.getMaxTotal();
+        return this.maxTotal;
     }
 
     /**
@@ -285,7 +303,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #getMaxTotal
      */
     public synchronized void setMaxTotal(int maxTotal) {
-        this.config.setMaxTotal(maxTotal);
+        this.maxTotal = maxTotal;
         allocate();
     }
 
@@ -299,7 +317,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #setWhenExhaustedAction
      */
     public synchronized WhenExhaustedAction getWhenExhaustedAction() {
-        return this.config.getWhenExhaustedAction();
+        return this.whenExhaustedAction;
     }
 
     /**
@@ -311,7 +329,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #getWhenExhaustedAction
      */
     public synchronized void setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
-        this.config.setWhenExhaustedAction(whenExhaustedAction);
+        this.whenExhaustedAction = whenExhaustedAction;
         allocate();
     }
 
@@ -332,7 +350,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see WhenExhaustedAction#BLOCK
      */
     public synchronized long getMaxWait() {
-        return this.config.getMaxWait();
+        return this.maxWait;
     }
 
     /**
@@ -351,7 +369,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see WhenExhaustedAction#BLOCK
      */
     public synchronized void setMaxWait(long maxWait) {
-        this.config.setMaxWait(maxWait);
+        this.maxWait = maxWait;
     }
 
     /**
@@ -359,9 +377,11 @@ public class GenericKeyedObjectPool<K,V>
      * @return the maximum number of "idle" instances that can be held
      * in a given keyed pool.
      * @see #setMaxIdle
+     *
+     * @since 2.0
      */
-    public synchronized int getMaxIdle() {
-        return this.config.getMaxIdle();
+    public synchronized int getMaxIdlePerKey() {
+        return this.maxIdlePerKey;
     }
 
     /**
@@ -373,13 +393,15 @@ public class GenericKeyedObjectPool<K,V>
      * number of idle objects to rise above maxIdle. The best value for maxIdle
      * for heavily loaded system will vary but the default is a good starting
      * point.
-     * @param maxIdle the maximum number of "idle" instances that can be held
+     * @param maxIdlePerKey the maximum number of "idle" instances that can be held
      * in a given keyed pool. Use a negative value for no limit.
      * @see #getMaxIdle
-     * @see #DEFAULT_MAX_IDLE
+     * @see #DEFAULT_MAX_IDLE_PER_KEY
+     *
+     * @since 2.0
      */
-    public synchronized void setMaxIdle(int maxIdle) {
-        this.config.setMaxIdle(maxIdle);
+    public synchronized void setMaxIdlePerKey(int maxIdlePerKey) {
+        this.maxIdlePerKey = maxIdlePerKey;
         allocate();
     }
 
@@ -389,13 +411,15 @@ public class GenericKeyedObjectPool<K,V>
      * <code>timeBetweenEvictionRunsMillis > 0</code> and attempts to ensure
      * that each pool has the required minimum number of instances are only
      * made during idle object eviction runs.
-     * @param poolSize - The minimum size of the each keyed pool
+     * @param minIdlePerKey - The minimum size of the each keyed pool
      * @since Pool 1.3
      * @see #getMinIdle
      * @see #setTimeBetweenEvictionRunsMillis
+     *
+     * @since 2.0
      */
-    public void setMinIdle(int poolSize) {
-        this.config.setMinIdle(poolSize);
+    public synchronized void setMinIdle(int minIdlePerKey) {
+        this.minIdlePerKey = minIdlePerKey;
     }
 
     /**
@@ -407,9 +431,11 @@ public class GenericKeyedObjectPool<K,V>
      * @return minimum size of the each keyed pool
      * @since Pool 1.3
      * @see #setTimeBetweenEvictionRunsMillis
+     *
+     * @since 2.0
      */
-    public int getMinIdle() {
-        return this.config.getMinIdle();
+    public synchronized int getMinIdlePerKey() {
+        return this.minIdlePerKey;
     }
 
     /**
@@ -423,8 +449,8 @@ public class GenericKeyedObjectPool<K,V>
      * @return <code>true</code> if objects are validated before being borrowed.
      * @see #setTestOnBorrow
      */
-    public boolean getTestOnBorrow() {
-        return this.config.getTestOnBorrow();
+    public synchronized boolean getTestOnBorrow() {
+        return this.testOnBorrow;
     }
 
     /**
@@ -438,8 +464,8 @@ public class GenericKeyedObjectPool<K,V>
      * @param testOnBorrow whether object should be validated before being returned by borrowObject.
      * @see #getTestOnBorrow
      */
-    public void setTestOnBorrow(boolean testOnBorrow) {
-        this.config.setTestOnBorrow(testOnBorrow);
+    public synchronized void setTestOnBorrow(boolean testOnBorrow) {
+        this.testOnBorrow = testOnBorrow;
     }
 
     /**
@@ -451,8 +477,8 @@ public class GenericKeyedObjectPool<K,V>
      * @return <code>true</code> when objects will be validated before being returned.
      * @see #setTestOnReturn
      */
-    public boolean getTestOnReturn() {
-        return this.config.getTestOnReturn();
+    public synchronized boolean getTestOnReturn() {
+        return this.testOnReturn;
     }
 
     /**
@@ -464,8 +490,8 @@ public class GenericKeyedObjectPool<K,V>
      * @param testOnReturn <code>true</code> so objects will be validated before being returned.
      * @see #getTestOnReturn
      */
-    public void setTestOnReturn(boolean testOnReturn) {
-        this.config.setTestOnReturn(testOnReturn);
+    public synchronized void setTestOnReturn(boolean testOnReturn) {
+        this.testOnReturn = testOnReturn;
     }
 
     /**
@@ -478,7 +504,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized long getTimeBetweenEvictionRunsMillis() {
-        return this.config.getTimeBetweenEvictionRunsMillis();
+        return this.timeBetweenEvictionRunsMillis;
     }
 
     /**
@@ -491,8 +517,8 @@ public class GenericKeyedObjectPool<K,V>
      * @see #getTimeBetweenEvictionRunsMillis
      */
     public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
-        this.config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
-        startEvictor(this.config.getTimeBetweenEvictionRunsMillis());
+        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+        startEvictor(this.timeBetweenEvictionRunsMillis);
     }
 
     /**
@@ -504,7 +530,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized int getNumTestsPerEvictionRun() {
-        return this.config.getNumTestsPerEvictionRun();
+        return this.numTestsPerEvictionRun;
     }
 
     /**
@@ -523,7 +549,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
-        this.config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
+        this.numTestsPerEvictionRun = numTestsPerEvictionRun;
     }
 
     /**
@@ -536,7 +562,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized long getMinEvictableIdleTimeMillis() {
-        return this.config.getMinEvictableIdleTimeMillis();
+        return this.minEvictableIdleTimeMillis;
     }
 
     /**
@@ -552,7 +578,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
-        this.config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
+        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
     }
 
     /**
@@ -566,7 +592,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized boolean getTestWhileIdle() {
-        return this.config.getTestWhileIdle();
+        return this.testWhileIdle;
     }
 
     /**
@@ -580,16 +606,7 @@ public class GenericKeyedObjectPool<K,V>
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized void setTestWhileIdle(boolean testWhileIdle) {
-        this.config.setTestWhileIdle(testWhileIdle);
-    }
-
-    /**
-     * Sets the configuration.
-     * @param conf the new configuration to use.
-     * @see GenericKeyedObjectPoolConfig
-     */
-    public synchronized void setConfig(GenericKeyedObjectPoolConfig conf) {
-        this.config = conf;
+        this.testWhileIdle = testWhileIdle;
     }
 
     /**
@@ -603,7 +620,7 @@ public class GenericKeyedObjectPool<K,V>
      * @since 1.4
      */
      public synchronized boolean getLifo() {
-         return this.config.getLifo();
+         return this.lifo;
      }
 
      /**
@@ -617,7 +634,7 @@ public class GenericKeyedObjectPool<K,V>
       * @since 1.4
       */
      public synchronized void setLifo(boolean lifo) {
-         this.config.setLifo(lifo);
+         this.lifo = lifo;
      }
 
     //-- ObjectPool methods ------------------------------------------
@@ -663,8 +680,8 @@ public class GenericKeyedObjectPool<K,V>
             // Get local copy of current config. Can't sync when used later as
             // it can result in a deadlock. Has the added advantage that config
             // is consistent for entire method execution
-            whenExhaustedAction = this.config.getWhenExhaustedAction();
-            maxWait = this.config.getMaxWait();
+            whenExhaustedAction = this.whenExhaustedAction;
+            maxWait = this.maxWait;
 
             // Add this request to the queue
             _allocationQueue.add(latch);
@@ -784,7 +801,7 @@ public class GenericKeyedObjectPool<K,V>
             // activate & validate the object
             try {
                 _factory.activateObject(key, latch.getPair().getValue());
-                if (this.config.getTestOnBorrow() && !_factory.validateObject(key, latch.getPair().getValue())) {
+                if (this.testOnBorrow && !_factory.validateObject(key, latch.getPair().getValue())) {
                     throw new Exception("ValidateObject failed");
                 }
                 synchronized (this) {
@@ -858,15 +875,15 @@ public class GenericKeyedObjectPool<K,V>
 
                 // If there is a totalMaxActive and we are at the limit then
                 // we have to make room
-                if ((this.config.getMaxTotal() > 0) &&
-                        (_totalActive + _totalIdle + _totalInternalProcessing >= this.config.getMaxTotal())) {
+                if ((this.maxTotal > 0) &&
+                        (_totalActive + _totalIdle + _totalInternalProcessing >= this.maxTotal)) {
                     clearOldest = true;
                     break;
                 }
 
                 // Second utilise any spare capacity to create new objects
-                if ((this.config.getMaxActive() < 0 || pool.activeCount + pool.internalProcessingCount < this.config.getMaxActive()) &&
-                        (this.config.getMaxTotal() < 0 || _totalActive + _totalIdle + _totalInternalProcessing < this.config.getMaxTotal())) {
+                if ((this.maxTotalPerKey < 0 || pool.activeCount + pool.internalProcessingCount < this.maxTotalPerKey) &&
+                        (this.maxTotal < 0 || _totalActive + _totalIdle + _totalInternalProcessing < this.maxTotal)) {
                     // allow new object to be created
                     allocationQueueIter.remove();
                     latch.setMayCreate(true);
@@ -881,7 +898,7 @@ public class GenericKeyedObjectPool<K,V>
                 // If there is no per-key limit and we reach this point we
                 // must have allocated all the objects we possibly can and there
                 // is no point looking at the rest of the allocation queue
-                if (this.config.getMaxActive() < 0) {
+                if (this.maxTotalPerKey < 0) {
                     break;
                 }
             }
@@ -1158,7 +1175,7 @@ public class GenericKeyedObjectPool<K,V>
 
         // if we need to validate this object, do so
         boolean success = true; // whether or not this object passed validation
-        if (this.config.getTestOnReturn() && !_factory.validateObject(key, obj)) {
+        if (this.testOnReturn && !_factory.validateObject(key, obj)) {
             success = false;
         } else {
             _factory.passivateObject(key, obj);
@@ -1183,12 +1200,12 @@ public class GenericKeyedObjectPool<K,V>
             } else {
                 // if there's no space in the pool, flag the object for destruction
                 // else if we passivated successfully, return it to the pool
-                if (this.config.getMaxIdle() >= 0 && (pool.queue.size() >= this.config.getMaxIdle())) {
+                if (this.maxIdlePerKey >= 0 && (pool.queue.size() >= this.maxIdlePerKey)) {
                     shouldDestroy = true;
                 } else if (success) {
                     // borrowObject always takes the first element from the queue,
                     // so for LIFO, push on top, FIFO add to end
-                    if (this.config.getLifo()) {
+                    if (this.lifo) {
                         pool.queue.addFirst(new ObjectTimestampPair<V>(obj));
                     } else {
                         pool.queue.addLast(new ObjectTimestampPair<V>(obj));
@@ -1353,8 +1370,8 @@ public class GenericKeyedObjectPool<K,V>
             // Get local copy of current config. Can't sync when used later as
             // it can result in a deadlock. Has the added advantage that config
             // is consistent for entire method execution
-            testWhileIdle = this.config.getTestWhileIdle();
-            minEvictableIdleTimeMillis = this.config.getMinEvictableIdleTimeMillis();
+            testWhileIdle = this.testWhileIdle;
+            minEvictableIdleTimeMillis = this.minEvictableIdleTimeMillis;
 
             // Initialize key to last key value
             if (_evictionKeyCursor != null &&
@@ -1401,8 +1418,8 @@ public class GenericKeyedObjectPool<K,V>
 
                 // If eviction cursor is exhausted, try to move
                 // to the next key and reset
-                if ((this.config.getLifo() && !_evictionCursor.hasPrevious()) ||
-                        (!this.config.getLifo() && !_evictionCursor.hasNext())) {
+                if ((this.lifo && !_evictionCursor.hasPrevious()) ||
+                        (!this.lifo && !_evictionCursor.hasNext())) {
                     if (_evictionKeyCursor != null) {
                         if (_evictionKeyCursor.hasNext()) {
                             key = _evictionKeyCursor.next();
@@ -1419,14 +1436,14 @@ public class GenericKeyedObjectPool<K,V>
                     }
                 }
 
-                if ((this.config.getLifo() && !_evictionCursor.hasPrevious()) ||
-                        (!this.config.getLifo() && !_evictionCursor.hasNext())) {
+                if ((this.lifo && !_evictionCursor.hasPrevious()) ||
+                        (!this.lifo && !_evictionCursor.hasNext())) {
                     continue; // reset failed, do nothing
                 }
 
                 // if LIFO and the _evictionCursor has a previous object,
                 // or FIFO and _evictionCursor has a next object, test it
-                pair = this.config.getLifo() ?
+                pair = this.lifo ?
                         _evictionCursor.previous() :
                         _evictionCursor.next();
                 _evictionCursor.remove();
@@ -1473,7 +1490,7 @@ public class GenericKeyedObjectPool<K,V>
                     //
                     // Otherwise if it was the last object for that key,
                     // drop that pool
-                    if (this.config.getMinIdle() == 0) {
+                    if (this.minIdlePerKey == 0) {
                         synchronized (this) {
                             ObjectQueue objectQueue =
                                 _poolMap.get(key);
@@ -1490,7 +1507,7 @@ public class GenericKeyedObjectPool<K,V>
                 if (!removeObject) {
                     _evictionCursor.add(pair);
                     _totalIdle++;
-                    if (this.config.getLifo()) {
+                    if (this.lifo) {
                         // Skip over the element we just added back
                         _evictionCursor.previous();
                     }
@@ -1530,7 +1547,7 @@ public class GenericKeyedObjectPool<K,V>
         ObjectQueue pool = _poolMap.get(key);
         if (pool != null) {
             CursorableLinkedList<ObjectTimestampPair<V>> queue = pool.queue;
-            _evictionCursor = queue.cursor(this.config.getLifo() ? queue.size() : 0);
+            _evictionCursor = queue.cursor(this.lifo ? queue.size() : 0);
         }
     }
 
@@ -1544,7 +1561,7 @@ public class GenericKeyedObjectPool<K,V>
     @SuppressWarnings("unchecked") // OK, see (1)
     private void ensureMinIdle() throws Exception {
         //Check if should sustain the pool
-        if (this.config.getMinIdle() > 0) {
+        if (this.minIdlePerKey > 0) {
             K[] keysCopy;
             synchronized(this) {
                 // Get the current set of keys
@@ -1646,10 +1663,10 @@ public class GenericKeyedObjectPool<K,V>
      * @return the number of tests for the Evictor to run
      */
     private synchronized int getNumTests() {
-        if (this.config.getNumTestsPerEvictionRun() >= 0) {
-            return Math.min(this.config.getNumTestsPerEvictionRun(), _totalIdle);
+        if (this.numTestsPerEvictionRun >= 0) {
+            return Math.min(this.numTestsPerEvictionRun, _totalIdle);
         } else {
-            return(int)(Math.ceil(_totalIdle/Math.abs((double)this.config.getNumTestsPerEvictionRun())));
+            return(int)(Math.ceil(_totalIdle/Math.abs((double)this.numTestsPerEvictionRun)));
         }
     }
 
@@ -1670,15 +1687,15 @@ public class GenericKeyedObjectPool<K,V>
 
         //Calculate no of objects needed to be created, in order to have
         //the number of pooled objects < maxActive();
-        objectDefecit = getMinIdle() - pool.queue.size();
-        if (getMaxActive() > 0) {
-            int growLimit = Math.max(0, getMaxActive() - pool.activeCount - pool.queue.size() - pool.internalProcessingCount);
+        objectDefecit = this.minIdlePerKey - pool.queue.size();
+        if (this.maxTotalPerKey > 0) {
+            int growLimit = Math.max(0, this.maxTotalPerKey - pool.activeCount - pool.queue.size() - pool.internalProcessingCount);
             objectDefecit = Math.min(objectDefecit, growLimit);
         }
 
         // Take the maxTotal limit into account
-        if (getMaxTotal() > 0) {
-            int growLimit = Math.max(0, getMaxTotal() - getNumActive() - getNumIdle() - _totalInternalProcessing);
+        if (this.maxTotal > 0) {
+            int growLimit = Math.max(0, this.maxTotal - getNumActive() - getNumIdle() - _totalInternalProcessing);
             objectDefecit = Math.min(objectDefecit, growLimit);
         }
 
@@ -1949,8 +1966,137 @@ public class GenericKeyedObjectPool<K,V>
 
     //--- protected attributes ---------------------------------------
 
-    /** Pool configuration */
-    private GenericKeyedObjectPoolConfig config;
+    /* Pool configuration */
+
+    /**
+     * The cap on the number of idle instances in the pool.
+     */
+    private int maxIdlePerKey; // @GuardedBy("this")
+
+    /**
+     * The cap on the minimum number of idle instances in the pool.
+     *
+     * @see #setMinIdle
+     */
+    private int minIdlePerKey; // @GuardedBy("this")
+
+    /**
+     * The cap on the total number of active instances from the pool per key.
+     *
+     * @see #setMaxTotal(int)
+     */
+    private int maxTotalPerKey; // @GuardedBy("this")
+
+    /**
+     * The cap on the total number of active instances from the pool.
+     *
+     * @see #setMaxTotal(int)
+     */
+    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")
 
     /** My hash of pools (ObjectQueue). */
     private final Map<K,ObjectQueue> _poolMap;

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java?rev=1051389&r1=1051388&r2=1051389&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java Tue Dec 21 06:51:17 2010
@@ -22,31 +22,494 @@ package org.apache.commons.pool2.impl;
  * @since Pool 2.0
  * @version $Revision$ $Date$
  */
-public class GenericKeyedObjectPoolConfig extends GenericObjectPoolConfig {
+public class GenericKeyedObjectPoolConfig {
 
     /**
-     * The default cap on the the overall maximum number of objects that can
-     * exist at one time.
+     * The cap on the number of idle instances in the pool.
+     */
+    private final int maxIdlePerKey;
+
+    /**
+     * The cap on the minimum number of idle instances in the pool.
+     */
+    private final int minIdlePerKey;
+
+    /**
+     * The cap on the total number of active instances from the pool per key.
+     */
+    private final int maxTotalPerKey;
+
+    /**
+     * The cap on the total number of active instances from the pool.
+     */
+    private final int maxTotal;
+
+    /**
+     * 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}.
      *
-     * @see #getMaxTotal
-     * @see #setMaxTotal
+     * When less than or equal to 0, the {@link org.apache.commons.pool2.ObjectPool#borrowObject} method
+     * may block indefinitely.
+     */
+    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).
+     */
+    private final WhenExhaustedAction whenExhaustedAction;
+
+    /**
+     * 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.
+     */
+    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}.
+     */
+    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.
+     */
+    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.
+     */
+    private final long timeBetweenEvictionRunsMillis;
+
+    /**
+     * 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.
+     */
+    private final int numTestsPerEvictionRun;
+
+    /**
+     * 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.
      */
-    public static final int DEFAULT_MAX_TOTAL  = -1;
+    private final long minEvictableIdleTimeMillis;
 
     /**
-     * The cap on the total number of instances from the pool if non-positive.
+     * Whether or not the pool behaves as a LIFO queue (last in first out).
+     */
+    private final boolean lifo;
+
+    /**
+     * TODO please fill me
      *
-     * @see #getMaxTotal
-     * @see #setMaxTotal
+     * @param maxIdlePerKey
+     * @param minIdlePerKey
+     * @param maxTotalPerKey
+     * @param maxWait
+     * @param whenExhaustedAction
+     * @param testOnBorrow
+     * @param testOnReturn
+     * @param testWhileIdle
+     * @param timeBetweenEvictionRunsMillis
+     * @param numTestsPerEvictionRun
+     * @param minEvictableIdleTimeMillis
+     * @param lifo
      */
-    private int maxTotal = DEFAULT_MAX_TOTAL;
+    private GenericKeyedObjectPoolConfig(final int maxIdlePerKey,
+            final int minIdlePerKey,
+            final int maxTotalPerKey,
+            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) {
+        this.maxIdlePerKey = maxIdlePerKey;
+        this.minIdlePerKey = minIdlePerKey;
+        this.maxTotalPerKey = maxTotalPerKey;
+        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;
+    }
+
+    public int getMaxIdlePerKey() {
+        return maxIdlePerKey;
+    }
+
+    public int getMinIdlePerKey() {
+        return minIdlePerKey;
+    }
+
+    public int getMaxTotalPerKey() {
+        return maxTotalPerKey;
+    }
 
     public int getMaxTotal() {
         return maxTotal;
     }
 
-    public void setMaxTotal(int maxTotal) {
-        this.maxTotal = maxTotal;
+    public long getMaxWait() {
+        return maxWait;
+    }
+
+    public WhenExhaustedAction getWhenExhaustedAction() {
+        return whenExhaustedAction;
+    }
+
+    public boolean getTestOnBorrow() {
+        return testOnBorrow;
+    }
+
+    public boolean getTestOnReturn() {
+        return testOnReturn;
+    }
+
+    public boolean getTestWhileIdle() {
+        return testWhileIdle;
+    }
+
+    public long getTimeBetweenEvictionRunsMillis() {
+        return timeBetweenEvictionRunsMillis;
+    }
+
+    public int getNumTestsPerEvictionRun() {
+        return numTestsPerEvictionRun;
+    }
+
+    public long getMinEvictableIdleTimeMillis() {
+        return minEvictableIdleTimeMillis;
+    }
+
+    public boolean getLifo() {
+        return lifo;
+    }
+
+    public static final class Builder {
+
+        /**
+         * The default cap on the number of "sleeping" instances in the pool.
+         */
+        public static final int DEFAULT_MAX_IDLE_PER_KEY = 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_PER_KEY = 0;
+
+        /**
+         * The default cap on the total number of active instances from the pool per key.
+         */
+        public static final int DEFAULT_MAX_TOTAL_PER_KEY = 8;
+
+        /**
+         * The default cap on the total number of active instances from the pool.
+         */
+        public static final int DEFAULT_MAX_TOTAL = -1;
+
+        /**
+         * 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 cap on the number of idle instances in the pool.
+         */
+        private int maxIdlePerKey = DEFAULT_MAX_IDLE_PER_KEY;
+
+        /**
+         * The cap on the minimum number of idle instances in the pool.
+         *
+         * @see #setMinIdle
+         */
+        private int minIdlePerKey = DEFAULT_MIN_IDLE_PER_KEY;
+
+        /**
+         * The cap on the total number of active instances from the pool per key.
+         *
+         * @see #setMaxTotalPerKey(int)
+         */
+        private int maxTotalPerKey = DEFAULT_MAX_TOTAL_PER_KEY;
+
+        /**
+         * The cap on the total number of active instances from the pool per key.
+         *
+         * @see #setMaxTotal(int)
+         */
+        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;
+
+        public Builder setMaxIdlePerKey(int maxIdlePerKey) {
+            this.maxIdlePerKey = maxIdlePerKey;
+            return this;
+        }
+
+        public Builder setMinIdlePerKey(int minIdlePerKey) {
+            this.minIdlePerKey = minIdlePerKey;
+            return this;
+        }
+
+        public Builder setMaxTotalPerKey(int maxTotalPerKey) {
+            this.maxTotalPerKey = maxTotalPerKey;
+            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;
+        }
+
+        /**
+         * Creates a {@link GenericObjectPoolConfig} instance.
+         *
+         * @return the created {@link GenericObjectPoolConfig} instance.
+         */
+        public GenericKeyedObjectPoolConfig createConfig() {
+            return new GenericKeyedObjectPoolConfig(maxIdlePerKey,
+                    minIdlePerKey,
+                    maxTotalPerKey,
+                    maxTotal,
+                    maxWait,
+                    whenExhaustedAction,
+                    testOnBorrow,
+                    testOnReturn,
+                    testWhileIdle,
+                    timeBetweenEvictionRunsMillis,
+                    numTestsPerEvictionRun,
+                    minEvictableIdleTimeMillis,
+                    lifo);
+        }
+
     }
 
 }

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java?rev=1051389&r1=1051388&r2=1051389&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java Tue Dec 21 06:51:17 2010
@@ -40,7 +40,7 @@ public class GenericKeyedObjectPoolFacto
      * @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory)
      */
     public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory) {
-        this(factory,new GenericKeyedObjectPoolConfig());
+        this(factory,new GenericKeyedObjectPoolConfig.Builder().createConfig());
     }
 
     /**
@@ -59,7 +59,19 @@ public class GenericKeyedObjectPoolFacto
             throw new IllegalArgumentException("config must not be null");
         }
         _factory = factory;
-        this.config = config;
+        this.maxIdlePerKey = config.getMaxIdlePerKey();
+        this.minIdlePerKey = config.getMinIdlePerKey();
+        this.maxTotalPerKey = config.getMaxTotalPerKey();
+        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();
     }
 
     /**
@@ -69,128 +81,385 @@ public class GenericKeyedObjectPoolFacto
      * current property settings
      */
     public KeyedObjectPool<K,V> createPool() {
-        return new GenericKeyedObjectPool<K,V>(_factory,this.config);
+        return new GenericKeyedObjectPool<K,V>(_factory,new GenericKeyedObjectPoolConfig.Builder()
+                .setMaxIdlePerKey(maxIdlePerKey)
+                .setMinIdlePerKey(minIdlePerKey)
+                .setMaxTotalPerKey(maxTotalPerKey)
+                .setMaxTotal(maxTotal)
+                .setMaxWait(maxWait)
+                .setWhenExhaustedAction(whenExhaustedAction)
+                .setTestOnBorrow(testOnBorrow)
+                .setTestOnReturn(testOnReturn)
+                .setTestWhileIdle(testWhileIdle)
+                .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis)
+                .setNumTestsPerEvictionRun(numTestsPerEvictionRun)
+                .setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis)
+                .setLifo(lifo)
+                .createConfig());
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getMaxIdle() maxIdle} setting for pools created by this factory.
-     * @since 1.5.5
+     * @return the {@link GenericKeyedObjectPoolConfig#getMaxIdle() maxIdle} setting for pools created by this factory.
+     * @since 2.0
      */
-    public int getMaxIdle() {
-        return this.config.getMaxIdle();
+    public synchronized int getMaxIdlePerKey() {
+        return this.maxIdlePerKey;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getMaxActive() maxActive} setting for pools created by this factory.
-     * @since 1.5.5
+     * @param maxIdle the {@link GenericKeyedObjectPoolConfig#getMaxIdle() maxIdle} setting for pools created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setMaxIdlePerKey(int maxIdlePerKey) {
+        this.maxIdlePerKey = maxIdlePerKey;
+    }
+
+    /**
+     * @return the {@link GenericKeyedObjectPoolConfig#getMinIdle() minIdle} setting for pools created by this factory.
+     * @since 2.0
      */
-    public int getMaxActive() {
-        return this.config.getMaxActive();
+    public synchronized int getMinIdlePerKey() {
+        return this.minIdlePerKey;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getMaxTotal() maxTotal} setting for pools created by this factory.
+     * @param minIdle the {@link GenericKeyedObjectPoolConfig#getMinIdle() minIdle} setting for pools created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setMinIdlePerKey(int minIdlePerKey) {
+        this.minIdlePerKey = minIdlePerKey;
+    }
+
+    /**
+     * @return the {@link GenericKeyedObjectPoolConfig#getMaxTotalPerKey()} setting for pools created by this factory.
+     * @since 2.0
+     */
+    public synchronized int getMaxTotalPerKey() {
+        return this.maxTotalPerKey;
+    }
+
+    /**
+     * @param maxActive the {@link GenericKeyedObjectPoolConfig#getMaxTotalPerKey()} setting for pools created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setMaxTotalPerKey(int maxTotalPerKey) {
+        this.maxTotalPerKey = maxTotalPerKey;
+    }
+
+    /**
+     * @return the {@link GenericKeyedObjectPoolConfig#getMaxTotal() maxTotal} setting for pools created by this factory.
      * @since 1.5.5
      */
-    public int getMaxTotal() {
-        return this.config.getMaxTotal();
+    public synchronized int getMaxTotal() {
+        return this.maxTotal;
+    }
+
+    /**
+     * @param maxActive the {@link GenericKeyedObjectPoolConfig#getMaxTotal() maxTotal} setting for pools created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setMaxTotal(int maxTotal) {
+        this.maxTotal = maxTotal;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getMinIdle() minIdle} setting for pools created by this factory.
+     * @return the {@link GenericKeyedObjectPoolConfig#getMaxWait() maxWait} setting for pools created by this factory.
      * @since 1.5.5
      */
-    public int getMinIdle() {
-        return this.config.getMinIdle();
+    public synchronized long getMaxWait() {
+        return this.maxWait;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getMaxWait() maxWait} setting for pools created by this factory.
+     * @param maxWait the {@link GenericKeyedObjectPoolConfig#getMaxWait() maxWait} setting for pools created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setMaxWait(long maxWait) {
+        this.maxWait = maxWait;
+    }
+
+    /**
+     * @return the {@link GenericKeyedObjectPoolConfig#getWhenExhaustedAction() whenExhaustedAction} setting for pools
+     * created by this factory.
      * @since 1.5.5
      */
-    public long getMaxWait() {
-        return this.config.getMaxWait();
+    public synchronized WhenExhaustedAction getWhenExhaustedAction() {
+        return this.whenExhaustedAction;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getWhenExhaustedAction() whenExhaustedAction} setting for pools created by this factory.
+     * @param whenExhaustedAction the {@link GenericKeyedObjectPoolConfig#getWhenExhaustedAction() whenExhaustedAction} setting for pools
+     * created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
+        this.whenExhaustedAction = whenExhaustedAction;
+    }
+
+    /**
+     * @return the {@link GenericKeyedObjectPoolConfig#getTestOnBorrow() testOnBorrow} setting for pools
+     * created by this factory.
      * @since 1.5.5
      */
-    public WhenExhaustedAction getWhenExhaustedAction() {
-        return this.config.getWhenExhaustedAction();
+    public synchronized boolean getTestOnBorrow() {
+        return this.testOnBorrow;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getTestOnBorrow() testOnBorrow} setting for pools created by this factory.
+     * @param testOnBorrow the {@link GenericKeyedObjectPoolConfig#getTestOnBorrow() testOnBorrow} setting for pools
+     * created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setTestOnBorrow(boolean testOnBorrow) {
+        this.testOnBorrow = testOnBorrow;
+    }
+
+    /**
+     * @return the {@link GenericKeyedObjectPoolConfig#getTestOnReturn() testOnReturn} setting for pools
+     * created by this factory.
      * @since 1.5.5
      */
-    public boolean getTestOnBorrow() {
-        return this.config.getTestOnBorrow();
+    public synchronized boolean getTestOnReturn() {
+        return this.testOnReturn;
+    }
+
+    /**
+     * @param testOnReturn the {@link GenericKeyedObjectPoolConfig#getTestOnReturn() testOnReturn} setting for pools
+     * created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setTestOnReturn(boolean testOnReturn) {
+        this.testOnReturn = testOnReturn;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getTestOnReturn() testOnReturn} setting for pools created by this factory.
+     * @return the {@link GenericKeyedObjectPoolConfig#getTestWhileIdle() testWhileIdle} setting for pools
+     * created by this factory.
      * @since 1.5.5
      */
-    public boolean getTestOnReturn() {
-        return this.config.getTestOnReturn();
+    public synchronized boolean getTestWhileIdle() {
+        return this.testWhileIdle;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getTestWhileIdle() testWhileIdle} setting for pools created by this factory.
+     * @param testWhileIdle the {@link GenericKeyedObjectPoolConfig#getTestWhileIdle() testWhileIdle} setting for pools
+     * created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setTestWhileIdle(boolean testWhileIdle) {
+        this.testWhileIdle = testWhileIdle;
+    }
+
+    /**
+     * @return the {@link GenericKeyedObjectPoolConfig#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis}
+     * setting for pools created by this factory.
      * @since 1.5.5
      */
-    public boolean getTestWhileIdle() {
-        return this.config.getTestWhileIdle();
+    public synchronized long getTimeBetweenEvictionRunsMillis() {
+        return this.timeBetweenEvictionRunsMillis;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis}
+     * @param timeBetweenEvictionRunsMillis the {@link GenericKeyedObjectPoolConfig#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis}
+     * setting for pools created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
+        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+    }
+
+    /**
+     * @return the {@link GenericKeyedObjectPoolConfig#getNumTestsPerEvictionRun() numTestsPerEvictionRun}
      * setting for pools created by this factory.
      * @since 1.5.5
      */
-    public long getTimeBetweenEvictionRunsMillis() {
-        return this.config.getTimeBetweenEvictionRunsMillis();
+    public synchronized int getNumTestsPerEvictionRun() {
+        return this.numTestsPerEvictionRun;
+    }
+
+    /**
+     * @param numTestsPerEvictionRun the {@link GenericKeyedObjectPoolConfig#getNumTestsPerEvictionRun() numTestsPerEvictionRun}
+     * setting for pools created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
+        this.numTestsPerEvictionRun = numTestsPerEvictionRun;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getNumTestsPerEvictionRun() numTestsPerEvictionRun}
+     * @return the {@link GenericKeyedObjectPoolConfig#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis}
      * setting for pools created by this factory.
      * @since 1.5.5
      */
-    public int getNumTestsPerEvictionRun() {
-        return this.config.getNumTestsPerEvictionRun();
+    public synchronized long getMinEvictableIdleTimeMillis() {
+        return this.minEvictableIdleTimeMillis;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis}
+     * @param minEvictableIdleTimeMillis the {@link GenericKeyedObjectPoolConfig#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis}
      * setting for pools created by this factory.
+     * @since 2.0
+     */
+    public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
+        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+    }
+
+    /**
+     * @return the {@link GenericKeyedObjectPoolConfig#getLifo() lifo} setting for pools created by this factory.
      * @since 1.5.5
      */
-    public long getMinEvictableIdleTimeMillis() {
-        return this.config.getMinEvictableIdleTimeMillis();
+    public synchronized boolean getLifo() {
+        return this.lifo;
     }
 
     /**
-     * @return the {@link KeyedPoolableObjectFactory} used by pools created by this factory.
+     * @param lifo the {@link GenericKeyedObjectPoolConfig#getLifo() lifo} setting for pools created by this factory.
      * @since 1.5.5
      */
-    public KeyedPoolableObjectFactory<K,V> getFactory() {
-        return _factory;
+    public synchronized void setLifo(boolean lifo) {
+        this.lifo = lifo;
     }
 
     /**
-     * @return the {@link GenericKeyedObjectPool#getLifo() lifo} setting for pools created by this factory.
+     * @return the {@link KeyedPoolableObjectFactory} used by pools created by this factory.
      * @since 1.5.5
      */
-    public boolean getLifo() {
-        return this.config.getLifo();
+    public KeyedPoolableObjectFactory<K,V> getFactory() {
+        return _factory;
     }
 
     //--- private attributes
 
     private final KeyedPoolableObjectFactory<K,V> _factory;
 
-    private final GenericKeyedObjectPoolConfig config;
+    /**
+     * The cap on the number of idle instances in the pool.
+     */
+    private int maxIdlePerKey; // @GuardedBy("this")
+
+    /**
+     * The cap on the minimum number of idle instances in the pool.
+     *
+     * @see #setMinIdle
+     */
+    private int minIdlePerKey; // @GuardedBy("this")
+
+    /**
+     * The cap on the total number of active instances from the pool per key.
+     *
+     * @see #setMaxActive
+     */
+    private int maxTotalPerKey; // @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")
 
 }

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=1051389&r1=1051388&r2=1051389&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 Tue Dec 21 06:51:17 2010
@@ -44,7 +44,7 @@ import org.apache.commons.pool2.impl.Gen
  *    objects that can be allocated by the pool (checked out to clients, or
  *    idle awaiting checkout) at a given time.  When non-positive, there is no
  *    limit to the number of objects that can be managed by the pool at one time.
- *    When {@link #setMaxActive <i>maxActive</i>} is reached, the pool is said
+ *    When {@link # <i>maxActive</i>} is reached, the pool is said
  *    to be exhausted. The default setting for this parameter is 8.
  *  </li>
  *  <li>
@@ -65,7 +65,7 @@ import org.apache.commons.pool2.impl.Gen
  *    <li>
  *      When {@link #setWhenExhaustedAction <i>whenExhaustedAction</i>} is
  *      {@link WhenExhaustedAction#GROW}, {@link #borrowObject} will create a new
- *      object and return it (essentially making {@link #setMaxActive <i>maxActive</i>}
+ *      object and return it (essentially making {@link #expected <i>maxActive</i>}
  *      meaningless.)
  *    </li>
  *    <li>
@@ -194,7 +194,7 @@ public class GenericObjectPool<T> extend
      * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
      */
     public GenericObjectPool(PoolableObjectFactory<T> factory) {
-        this(factory, new GenericObjectPoolConfig());
+        this(factory, new GenericObjectPoolConfig.Builder().createConfig());
     }
 
     /**
@@ -210,7 +210,19 @@ public class GenericObjectPool<T> extend
             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();
 
         _pool = new CursorableLinkedList<ObjectTimestampPair<T>>();
         startEvictor(config.getTimeBetweenEvictionRunsMillis());
@@ -227,10 +239,11 @@ public class GenericObjectPool<T> extend
      * be managed by the pool at one time.
      *
      * @return the cap on the total number of object instances managed by the pool.
-     * @see #setMaxActive
+     * @see #expected
+     * @since 2.0
      */
-    public synchronized int getMaxActive() {
-        return this.config.getMaxActive();
+    public synchronized int getMaxTotal() {
+        return this.maxTotal;
     }
 
     /**
@@ -238,13 +251,13 @@ public class GenericObjectPool<T> extend
      * (checked out to clients, or idle awaiting checkout) at a given time. Use
      * a negative value for no limit.
      *
-     * @param maxActive The cap on the total number of object instances managed by the pool.
+     * @param maxTotal The cap on the total number of object instances managed by the pool.
      * Negative values mean that there is no limit to the number of objects allocated
      * by the pool.
-     * @see #getMaxActive
+     * @see #getMaxTotal
      */
-    public synchronized void setMaxActive(int maxActive) {
-        this.config.setMaxActive(maxActive);
+    public synchronized void setMaxTotal(int maxTotal) {
+        this.maxTotal = maxTotal;
         allocate();
     }
 
@@ -257,7 +270,7 @@ public class GenericObjectPool<T> extend
      * @see #setWhenExhaustedAction
      */
     public synchronized WhenExhaustedAction getWhenExhaustedAction() {
-        return this.config.getWhenExhaustedAction();
+        return this.whenExhaustedAction;
     }
 
     /**
@@ -271,7 +284,7 @@ public class GenericObjectPool<T> extend
      * @see #getWhenExhaustedAction
      */
     public synchronized void setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
-        this.config.setWhenExhaustedAction(whenExhaustedAction);
+        this.whenExhaustedAction = whenExhaustedAction;
         allocate();
     }
 
@@ -292,7 +305,7 @@ public class GenericObjectPool<T> extend
      * @see WhenExhaustedAction#BLOCK
      */
     public synchronized long getMaxWait() {
-        return this.config.getMaxWait();
+        return this.maxWait;
     }
 
     /**
@@ -311,7 +324,7 @@ public class GenericObjectPool<T> extend
      * @see WhenExhaustedAction#BLOCK
      */
     public synchronized void setMaxWait(long maxWait) {
-        this.config.setMaxWait(maxWait);
+        this.maxWait = maxWait;
         allocate();
     }
 
@@ -321,7 +334,7 @@ public class GenericObjectPool<T> extend
      * @see #setMaxIdle
      */
     public synchronized int getMaxIdle() {
-        return this.config.getMaxIdle();
+        return this.maxIdle;
     }
 
     /**
@@ -338,7 +351,7 @@ public class GenericObjectPool<T> extend
      * @see #getMaxIdle
      */
     public synchronized void setMaxIdle(int maxIdle) {
-        this.config.setMaxIdle(maxIdle);
+        this.maxIdle = maxIdle;
         allocate();
     }
 
@@ -355,7 +368,7 @@ public class GenericObjectPool<T> extend
      * @see #getTimeBetweenEvictionRunsMillis()
      */
     public synchronized void setMinIdle(int minIdle) {
-        this.config.setMinIdle(minIdle);
+        this.minIdle = minIdle;
         allocate();
     }
 
@@ -368,7 +381,7 @@ public class GenericObjectPool<T> extend
      * @see #setMinIdle
      */
     public synchronized int getMinIdle() {
-        return this.config.getMinIdle();
+        return this.minIdle;
     }
 
     /**
@@ -383,7 +396,7 @@ public class GenericObjectPool<T> extend
      * @see #setTestOnBorrow
      */
     public boolean getTestOnBorrow() {
-        return this.config.getTestOnBorrow();
+        return this.testOnBorrow;
     }
 
     /**
@@ -398,7 +411,7 @@ public class GenericObjectPool<T> extend
      * @see #getTestOnBorrow
      */
     public void setTestOnBorrow(boolean testOnBorrow) {
-        this.config.setTestOnBorrow(testOnBorrow);
+        this.testOnBorrow = testOnBorrow;
     }
 
     /**
@@ -411,7 +424,7 @@ public class GenericObjectPool<T> extend
      * @see #setTestOnReturn
      */
     public boolean getTestOnReturn() {
-        return this.config.getTestOnReturn();
+        return this.testOnReturn;
     }
 
     /**
@@ -424,7 +437,7 @@ public class GenericObjectPool<T> extend
      * @see #getTestOnReturn
      */
     public void setTestOnReturn(boolean testOnReturn) {
-        this.config.setTestOnReturn(testOnReturn);
+        this.testOnReturn = testOnReturn;
     }
 
     /**
@@ -437,7 +450,7 @@ public class GenericObjectPool<T> extend
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized long getTimeBetweenEvictionRunsMillis() {
-        return this.config.getTimeBetweenEvictionRunsMillis();
+        return this.timeBetweenEvictionRunsMillis;
     }
 
     /**
@@ -450,8 +463,8 @@ public class GenericObjectPool<T> extend
      * @see #getTimeBetweenEvictionRunsMillis
      */
     public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
-        this.config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
-        startEvictor(this.config.getTimeBetweenEvictionRunsMillis());
+        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+        startEvictor(this.timeBetweenEvictionRunsMillis);
     }
 
     /**
@@ -463,7 +476,7 @@ public class GenericObjectPool<T> extend
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized int getNumTestsPerEvictionRun() {
-        return this.config.getNumTestsPerEvictionRun();
+        return this.numTestsPerEvictionRun;
     }
 
     /**
@@ -481,7 +494,7 @@ public class GenericObjectPool<T> extend
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
-        this.config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
+        this.numTestsPerEvictionRun = numTestsPerEvictionRun;
     }
 
     /**
@@ -494,7 +507,7 @@ public class GenericObjectPool<T> extend
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized long getMinEvictableIdleTimeMillis() {
-        return this.config.getMinEvictableIdleTimeMillis();
+        return this.minEvictableIdleTimeMillis;
     }
 
     /**
@@ -509,7 +522,7 @@ public class GenericObjectPool<T> extend
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
-        this.config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
+        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
     }
 
     /**
@@ -523,7 +536,7 @@ public class GenericObjectPool<T> extend
      * @see #setSoftMinEvictableIdleTimeMillis
      */
     public synchronized long getSoftMinEvictableIdleTimeMillis() {
-        return this.config.getSoftMinEvictableIdleTimeMillis();
+        return this.softMinEvictableIdleTimeMillis;
     }
 
     /**
@@ -540,7 +553,7 @@ public class GenericObjectPool<T> extend
      * @see #getSoftMinEvictableIdleTimeMillis
      */
     public synchronized void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {
-        this.config.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
+        this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
     }
 
     /**
@@ -554,7 +567,7 @@ public class GenericObjectPool<T> extend
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized boolean getTestWhileIdle() {
-        return this.config.getTestWhileIdle();
+        return this.testWhileIdle;
     }
 
     /**
@@ -568,7 +581,7 @@ public class GenericObjectPool<T> extend
      * @see #setTimeBetweenEvictionRunsMillis
      */
     public synchronized void setTestWhileIdle(boolean testWhileIdle) {
-        this.config.setTestWhileIdle(testWhileIdle);
+        this.testWhileIdle = testWhileIdle;
     }
 
     /**
@@ -582,7 +595,7 @@ public class GenericObjectPool<T> extend
      * @since 1.4
      */
      public synchronized boolean getLifo() {
-         return this.config.getLifo();
+         return this.lifo;
      }
 
      /**
@@ -596,20 +609,9 @@ public class GenericObjectPool<T> extend
       * @since 1.4
       */
      public synchronized void setLifo(boolean lifo) {
-         this.config.setLifo(lifo);
+         this.lifo = lifo;
      }
 
-    /**
-     * Sets my configuration.
-     *
-     * @param conf configuration to use.
-     * @see GenericObjectPoolConfig
-     */
-    public synchronized void setConfig(GenericObjectPoolConfig conf) {
-        this.config = conf;
-        allocate();
-    }
-
     //-- ObjectPool methods ------------------------------------------
 
     /**
@@ -649,8 +651,8 @@ public class GenericObjectPool<T> extend
             // Get local copy of current config. Can't sync when used later as
             // it can result in a deadlock. Has the added advantage that config
             // is consistent for entire method execution
-            whenExhaustedAction = this.config.getWhenExhaustedAction();
-            maxWait = this.config.getMaxWait();
+            whenExhaustedAction = this.whenExhaustedAction;
+            maxWait = this.maxWait;
 
             // Add this request to the queue
             _allocationQueue.add(latch);
@@ -772,7 +774,7 @@ public class GenericObjectPool<T> extend
             // activate & validate the object
             try {
                 _factory.activateObject(latch.getPair().getValue());
-                if(this.config.getTestOnBorrow() &&
+                if(testOnBorrow &&
                         !_factory.validateObject(latch.getPair().getValue())) {
                     throw new Exception("ValidateObject failed");
                 }
@@ -833,7 +835,7 @@ public class GenericObjectPool<T> extend
 
         // Second utilise any spare capacity to create new objects
         for(;;) {
-            if((!_allocationQueue.isEmpty()) && (this.config.getMaxActive() < 0 || (_numActive + _numInternalProcessing) < this.config.getMaxActive())) {
+            if((!_allocationQueue.isEmpty()) && (this.maxTotal < 0 || (_numActive + _numInternalProcessing) < this.maxTotal)) {
                 Latch latch = _allocationQueue.removeFirst();
                 latch.setMayCreate(true);
                 _numInternalProcessing++;
@@ -989,7 +991,7 @@ public class GenericObjectPool<T> extend
      */
     private void addObjectToPool(T obj, boolean decrementNumActive) throws Exception {
         boolean success = true;
-        if(this.config.getTestOnReturn() && !(_factory.validateObject(obj))) {
+        if(this.testOnReturn && !(_factory.validateObject(obj))) {
             success = false;
         } else {
             _factory.passivateObject(obj);
@@ -1003,7 +1005,7 @@ public class GenericObjectPool<T> extend
             if (isClosed()) {
                 shouldDestroy = true;
             } else {
-                if((this.config.getMaxIdle() >= 0) && (_pool.size() >= this.config.getMaxIdle())) {
+                if((this.maxIdle >= 0) && (_pool.size() >= this.maxIdle)) {
                     shouldDestroy = true;
                 } else if(success) {
                     // borrowObject always takes the first element from the queue,
@@ -1078,20 +1080,20 @@ public class GenericObjectPool<T> extend
                 return;
             }
             if (null == _evictionCursor) {
-                _evictionCursor = (_pool.cursor(this.config.getLifo() ? _pool.size() : 0));
+                _evictionCursor = (_pool.cursor(this.lifo ? _pool.size() : 0));
             }
         }
 
         for (int i=0,m=getNumTests();i<m;i++) {
             final ObjectTimestampPair<T> pair;
             synchronized (this) {
-                if ((this.config.getLifo() && !_evictionCursor.hasPrevious()) ||
-                        !this.config.getLifo() && !_evictionCursor.hasNext()) {
+                if ((this.lifo && !_evictionCursor.hasPrevious()) ||
+                        !this.lifo && !_evictionCursor.hasNext()) {
                     _evictionCursor.close();
-                    _evictionCursor = _pool.cursor(this.config.getLifo() ? _pool.size() : 0);
+                    _evictionCursor = _pool.cursor(this.lifo ? _pool.size() : 0);
                 }
 
-                pair = this.config.getLifo() ? _evictionCursor.previous() : _evictionCursor.next();
+                pair = this.lifo ? _evictionCursor.previous() : _evictionCursor.next();
 
                 _evictionCursor.remove();
                 _numInternalProcessing++;
@@ -1138,7 +1140,7 @@ public class GenericObjectPool<T> extend
             synchronized (this) {
                 if(!removeObject) {
                     _evictionCursor.add(pair);
-                    if (this.config.getLifo()) {
+                    if (this.lifo) {
                         // Skip over the element we just added back
                         _evictionCursor.previous();
                     }
@@ -1185,9 +1187,9 @@ public class GenericObjectPool<T> extend
      */
     private synchronized int calculateDeficit(boolean incrementInternal) {
         int objectDeficit = getMinIdle() - getNumIdle();
-        if (this.config.getMaxActive() > 0) {
+        if (this.maxTotal > 0) {
             int growLimit = Math.max(0,
-                    getMaxActive() - getNumActive() - getNumIdle() - _numInternalProcessing);
+                    maxTotal - getNumActive() - getNumIdle() - _numInternalProcessing);
             objectDeficit = Math.min(objectDeficit, growLimit);
         }
         if (incrementInternal && objectDeficit >0) {
@@ -1264,7 +1266,7 @@ public class GenericObjectPool<T> extend
      * @return the number of tests for the Evictor to run
      */
     private int getNumTests() {
-        int numTestsPerEvictionRun = this.config.getNumTestsPerEvictionRun();
+        int numTestsPerEvictionRun = this.numTestsPerEvictionRun;
         if(numTestsPerEvictionRun >= 0) {
             return Math.min(numTestsPerEvictionRun, _pool.size());
         } else {
@@ -1360,8 +1362,141 @@ public class GenericObjectPool<T> extend
 
     //--- private attributes ---------------------------------------
 
-    /** Pool configuration */
-    private GenericObjectPoolConfig config;
+    /* Pool configuration */
+
+    /**
+     * 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 #  */
+    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 long softMinEvictableIdleTimeMillis; // @GuardedBy("this")
 
     /** My pool. */
     private CursorableLinkedList<ObjectTimestampPair<T>> _pool = null;



Mime
View raw message