You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2010/10/25 15:35:45 UTC

svn commit: r1027112 [3/4] - in /commons/proper/pool/trunk/src: java/org/apache/commons/pool2/impl/ test/org/apache/commons/pool2/impl/

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=1027112&r1=1027111&r2=1027112&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 Mon Oct 25 13:35:44 2010
@@ -36,423 +36,260 @@ public class GenericObjectPoolFactory<T>
      * Create a new GenericObjectPoolFactory.
      *
      * @param factory the PoolableObjectFactory used by created pools.
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory)
+     * @see GenericObjectPoolConfig#GenericObjectPool(PoolableObjectFactory)
      */
     public GenericObjectPoolFactory(PoolableObjectFactory<T> factory) {
-        this(factory,GenericObjectPool.DEFAULT_MAX_ACTIVE,GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,GenericObjectPool.DEFAULT_MAX_WAIT,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
+        this(factory,new GenericObjectPoolConfig());
     }
 
     /**
      * Create a new GenericObjectPoolFactory.
      *
      * @param factory the PoolableObjectFactory used by created pools.
-     * @param config a non-<code>null</code> GenericObjectPool.Config describing the configuration.
-     * @throws NullPointerException when config is <code>null</code>.
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, GenericObjectPool.Config)
+     * @param config a non-<code>null</code> GenericObjectPoolConfig describing the configuration.
+     * @throws IllegalArgumentException when factory or config is <code>null</code>.
+     * @see GenericObjectPoolConfig#GenericObjectPool(PoolableObjectFactory, GenericObjectPool.Config)
      */
-    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, GenericObjectPool.Config config) throws NullPointerException {
-        this(factory,config.getMaxActive(),config.getWhenExhaustedAction(),config.getMaxWait(),config.getMaxIdle(),config.getMinIdle(),config.getTestOnBorrow(),config.getTestOnReturn(),config.getTimeBetweenEvictionRunsMillis(),config.getNumTestsPerEvictionRun(),config.getMinEvictableIdleTimeMillis(),config.getTestWhileIdle(),config.getSoftMinEvictableIdleTimeMillis(), config.getLifo());
-    }
-
-    /**
-     * Create a new GenericObjectPoolFactory.
-     *
-     * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxActive maximum number of objects that can be borrowed from created pools at one time.
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int)
-     */
-    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive) {
-        this(factory,maxActive,GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,GenericObjectPool.DEFAULT_MAX_WAIT,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
-    }
-
-    /**
-     * Create a new GenericObjectPoolFactory.
-     *
-     * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxActive maximum number of objects that can be borrowed from created pools at one time.
-     * @param whenExhaustedAction the action to take when the pool is exhausted.
-     * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted.
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, WhenExhaustedAction, long)
-     */
-    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait) {
-        this(factory,maxActive,whenExhaustedAction,maxWait,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
-    }
-
-    /**
-     * Create a new GenericObjectPoolFactory.
-     *
-     * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxActive maximum number of objects that can be borrowed from created pools at one time.
-     * @param whenExhaustedAction the action to take when the pool is exhausted.
-     * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted.
-     * @param testOnBorrow whether to validate objects before they are returned by the borrowObject.
-     * @param testOnReturn whether to validate objects after they are returned to the returnObject.
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, WhenExhaustedAction, long, boolean, boolean)
-     */
-    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn) {
-        this(factory,maxActive,whenExhaustedAction,maxWait,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
-    }
-
-    /**
-     * Create a new GenericObjectPoolFactory.
-     *
-     * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxActive maximum number of objects that can be borrowed from created pools at one time.
-     * @param whenExhaustedAction the action to take when the pool is exhausted.
-     * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted.
-     * @param maxIdle the maximum number of idle objects in my pool.
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, WhenExhaustedAction, long, int)
-     */
-    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle) {
-        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
-    }
-
-    /**
-     * Create a new GenericObjectPoolFactory.
-     *
-     * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxActive maximum number of objects that can be borrowed from created pools at one time.
-     * @param whenExhaustedAction the action to take when the pool is exhausted.
-     * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted.
-     * @param maxIdle the maximum number of idle objects in my pool.
-     * @param testOnBorrow whether to validate objects before they are returned by the borrowObject.
-     * @param testOnReturn whether to validate objects after they are returned to the returnObject.
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, WhenExhaustedAction, long, int, boolean, boolean)
-     */
-    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn) {
-        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,GenericObjectPool.DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
-    }
-
-    /**
-     * Create a new GenericObjectPoolFactory.
-     *
-     * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxActive maximum number of objects that can be borrowed from created pools at one time.
-     * @param whenExhaustedAction the action to take when the pool is exhausted.
-     * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted.
-     * @param maxIdle the maximum number of idle objects in my pool.
-     * @param testOnBorrow whether to validate objects before they are returned by the borrowObject.
-     * @param testOnReturn whether to validate objects after they are returned to the returnObject.
-     * @param timeBetweenEvictionRunsMillis the number of milliseconds to sleep between examining idle objects for eviction.
-     * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread.
-     * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction.
-     * @param testWhileIdle whether or not to validate objects in the idle object eviction thread.
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, WhenExhaustedAction, long, int, boolean, boolean, long, int, long, boolean)
-     */
-    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
-        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,GenericObjectPool.DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,timeBetweenEvictionRunsMillis,numTestsPerEvictionRun,minEvictableIdleTimeMillis,testWhileIdle, GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
-    }
-
-    /**
-     * Create a new GenericObjectPoolFactory.
-     *
-     * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxActive maximum number of objects that can be borrowed from created pools at one time.
-     * @param whenExhaustedAction the action to take when the pool is exhausted.
-     * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted.
-     * @param maxIdle the maximum number of idle objects in my pool.
-     * @param minIdle the minimum number of idle objects in my pool.
-     * @param testOnBorrow whether to validate objects before they are returned by the borrowObject.
-     * @param testOnReturn whether to validate objects after they are returned to the returnObject.
-     * @param timeBetweenEvictionRunsMillis the number of milliseconds to sleep between examining idle objects for eviction.
-     * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread.
-     * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction.
-     * @param testWhileIdle whether or not to validate objects in the idle object eviction thread.
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, WhenExhaustedAction, long, int, int, boolean, boolean, long, int, long, boolean)
-     */
-    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
-        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,minIdle,testOnBorrow,testOnReturn,timeBetweenEvictionRunsMillis,numTestsPerEvictionRun,minEvictableIdleTimeMillis,testWhileIdle, GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
-    }
-
-    /**
-     * Create a new GenericObjectPoolFactory.
-     *
-     * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxActive maximum number of objects that can be borrowed from created pools at one time.
-     * @param whenExhaustedAction the action to take when the pool is exhausted.
-     * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted.
-     * @param maxIdle the maximum number of idle objects in my pool.
-     * @param minIdle the minimum number of idle objects in my pool.
-     * @param testOnBorrow whether to validate objects before they are returned by the borrowObject.
-     * @param testOnReturn whether to validate objects after they are returned to the returnObject.
-     * @param timeBetweenEvictionRunsMillis the number of milliseconds to sleep between examining idle objects for eviction.
-     * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread.
-     * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction.
-     * @param testWhileIdle whether or not to validate objects in the idle object eviction thread.
-     * @param softMinEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction with the extra condition that at least "minIdle" amount of object remain in the pool.
-     * @since Pool 1.3
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, WhenExhaustedAction, long, int, int, boolean, boolean, long, int, long, boolean, long)
-     */
-    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle, long softMinEvictableIdleTimeMillis) {
-        this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,minIdle,testOnBorrow,testOnReturn,timeBetweenEvictionRunsMillis,numTestsPerEvictionRun,minEvictableIdleTimeMillis,testWhileIdle,softMinEvictableIdleTimeMillis, GenericObjectPool.DEFAULT_LIFO);
-    }
-
-    /**
-     * Create a new GenericObjectPoolFactory.
-     *
-     * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxActive maximum number of objects that can be borrowed from created pools at one time.
-     * @param whenExhaustedAction the action to take when the pool is exhausted.
-     * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted.
-     * @param maxIdle the maximum number of idle objects in my pool.
-     * @param minIdle the minimum number of idle objects in my pool.
-     * @param testOnBorrow whether to validate objects before they are returned by the borrowObject.
-     * @param testOnReturn whether to validate objects after they are returned to the returnObject.
-     * @param timeBetweenEvictionRunsMillis the number of milliseconds to sleep between examining idle objects for eviction.
-     * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread.
-     * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction.
-     * @param testWhileIdle whether or not to validate objects in the idle object eviction thread.
-     * @param softMinEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction with the extra condition that at least "minIdle" amount of object remain in the pool.
-     * @param lifo whether or not objects are returned in last-in-first-out order from the idle object pool.
-     * @since Pool 1.4
-     * @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, WhenExhaustedAction, long, int, int, boolean, boolean, long, int, long, boolean, long, boolean)
-     */
-    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle, long softMinEvictableIdleTimeMillis, boolean lifo) {
-        _maxIdle = maxIdle;
-        _minIdle = minIdle;
-        _maxActive = maxActive;
-        _maxWait = maxWait;
-        _whenExhaustedAction = whenExhaustedAction;
-        _testOnBorrow = testOnBorrow;
-        _testOnReturn = testOnReturn;
-        _testWhileIdle = testWhileIdle;
-        _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
-        _numTestsPerEvictionRun = numTestsPerEvictionRun;
-        _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
-        _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
-        _lifo = lifo;
-        _factory = factory;
+    public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, GenericObjectPoolConfig config) throws NullPointerException {
+        if (factory == null) {
+            throw new IllegalArgumentException("factory must not be null");
+        }
+        if (config == null) {
+            throw new IllegalArgumentException("config must not be null");
+        }
+        this._factory = factory;
+        this.config = config;
     }
 
     /**
      * {@inheritDoc}
      */
     public ObjectPool<T> createPool() {
-        return new GenericObjectPool<T>(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle,_softMinEvictableIdleTimeMillis,_lifo);
+        return new GenericObjectPool<T>(_factory,this.config);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getMaxIdle() maxIdle} setting for pools created by this factory.
+     * @return the {@link GenericObjectPoolConfig#getMaxIdle() maxIdle} setting for pools created by this factory.
      * @since 1.5.5
      */
     public synchronized int getMaxIdle() {
-        return _maxIdle;
+        return this.config.getMaxIdle();
     }
 
     /**
-     * @param maxIdle the {@link GenericObjectPool#getMaxIdle() maxIdle} setting for pools created by this factory.
+     * @param maxIdle the {@link GenericObjectPoolConfig#getMaxIdle() maxIdle} setting for pools created by this factory.
      * @since 2.0
      */
     public synchronized void setMaxIdle(int maxIdle) {
-        _maxIdle = maxIdle;
+        this.config.setMaxIdle(maxIdle);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getMinIdle() minIdle} setting for pools created by this factory.
+     * @return the {@link GenericObjectPoolConfig#getMinIdle() minIdle} setting for pools created by this factory.
      * @since 1.5.5
      */
     public synchronized int getMinIdle() {
-        return _minIdle;
+        return this.config.getMinIdle();
     }
 
     /**
-     * @param minIdle the {@link GenericObjectPool#getMinIdle() minIdle} setting for pools created by this factory.
+     * @param minIdle the {@link GenericObjectPoolConfig#getMinIdle() minIdle} setting for pools created by this factory.
      * @since 2.0
      */
     public synchronized void setMinIdle(int minIdle) {
-        _minIdle = minIdle;
+        this.config.setMinIdle(minIdle);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getMaxActive() maxActive} setting for pools created by this factory.
+     * @return the {@link GenericObjectPoolConfig#getMaxActive() maxActive} setting for pools created by this factory.
      * @since 1.5.5
      */
     public synchronized int getMaxActive() {
-        return _maxActive;
+        return this.config.getMaxActive();
     }
 
     /**
-     * @param maxActive the {@link GenericObjectPool#getMaxActive() maxActive} setting for pools created by this factory.
+     * @param maxActive the {@link GenericObjectPoolConfig#getMaxActive() maxActive} setting for pools created by this factory.
      * @since 2.0
      */
     public synchronized void setMaxActive(int maxActive) {
-        _maxActive = maxActive;
+        this.config.setMaxActive(maxActive);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getMaxWait() maxWait} setting for pools created by this factory.
+     * @return the {@link GenericObjectPoolConfig#getMaxWait() maxWait} setting for pools created by this factory.
      * @since 1.5.5
      */
     public synchronized long getMaxWait() {
-        return _maxWait;
+        return this.config.getMaxWait();
     }
 
     /**
-     * @param maxWait the {@link GenericObjectPool#getMaxWait() maxWait} setting for pools created by this factory.
+     * @param maxWait the {@link GenericObjectPoolConfig#getMaxWait() maxWait} setting for pools created by this factory.
      * @since 2.0
      */
     public synchronized void setMaxWait(long maxWait) {
-        _maxWait = maxWait;
+        this.config.setMaxWait(maxWait);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getWhenExhaustedAction() whenExhaustedAction} setting for pools
+     * @return the {@link GenericObjectPoolConfig#getWhenExhaustedAction() whenExhaustedAction} setting for pools
      * created by this factory.
      * @since 1.5.5
      */
     public synchronized WhenExhaustedAction getWhenExhaustedAction() {
-        return _whenExhaustedAction;
+        return this.config.getWhenExhaustedAction();
     }
 
     /**
-     * @param whenExhaustedAction the {@link GenericObjectPool#getWhenExhaustedAction() whenExhaustedAction} setting for pools
+     * @param whenExhaustedAction the {@link GenericObjectPoolConfig#getWhenExhaustedAction() whenExhaustedAction} setting for pools
      * created by this factory.
      * @since 2.0
      */
     public synchronized void setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
-        _whenExhaustedAction = whenExhaustedAction;
+        this.config.setWhenExhaustedAction(whenExhaustedAction);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getTestOnBorrow() testOnBorrow} setting for pools
+     * @return the {@link GenericObjectPoolConfig#getTestOnBorrow() testOnBorrow} setting for pools
      * created by this factory.
      * @since 1.5.5
      */
     public synchronized boolean getTestOnBorrow() {
-        return _testOnBorrow;
+        return this.config.getTestOnBorrow();
     }
 
     /**
-     * @param testOnBorrow the {@link GenericObjectPool#getTestOnBorrow() testOnBorrow} setting for pools
+     * @param testOnBorrow the {@link GenericObjectPoolConfig#getTestOnBorrow() testOnBorrow} setting for pools
      * created by this factory.
      * @since 2.0
      */
     public synchronized void setTestOnBorrow(boolean testOnBorrow) {
-        _testOnBorrow = testOnBorrow;
+        this.config.setTestOnBorrow(testOnBorrow);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getTestOnReturn() testOnReturn} setting for pools
+     * @return the {@link GenericObjectPoolConfig#getTestOnReturn() testOnReturn} setting for pools
      * created by this factory.
      * @since 1.5.5
      */
     public synchronized boolean getTestOnReturn() {
-        return _testOnReturn;
+        return this.config.getTestOnReturn();
     }
 
     /**
-     * @param testOnReturn the {@link GenericObjectPool#getTestOnReturn() testOnReturn} setting for pools
+     * @param testOnReturn the {@link GenericObjectPoolConfig#getTestOnReturn() testOnReturn} setting for pools
      * created by this factory.
      * @since 2.0
      */
     public synchronized void setTestOnReturn(boolean testOnReturn) {
-        _testOnReturn = testOnReturn;
+        this.config.setTestOnReturn(testOnReturn);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getTestWhileIdle() testWhileIdle} setting for pools
+     * @return the {@link GenericObjectPoolConfig#getTestWhileIdle() testWhileIdle} setting for pools
      * created by this factory.
      * @since 1.5.5
      */
     public synchronized boolean getTestWhileIdle() {
-        return _testWhileIdle;
+        return this.config.getTestWhileIdle();
     }
 
     /**
-     * @param testWhileIdle the {@link GenericObjectPool#getTestWhileIdle() testWhileIdle} setting for pools
+     * @param testWhileIdle the {@link GenericObjectPoolConfig#getTestWhileIdle() testWhileIdle} setting for pools
      * created by this factory.
      * @since 2.0
      */
     public synchronized void setTestWhileIdle(boolean testWhileIdle) {
-        _testWhileIdle = testWhileIdle;
+        this.config.setTestWhileIdle(testWhileIdle);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis}
+     * @return the {@link GenericObjectPoolConfig#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis}
      * setting for pools created by this factory.
      * @since 1.5.5
      */
     public synchronized long getTimeBetweenEvictionRunsMillis() {
-        return _timeBetweenEvictionRunsMillis;
+        return this.config.getTimeBetweenEvictionRunsMillis();
     }
 
     /**
-     * @param timeBetweenEvictionRunsMillis the {@link GenericObjectPool#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis}
+     * @param timeBetweenEvictionRunsMillis the {@link GenericObjectPoolConfig#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis}
      * setting for pools created by this factory.
      * @since 2.0
      */
     public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
-        _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+        this.config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getNumTestsPerEvictionRun() numTestsPerEvictionRun}
+     * @return the {@link GenericObjectPoolConfig#getNumTestsPerEvictionRun() numTestsPerEvictionRun}
      * setting for pools created by this factory.
      * @since 1.5.5
      */
     public synchronized int getNumTestsPerEvictionRun() {
-        return _numTestsPerEvictionRun;
+        return this.config.getNumTestsPerEvictionRun();
     }
 
     /**
-     * @param numTestsPerEvictionRun the {@link GenericObjectPool#getNumTestsPerEvictionRun() numTestsPerEvictionRun}
+     * @param numTestsPerEvictionRun the {@link GenericObjectPoolConfig#getNumTestsPerEvictionRun() numTestsPerEvictionRun}
      * setting for pools created by this factory.
      * @since 2.0
      */
     public synchronized void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
-        _numTestsPerEvictionRun = numTestsPerEvictionRun;
+        this.config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis}
+     * @return the {@link GenericObjectPoolConfig#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis}
      * setting for pools created by this factory.
      * @since 1.5.5
      */
     public synchronized long getMinEvictableIdleTimeMillis() {
-        return _minEvictableIdleTimeMillis;
+        return this.config.getMinEvictableIdleTimeMillis();
     }
 
     /**
-     * @param minEvictableIdleTimeMillis the {@link GenericObjectPool#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis}
+     * @param minEvictableIdleTimeMillis the {@link GenericObjectPoolConfig#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis}
      * setting for pools created by this factory.
      * @since 2.0
      */
     public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
-        _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+        this.config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getSoftMinEvictableIdleTimeMillis() softMinEvicatableIdleTimeMillis}
+     * @return the {@link GenericObjectPoolConfig#getSoftMinEvictableIdleTimeMillis() softMinEvicatableIdleTimeMillis}
      * setting for pools created by this factory.
      * @since 1.5.5
      */
     public synchronized long getSoftMinEvictableIdleTimeMillis() {
-        return _softMinEvictableIdleTimeMillis;
+        return this.config.getSoftMinEvictableIdleTimeMillis();
     }
 
     /**
-     * @param softMinEvictableIdleTimeMillis the {@link GenericObjectPool#getSoftMinEvictableIdleTimeMillis() softMinEvicatableIdleTimeMillis}
+     * @param softMinEvictableIdleTimeMillis the {@link GenericObjectPoolConfig#getSoftMinEvictableIdleTimeMillis() softMinEvicatableIdleTimeMillis}
      * setting for pools created by this factory.
      * @since 2.0
      */
     public synchronized void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {
-        _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+        this.config.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
     }
 
     /**
-     * @return the {@link GenericObjectPool#getLifo() lifo} setting for pools created by this factory.
+     * @return the {@link GenericObjectPoolConfig#getLifo() lifo} setting for pools created by this factory.
      * @since 1.5.5
      */
     public synchronized boolean getLifo() {
-        return _lifo;
+        return this.config.getLifo();
     }
 
     /**
-     * @param lifo the {@link GenericObjectPool#getLifo() lifo} setting for pools created by this factory.
+     * @param lifo the {@link GenericObjectPoolConfig#getLifo() lifo} setting for pools created by this factory.
      * @since 2.0
      */
     public synchronized void setLifo(boolean lifo) {
-        _lifo = lifo;
+        this.config.setLifo(lifo);
     }
 
     /**
@@ -461,80 +298,15 @@ public class GenericObjectPoolFactory<T>
     public PoolableObjectFactory<T> getFactory() {
         return _factory;
     }
-  
-    /**
-     * The {@link GenericObjectPool#getMaxIdle() maxIdle} setting for pools created by this factory.
-     */
-    private int _maxIdle = GenericObjectPool.DEFAULT_MAX_IDLE; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getMinIdle() minIdle} setting for pools created by this factory.
-     */
-    private int _minIdle = GenericObjectPool.DEFAULT_MIN_IDLE; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getMaxActive() maxActive} setting for pools created by this factory.
-     */
-    private int _maxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getMaxWait() maxWait} setting for pools created by this factory.
-     */
-    private long _maxWait = GenericObjectPool.DEFAULT_MAX_WAIT; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getWhenExhaustedAction() whenExhaustedAction} setting for pools
-     * created by this factory.
-     */
-    private WhenExhaustedAction _whenExhaustedAction = GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getTestOnBorrow() testOnBorrow} setting for pools created by this factory.
-     */
-    private boolean _testOnBorrow = GenericObjectPool.DEFAULT_TEST_ON_BORROW; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getTestOnReturn() testOnReturn} setting for pools created by this factory.
-     */
-    private boolean _testOnReturn = GenericObjectPool.DEFAULT_TEST_ON_RETURN; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getTestWhileIdle() testWhileIdle} setting for pools created by this factory.
-     */
-    private boolean _testWhileIdle = GenericObjectPool.DEFAULT_TEST_WHILE_IDLE; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis}
-     * setting for pools created by this factory.
-     */
-    private long _timeBetweenEvictionRunsMillis = GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getNumTestsPerEvictionRun() numTestsPerEvictionRun} setting
-     * for pools created by this factory.
-     */
-    private int _numTestsPerEvictionRun =  GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN; // @GuardedBy("this")
 
     /**
-     * The {@link GenericObjectPool#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis}
-     * setting for pools created by this factory.
-     */
-    private long _minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getSoftMinEvictableIdleTimeMillis() softMinEvictableIdleTimeMillis}
-     * setting for pools created by this factory.
-     */
-    private long _softMinEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS; // @GuardedBy("this")
-
-    /**
-     * The {@link GenericObjectPool#getLifo() lifo} setting for pools created by this factory.
+     * The {@link PoolableObjectFactory} used by pools created by this factory.
      */
-    private boolean _lifo = GenericObjectPool.DEFAULT_LIFO; // @GuardedBy("this")
+    private final PoolableObjectFactory<T> _factory;
 
     /**
-     * The {@link PoolableObjectFactory} used by pools created by this factory.
+     * The {@link GenericObjectPoolConfig} used by pools created by this factory.
      */
-    private final PoolableObjectFactory<T> _factory;
+    private final GenericObjectPoolConfig config;
 
 }

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPool.java?rev=1027112&r1=1027111&r2=1027112&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPool.java Mon Oct 25 13:35:44 2010
@@ -49,45 +49,33 @@ import org.apache.commons.pool2.PoolUtil
 public class StackKeyedObjectPool<K,V> extends BaseKeyedObjectPool<K,V> implements KeyedObjectPool<K,V> {
     /**
      * Create a new <code>SimpleKeyedObjectPool</code> using
-     * the specified <code>factory</code> to create new instances.
+     * the specified <code>factory</code> to create new instances
+     * with the default configuration.
      *
      * @param factory the {@link KeyedPoolableObjectFactory} used to populate the pool
      */
     public StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory) {
-        this(factory,DEFAULT_MAX_SLEEPING);
+        this(factory,new StackObjectPoolConfig());
     }
 
     /**
      * Create a new <code>SimpleKeyedObjectPool</code> using
-     * the specified <code>factory</code> to create new instances.
-     * capping the number of "sleeping" instances to <code>max</code>
+     * the specified <code>factory</code> to create new instances,
+     * with a user defined configuration.
      *
      * @param factory the {@link KeyedPoolableObjectFactory} used to populate the pool
-     * @param max cap on the number of "sleeping" instances in the pool
+     * @param config the {@link StackObjectPoolConfig} used to configure the pool.
      */
-    public StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory, int max) {
-        this(factory,max,DEFAULT_INIT_SLEEPING_CAPACITY);
-    }
-
-    /**
-     * Create a new <code>SimpleKeyedObjectPool</code> using
-     * the specified <code>factory</code> to create new instances.
-     * capping the number of "sleeping" instances to <code>max</code>,
-     * and initially allocating a container capable of containing
-     * at least <code>init</code> instances.
-     *
-     * @param factory the {@link KeyedPoolableObjectFactory} used to populate the pool
-     * @param max cap on the number of "sleeping" instances in the pool
-     * @param init initial size of the pool (this specifies the size of the container,
-     *             it does not cause the pool to be pre-populated.)
-     */
-    public StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory, int max, int init) {
+    public StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory, StackObjectPoolConfig config) {
         if (factory == null) {
             throw new IllegalArgumentException("factory must not be null");
         }
+        if (config == null) {
+            throw new IllegalArgumentException("config must not be null");
+        }
         _factory = factory;
-        _maxSleeping = (max < 0 ? DEFAULT_MAX_SLEEPING : max);
-        _initSleepingCapacity = (init < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : init);
+        this.config = config;
+
         _pools = new HashMap<K,Stack<V>>();
         _activeCount = new HashMap<K,Integer>();
     }
@@ -105,7 +93,7 @@ public class StackKeyedObjectPool<K,V> e
         Stack<V> stack = _pools.get(key);
         if(null == stack) {
             stack = new Stack<V>();
-            stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity);
+            stack.ensureCapacity(this.config.getInitIdleCapacity() > this.config.getMaxSleeping() ? this.config.getMaxSleeping() : this.config.getInitIdleCapacity());
             _pools.put(key,stack);
         }
         V obj = null;
@@ -181,11 +169,11 @@ public class StackKeyedObjectPool<K,V> e
         Stack<V> stack = _pools.get(key);
         if(null == stack) {
             stack = new Stack<V>();
-            stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity);
+            stack.ensureCapacity(this.config.getInitIdleCapacity() > this.config.getMaxSleeping() ? this.config.getMaxSleeping() : this.config.getInitIdleCapacity());
             _pools.put(key,stack);
         }
         final int stackSize = stack.size();
-        if (stackSize >= _maxSleeping) {
+        if (stackSize >= this.config.getMaxSleeping()) {
             final V staleObj;
             if (stackSize > 0) {
                 staleObj = stack.remove(0);
@@ -242,12 +230,12 @@ public class StackKeyedObjectPool<K,V> e
         Stack<V> stack = _pools.get(key);
         if(null == stack) {
             stack = new Stack<V>();
-            stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity);
+            stack.ensureCapacity(this.config.getInitIdleCapacity() > this.config.getMaxSleeping() ? this.config.getMaxSleeping() : this.config.getInitIdleCapacity());
             _pools.put(key,stack);
         }
 
         final int stackSize = stack.size();
-        if (stackSize >= _maxSleeping) {
+        if (stackSize >= this.config.getMaxSleeping()) {
             final V staleObj;
             if (stackSize > 0) {
                 staleObj = stack.remove(0);
@@ -470,7 +458,7 @@ public class StackKeyedObjectPool<K,V> e
      * @since 1.5.5
      */
     public synchronized int getMaxSleeping() {
-        return _maxSleeping;
+        return this.config.getMaxSleeping();
     }
 
     /**
@@ -480,7 +468,7 @@ public class StackKeyedObjectPool<K,V> e
      * @since 2.0
      */
     public synchronized void setMaxSleeping(int maxSleeping) {
-        _maxSleeping = maxSleeping;
+        this.config.setMaxSleeping(maxSleeping);
     }
 
     /**
@@ -488,7 +476,7 @@ public class StackKeyedObjectPool<K,V> e
      * @since 1.5.5
      */
     public int getInitSleepingCapacity() {
-        return _initSleepingCapacity;
+        return this.config.getInitIdleCapacity();
     }
 
     /**
@@ -514,16 +502,6 @@ public class StackKeyedObjectPool<K,V> e
     }
 
 
-    /** The default cap on the number of "sleeping" instances in the pool. */
-    protected static final int DEFAULT_MAX_SLEEPING  = 8;
-
-    /**
-     * The default initial size of the pool
-     * (this specifies the size of the container, it does not
-     * cause the pool to be pre-populated.)
-     */
-    protected static final int DEFAULT_INIT_SLEEPING_CAPACITY = 4;
-
     /**
      *  My named-set of pools.
      */
@@ -535,14 +513,9 @@ public class StackKeyedObjectPool<K,V> e
     private final KeyedPoolableObjectFactory<K,V> _factory;
 
     /**
-     *  The cap on the number of "sleeping" instances in <code>each</code> pool.
-     */
-    private int _maxSleeping = DEFAULT_MAX_SLEEPING; // @GuardedBy("this")
-
-    /**
-     * The initial capacity of each pool.
+     * My {@link StackObjectPoolConfig}.
      */
-    private final int _initSleepingCapacity;
+    private final StackObjectPoolConfig config;
 
     /**
      * Total number of object borrowed and not yet returned for all pools.

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPoolFactory.java?rev=1027112&r1=1027111&r2=1027112&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPoolFactory.java Mon Oct 25 13:35:44 2010
@@ -33,39 +33,31 @@ import org.apache.commons.pool2.KeyedPoo
  */
 public class StackKeyedObjectPoolFactory<K,V> implements KeyedObjectPoolFactory<K,V> {
     /**
-     * Create a new StackKeyedObjectPoolFactory.
+     * Create a new StackKeyedObjectPoolFactory with the default configuration..
      *
      * @param factory the KeyedPoolableObjectFactory used by created pools.
      * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory)
      */
     public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory) {
-        this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
+        this(factory,new StackObjectPoolConfig());
     }
 
     /**
-     * Create a new StackKeyedObjectPoolFactory.
+     * Create a new StackKeyedObjectPoolFactory, with a user defined configuration.
      *
      * @param factory the KeyedPoolableObjectFactory used by created pools.
-     * @param maxSleeping cap on the number of "sleeping" instances in the pool.
-     * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int)
+     * @param config the {@link StackObjectPoolConfig} used to configure the pool.
+     * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, StackObjectPoolConfig)
      */
-    public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxSleeping) {
-        this(factory,maxSleeping,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
-    }
-
-    /**
-     * Create a new StackKeyedObjectPoolFactory.
-     *
-     * @param factory the KeyedPoolableObjectFactory used by created pools.
-     * @param maxSleeping cap on the number of "sleeping" instances in the pool.
-     * @param initialCapacity initial size of the pool (this specifies the size of the container,
-     * it does not cause the pool to be pre-populated.)
-     * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int, int)
-     */
-    public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxSleeping, int initialCapacity) {
+    public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, StackObjectPoolConfig config) {
+        if (factory == null) {
+            throw new IllegalArgumentException("factory must not be null");
+        }
+        if (config == null) {
+            throw new IllegalArgumentException("config must not be null");
+        }
         _factory = factory;
-        _maxSleeping = maxSleeping;
-        _initCapacity = initialCapacity;
+        this.config = config;
     }
 
     /**
@@ -74,7 +66,7 @@ public class StackKeyedObjectPoolFactory
      * @return a new StackKeyedObjectPool with the configured factory, maxSleeping and initialCapacity
      */
     public KeyedObjectPool<K,V> createPool() {
-        return new StackKeyedObjectPool<K,V>(_factory,_maxSleeping,_initCapacity);
+        return new StackKeyedObjectPool<K,V>(_factory,this.config);
     }
 
     /** 
@@ -83,14 +75,9 @@ public class StackKeyedObjectPoolFactory
     private final KeyedPoolableObjectFactory<K,V> _factory;
 
     /** 
-     * Maximum number of idle instances in each keyed pool for StackKeyedObjectPools created by this factory
+     * The {@link StackObjectPoolConfig} used to configure the pool.
      */
-    private int _maxSleeping = StackKeyedObjectPool.DEFAULT_MAX_SLEEPING;
-
-    /**
-     * Initial capacity of StackKeyedObjectPools created by this factory.
-     */
-    private final int _initCapacity;
+    private StackObjectPoolConfig config;
 
     /**
      * Returns the KeyedPoolableObjectFactory used by StackKeyedObjectPools created by this factory
@@ -109,7 +96,7 @@ public class StackKeyedObjectPoolFactory
      * @since 1.5.5
      */
     public synchronized int getMaxSleeping() {
-        return _maxSleeping;
+        return this.config.getMaxSleeping();
     }
 
     /**
@@ -119,7 +106,7 @@ public class StackKeyedObjectPoolFactory
      * @since 2.0
      */
     public synchronized void setMaxSleeping(int maxSleeping) {
-        _maxSleeping = maxSleeping;
+        this.config.setMaxSleeping(maxSleeping);
     }
 
     /**
@@ -129,7 +116,17 @@ public class StackKeyedObjectPoolFactory
      * @since 1.5.5
      */
     public synchronized int getInitialCapacity() {
-        return _initCapacity;
+        return this.config.getInitIdleCapacity();
+    }
+
+    /**
+     * Sets initial size of the StackKeyedObjectPools created by this factory.
+     *
+     * @param initIdleCapacity
+     * @since 2.0
+     */
+    public synchronized void setInitIdleCapacity(int initIdleCapacity) {
+        this.config.setInitIdleCapacity(initIdleCapacity);
     }
 
 }

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPool.java?rev=1027112&r1=1027111&r2=1027112&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPool.java Mon Oct 25 13:35:44 2010
@@ -45,46 +45,31 @@ import org.apache.commons.pool2.Poolable
  */
 public class StackObjectPool<T> extends BaseObjectPool<T> implements ObjectPool<T> {
     /**
-     * Create a new <tt>StackObjectPool</tt> using the specified <i>factory</i> to create new instances.
+     * Create a new <tt>StackObjectPool</tt> using the specified <i>factory</i> to create new instances
+     * with the default configuration.
      *
      * @param factory the {@link PoolableObjectFactory} used to populate the pool
      */
     public StackObjectPool(PoolableObjectFactory<T> factory) {
-        this(factory,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY);
+        this(factory,new StackObjectPoolConfig());
     }
 
     /**
      * Create a new <tt>SimpleObjectPool</tt> using the specified <i>factory</i> to create new instances,
-     * capping the number of "sleeping" instances to <i>maxIdle</i>.
+     * with a user defined configuration.
      *
-     * @param factory the {@link PoolableObjectFactory} used to populate the pool
-     * @param maxIdle cap on the number of "sleeping" instances in the pool
+     * @param factory the {@link PoolableObjectFactory} used to populate the pool.
+     * @param config the {@link StackObjectPoolConfig} used to configure the pool.
      */
-    public StackObjectPool(PoolableObjectFactory<T> factory, int maxIdle) {
-        this(factory,maxIdle,DEFAULT_INIT_SLEEPING_CAPACITY);
-    }
-
-    /**
-     * <p>Create a new <tt>StackObjectPool</tt> using the specified <code>factory</code> to create new instances,
-     * capping the number of "sleeping" instances to <code>maxIdle</code>, and initially allocating a container
-     * capable of containing at least <code>initIdleCapacity</code> instances.  The pool is not pre-populated.
-     * The <code>initIdleCapacity</code> parameter just determines the initial size of the underlying
-     * container, which can increase beyond this value if <code>maxIdle &gt; initIdleCapacity.</code></p>
-     * 
-     * <p>Negative values of <code>maxIdle</code> are ignored (i.e., the pool is created using
-     * {@link #DEFAULT_MAX_SLEEPING}) as are non-positive values for <code>initIdleCapacity.</code>
-     *
-     * @param factory the {@link PoolableObjectFactory} used to populate the pool
-     * @param maxIdle cap on the number of "sleeping" instances in the pool
-     * @param initIdleCapacity initial size of the pool (this specifies the size of the container,
-     *             it does not cause the pool to be pre-populated.)
-     */
-    public StackObjectPool(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) {
+    public StackObjectPool(PoolableObjectFactory<T> factory, StackObjectPoolConfig config) {
+        if (config == null) {
+            throw new IllegalArgumentException("config must not be null");
+        }
         _factory = factory;
-        _maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle);
-        int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity);
+        this.config = config;
+
         _pool = new Stack<T>();
-        _pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity);
+        _pool.ensureCapacity(this.config.getInitIdleCapacity() > this.config.getMaxSleeping() ? this.config.getMaxSleeping() : this.config.getInitIdleCapacity());
     }
 
     /**
@@ -192,7 +177,7 @@ public class StackObjectPool<T> extends 
         _numActive--;
         if (success) {
             T toBeDestroyed = null;
-            if(_pool.size() >= _maxSleeping) {
+            if(_pool.size() >= this.config.getMaxSleeping()) {
                 shouldDestroy = true;
                 toBeDestroyed = _pool.remove(0); // remove the stalest object
             }
@@ -314,7 +299,7 @@ public class StackObjectPool<T> extends 
 
         if (success) {
             T toBeDestroyed = null;
-            if(_pool.size() >= _maxSleeping) {
+            if(_pool.size() >= this.config.getMaxSleeping()) {
                 shouldDestroy = true;
                 toBeDestroyed = _pool.remove(0); // remove the stalest object
             }
@@ -332,18 +317,6 @@ public class StackObjectPool<T> extends 
         }
     }
 
-    /**
-     * The cap on the number of "sleeping" instances in the pool.
-     */
-    protected static final int DEFAULT_MAX_SLEEPING  = 8;
-
-    /**
-     * The default initial size of the pool
-     * (this specifies the size of the container, it does not
-     * cause the pool to be pre-populated.)
-     */
-    protected static final int DEFAULT_INIT_SLEEPING_CAPACITY = 4;
-
     /** 
      * My pool. 
      */
@@ -354,10 +327,10 @@ public class StackObjectPool<T> extends 
      */
     private final PoolableObjectFactory<T> _factory;
 
-    /** 
-     * The cap on the number of "sleeping" instances in the pool.
+    /**
+     * My {@link StackObjectPoolConfig}.
      */
-    private int _maxSleeping = DEFAULT_MAX_SLEEPING; // @GuardedBy("this")
+    private final StackObjectPoolConfig config;
 
     /**
      * Number of objects borrowed but not yet returned to the pool.
@@ -381,7 +354,7 @@ public class StackObjectPool<T> extends 
      * @since 1.5.5
      */
     public synchronized int getMaxSleeping() {
-        return _maxSleeping;
+        return this.config.getMaxSleeping();
     }
 
     /**
@@ -391,6 +364,6 @@ public class StackObjectPool<T> extends 
      * @since 2.0
      */
    public synchronized void setMaxSleeping(int maxSleeping) {
-       _maxSleeping = maxSleeping;
+       this.config.setMaxSleeping(maxSleeping);
    }
 }

Added: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java?rev=1027112&view=auto
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java (added)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java Mon Oct 25 13:35:44 2010
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.pool2.impl;
+
+/**
+ * 
+ * @version $Revision$ $Date$
+ * @since Pool 2.0
+ */
+public class StackObjectPoolConfig {
+
+    /**
+     * The cap on the number of "sleeping" instances in the pool.
+     */
+    public static final int DEFAULT_MAX_SLEEPING  = 8;
+
+    /**
+     * The default initial size of the pool
+     * (this specifies the size of the container, it does not
+     * cause the pool to be pre-populated.)
+     */
+    public static final int DEFAULT_INIT_SLEEPING_CAPACITY = 4;
+
+    /**
+     * cap on the number of "sleeping" instances in the pool
+     */
+    private int maxSleeping = DEFAULT_MAX_SLEEPING;
+
+    /**
+     * initial size of the pool (this specifies the size of the container,
+     * it does not cause the pool to be pre-populated.)
+     */
+    private int initIdleCapacity = DEFAULT_INIT_SLEEPING_CAPACITY;
+
+    public int getMaxSleeping() {
+        return maxSleeping;
+    }
+
+    public void setMaxSleeping(int maxSleeping) {
+        this.maxSleeping = (maxSleeping < 0 ? DEFAULT_MAX_SLEEPING : maxSleeping);
+    }
+
+    public int getInitIdleCapacity() {
+        return initIdleCapacity;
+    }
+
+    public void setInitIdleCapacity(int initIdleCapacity) {
+        this.initIdleCapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity);
+    }
+
+}

Propchange: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolFactory.java?rev=1027112&r1=1027111&r2=1027112&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolFactory.java Mon Oct 25 13:35:44 2010
@@ -39,31 +39,24 @@ public class StackObjectPoolFactory<T> i
      * @see StackObjectPool#StackObjectPool(PoolableObjectFactory)
      */
     public StackObjectPoolFactory(PoolableObjectFactory<T> factory) {
-        this(factory,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
+        this(factory,new StackObjectPoolConfig());
     }
 
     /**
      * Create a new StackObjectPoolFactory.
      *
      * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxIdle cap on the number of "sleeping" instances in the pool.
+     * @param config the {@link StackObjectPoolConfig} used to configure the pool.
      */
-    public StackObjectPoolFactory(PoolableObjectFactory<T> factory, int maxIdle) {
-        this(factory,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
-    }
-
-    /**
-     * Create a new StackObjectPoolFactory.
-     *
-     * @param factory the PoolableObjectFactory used by created pools.
-     * @param maxIdle cap on the number of "sleeping" instances in the pool.
-     * @param initIdleCapacity - initial size of the pool (this specifies the size of the container,
-     * it does not cause the pool to be pre-populated.)
-     */
-    public StackObjectPoolFactory(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) {
+    public StackObjectPoolFactory(PoolableObjectFactory<T> factory, StackObjectPoolConfig config) {
+        if (factory == null) {
+            throw new IllegalArgumentException("factory must not be null");
+        }
+        if (config == null) {
+            throw new IllegalArgumentException("config must not be null");
+        }
         _factory = factory;
-        _maxSleeping = maxIdle;
-        _initCapacity = initIdleCapacity;
+        this.config = config;
     }
 
     /**
@@ -72,7 +65,7 @@ public class StackObjectPoolFactory<T> i
      * @return a new StackObjectPool with the configured factory, maxIdle and initial capacity settings
      */
     public ObjectPool<T> createPool() {
-        return new StackObjectPool<T>(_factory,_maxSleeping,_initCapacity);
+        return new StackObjectPool<T>(_factory,this.config);
     }
 
     /**
@@ -81,14 +74,9 @@ public class StackObjectPoolFactory<T> i
     private final PoolableObjectFactory<T> _factory;
 
     /**
-     * The maximum number of idle instances in created pools.
-     */
-    private int _maxSleeping = StackObjectPool.DEFAULT_MAX_SLEEPING;
-
-    /**
-     * The initial size of created pools.
+     * The {@link StackObjectPoolConfig} used to configure the pool.
      */
-    private final int _initCapacity;
+    private final StackObjectPoolConfig config;
 
     /**
      * Returns the factory used by created pools.
@@ -107,7 +95,7 @@ public class StackObjectPoolFactory<T> i
      * @since 1.5.5
      */
     public synchronized int getMaxSleeping() {
-        return _maxSleeping;
+        return this.config.getMaxSleeping();
     }
 
     /**
@@ -117,7 +105,7 @@ public class StackObjectPoolFactory<T> i
      * @since 2.0
      */
     public synchronized void setMaxSleeping(int maxSleeping) {
-        _maxSleeping = maxSleeping;
+        this.config.setMaxSleeping(maxSleeping);
     }
 
     /**
@@ -127,7 +115,7 @@ public class StackObjectPoolFactory<T> i
      * @since 1.5.5
      */
     public synchronized int getInitCapacity() {
-        return _initCapacity;
+        return this.config.getInitIdleCapacity();
     }
 
 }

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=1027112&r1=1027111&r2=1027112&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 Mon Oct 25 13:35:44 2010
@@ -36,8 +36,6 @@ import org.apache.commons.pool2.KeyedPoo
 import org.apache.commons.pool2.TestBaseKeyedObjectPool;
 import org.apache.commons.pool2.VisitTracker;
 import org.apache.commons.pool2.VisitTrackerFactory;
-import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
-import org.apache.commons.pool2.impl.WhenExhaustedAction;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -298,7 +296,7 @@ public class TestGenericKeyedObjectPool 
     public void testMaxTotalLRU() throws Exception {
         pool.setMaxActive(2);
         pool.setMaxTotal(3);
-//        pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW);
+//        pool.setWhenExhaustedAction(GenericKeyedObjectPoolConfig.WHEN_EXHAUSTED_GROW);
 
         String o1 = pool.borrowObject("a");
         assertNotNull(o1);
@@ -1020,28 +1018,28 @@ public class TestGenericKeyedObjectPool 
             }
         };   
         GenericKeyedObjectPool<Object,Object> pool = new GenericKeyedObjectPool<Object,Object>(factory);
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE, pool.getMaxActive());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_WAIT, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        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,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_BORROW,
                 pool.getTestOnBorrow());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_RETURN,
                 pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_WHEN_EXHAUSTED_ACTION,
                 pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
         
-        GenericKeyedObjectPool.Config config = new GenericKeyedObjectPool.Config();
+        GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
         config.setLifo(lifo);
         config.setMaxActive(maxActive);
         config.setMaxIdle(maxIdle);
@@ -1071,121 +1069,150 @@ public class TestGenericKeyedObjectPool 
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
         assertEquals(lifo, pool.getLifo());
-        
-        pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive);
+
+        config = new GenericKeyedObjectPoolConfig();
+        config.setMaxActive(maxActive);
+        pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
         assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_WAIT, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        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,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_BORROW,
                 pool.getTestOnBorrow());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_RETURN,
                 pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_WHEN_EXHAUSTED_ACTION,
                 pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
-        
-        pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction, maxWait);
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+
+        config = new GenericKeyedObjectPoolConfig();
+        config.setMaxActive(maxActive);
+        config.setWhenExhaustedAction(whenExhaustedAction);
+        config.setMaxWait(maxWait);
+        pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
         assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE, pool.getMaxIdle());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_BORROW,
                 pool.getTestOnBorrow());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_RETURN,
                 pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
-        
-        pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
-                   maxWait, testOnBorrow, testOnReturn);
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+
+        config = new GenericKeyedObjectPoolConfig();
+        config.setMaxActive(maxActive);
+        config.setWhenExhaustedAction(whenExhaustedAction);
+        config.setMaxWait(maxWait);
+        config.setTestOnReturn(testOnReturn);
+        config.setTestOnReturn(testOnReturn);
+        pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
         assertEquals(maxActive, pool.getMaxActive());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE, pool.getMaxIdle());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
         assertEquals(testOnBorrow,pool.getTestOnBorrow());
         assertEquals(testOnReturn,pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
-        
-        pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
-                maxWait, maxIdle);
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
+
+        config = new GenericKeyedObjectPoolConfig();
+        config.setMaxActive(maxActive);
+        config.setWhenExhaustedAction(whenExhaustedAction);
+        config.setMaxWait(maxWait);
+        config.setMinIdle(minIdle);
+        pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
         assertEquals(maxActive, pool.getMaxActive());
         assertEquals(maxIdle, pool.getMaxIdle());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_BORROW,
                 pool.getTestOnBorrow());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_RETURN,
                 pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
 
-        pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
-                maxWait, maxIdle, testOnBorrow, testOnReturn);
+        config = new GenericKeyedObjectPoolConfig();
+        config.setMaxActive(maxActive);
+        config.setWhenExhaustedAction(whenExhaustedAction);
+        config.setMaxWait(maxWait);
+        config.setMaxIdle(maxIdle);
+        config.setTestOnBorrow(testOnBorrow);
+        config.setTestOnReturn(testOnReturn);
+        pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
         assertEquals(maxActive, pool.getMaxActive());
         assertEquals(maxIdle, pool.getMaxIdle());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
                 pool.getMinEvictableIdleTimeMillis());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
                 pool.getNumTestsPerEvictionRun());
         assertEquals(testOnBorrow, pool.getTestOnBorrow());
         assertEquals(testOnReturn, pool.getTestOnReturn());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE,
                 pool.getTestWhileIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_LIFO, pool.getLifo());
 
-        pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
-                maxWait, maxIdle, testOnBorrow, testOnReturn,
-                timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
-                minEvictableIdleTimeMillis, testWhileIdle);
+        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);
+        pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
         assertEquals(maxActive, pool.getMaxActive());
         assertEquals(maxIdle, pool.getMaxIdle());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
         assertEquals(minEvictableIdleTimeMillis,
                 pool.getMinEvictableIdleTimeMillis());
         assertEquals(numTestsPerEvictionRun,
@@ -1197,16 +1224,25 @@ public class TestGenericKeyedObjectPool 
         assertEquals(timeBetweenEvictionRunsMillis,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
-        
-        pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
-                maxWait, maxIdle, maxTotal, testOnBorrow, testOnReturn,
-                timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
-                minEvictableIdleTimeMillis, testWhileIdle);
+        assertEquals(GenericKeyedObjectPoolConfig.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);
+        pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
         assertEquals(maxActive, pool.getMaxActive());
         assertEquals(maxIdle, pool.getMaxIdle());
         assertEquals(maxWait, pool.getMaxWait());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
+        assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE, pool.getMinIdle());
         assertEquals(maxTotal, pool.getMaxTotal());
         assertEquals(minEvictableIdleTimeMillis,
                 pool.getMinEvictableIdleTimeMillis());
@@ -1219,12 +1255,22 @@ public class TestGenericKeyedObjectPool 
         assertEquals(timeBetweenEvictionRunsMillis,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
-        
-        pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
-                maxWait, maxIdle, maxTotal, minIdle, testOnBorrow, testOnReturn,
-                timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
-                minEvictableIdleTimeMillis, testWhileIdle);
+        assertEquals(GenericKeyedObjectPoolConfig.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);
+        pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
         assertEquals(maxActive, pool.getMaxActive());
         assertEquals(maxIdle, pool.getMaxIdle());
         assertEquals(maxWait, pool.getMaxWait());
@@ -1241,12 +1287,23 @@ public class TestGenericKeyedObjectPool 
         assertEquals(timeBetweenEvictionRunsMillis,
                 pool.getTimeBetweenEvictionRunsMillis());
         assertEquals(whenExhaustedAction,pool.getWhenExhaustedAction());
-        assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());
-        
-        pool = new GenericKeyedObjectPool<Object,Object>(factory, maxActive, whenExhaustedAction,
-                maxWait, maxIdle, maxTotal, minIdle, testOnBorrow, testOnReturn,
-                timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
-                minEvictableIdleTimeMillis, testWhileIdle, lifo);
+        assertEquals(GenericKeyedObjectPoolConfig.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);
+        pool = new GenericKeyedObjectPool<Object,Object>(factory, config);
         assertEquals(maxActive, pool.getMaxActive());
         assertEquals(maxIdle, pool.getMaxIdle());
         assertEquals(maxWait, pool.getMaxWait());