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 [2/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/GenericKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java?rev=1027112&r1=1027111&r2=1027112&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 Mon Oct 25 13:35:44 2010
@@ -40,7 +40,7 @@ public class GenericKeyedObjectPoolFacto
* @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory)
*/
public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory) {
- this(factory,GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE,GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,GenericKeyedObjectPool.DEFAULT_MAX_WAIT,GenericKeyedObjectPool.DEFAULT_MAX_IDLE,GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
+ this(factory,new GenericKeyedObjectPoolConfig());
}
/**
@@ -51,192 +51,15 @@ public class GenericKeyedObjectPoolFacto
* @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, GenericKeyedObjectPool.Config)
* @throws NullPointerException when config is <code>null</code>.
*/
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, GenericKeyedObjectPool.Config config) throws NullPointerException {
- this(factory,config.getMaxActive(),config.getWhenExhaustedAction(),config.getMaxWait(),config.getMaxIdle(),config.getMaxTotal(),config.getMinIdle(),config.getTestOnBorrow(),config.getTestOnReturn(),config.getTimeBetweenEvictionRunsMillis(),config.getNumTestsPerEvictionRun(),config.getMinEvictableIdleTimeMillis(),config.getTestWhileIdle(),config.getLifo());
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param maxActive the maximum number of objects that can be borrowed from pools at one time.
- * @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int)
- */
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxActive) {
- this(factory,maxActive,GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,GenericKeyedObjectPool.DEFAULT_MAX_WAIT,GenericKeyedObjectPool.DEFAULT_MAX_IDLE, GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param maxActive the maximum number of objects that can be borrowed from 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 GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, WhenExhaustedAction, long)
- */
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait) {
- this(factory,maxActive,whenExhaustedAction,maxWait,GenericKeyedObjectPool.DEFAULT_MAX_IDLE, GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param maxActive the maximum number of objects that can be borrowed from 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 borrowObject.
- * @param testOnReturn whether to validate objects after they are returned to returnObject.
- * @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, WhenExhaustedAction, long, boolean, boolean)
- */
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn) {
- this(factory,maxActive,whenExhaustedAction,maxWait,GenericKeyedObjectPool.DEFAULT_MAX_IDLE, GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,testOnBorrow,testOnReturn,GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param maxActive the maximum number of objects that can be borrowed from 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 the pools.
- * @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, WhenExhaustedAction, long, int)
- */
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle) {
- this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle, GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param maxActive the maximum number of objects that can be borrowed from 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 the pools.
- * @param maxTotal the maximum number of objects that can exists at one time.
- */
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle, int maxTotal) {
- this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle, maxTotal, GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW,GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN,GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param maxActive the maximum number of objects that can be borrowed from 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 the pools.
- * @param testOnBorrow whether to validate objects before they are returned by borrowObject.
- * @param testOnReturn whether to validate objects after they are returned to returnObject.
- * @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, WhenExhaustedAction, long, int, boolean, boolean)
- */
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn) {
- this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle, GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,testOnBorrow,testOnReturn,GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param maxActive the maximum number of objects that can be borrowed from 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 the pools.
- * @param testOnBorrow whether to validate objects before they are returned by borrowObject.
- * @param testOnReturn whether to validate objects after they are returned to 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 of the evictor.
- * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction.
- * @param testWhileIdle whether to validate objects in the idle object eviction thread.
- * @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, WhenExhaustedAction, long, int, boolean, boolean, long, int, long, boolean)
- */
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> 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, GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle);
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param maxActive the maximum number of objects that can be borrowed from 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 the pools.
- * @param maxTotal the maximum number of objects that can exists at one time.
- * @param testOnBorrow whether to validate objects before they are returned by borrowObject.
- * @param testOnReturn whether to validate objects after they are returned to 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 of the evictor.
- * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction.
- * @param testWhileIdle whether to validate objects in the idle object eviction thread.
- * @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, WhenExhaustedAction, long, int, int, boolean, boolean, long, int, long, boolean)
- */
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
- this(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal, GenericKeyedObjectPool.DEFAULT_MIN_IDLE , testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle);
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param maxActive the maximum number of objects that can be borrowed from 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 the pools.
- * @param maxTotal the maximum number of objects that can exists at one time.
- * @param minIdle the minimum number of idle objects to have in the pool at any one time.
- * @param testOnBorrow whether to validate objects before they are returned by borrowObject.
- * @param testOnReturn whether to validate objects after they are returned to 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 of the evictor.
- * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction.
- * @param testWhileIdle whether to validate objects in the idle object eviction thread.
- * @since Pool 1.3
- * @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, WhenExhaustedAction, long, int, int, int, boolean, boolean, long, int, long, boolean)
- */
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
- this(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal, minIdle, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle, GenericKeyedObjectPool.DEFAULT_LIFO);
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param maxActive the maximum number of objects that can be borrowed from 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 the pools.
- * @param maxTotal the maximum number of objects that can exists at one time.
- * @param minIdle the minimum number of idle objects to have in the pool at any one time.
- * @param testOnBorrow whether to validate objects before they are returned by borrowObject.
- * @param testOnReturn whether to validate objects after they are returned to 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 of the evictor.
- * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligible for eviction.
- * @param testWhileIdle whether to validate objects in the idle object eviction thread.
- * @param lifo whether or not objects are returned in last-in-first-out order from the idle object pool.
- * @since Pool 1.4
- * @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, WhenExhaustedAction, long, int, int, int, boolean, boolean, long, int, long, boolean, boolean)
- */
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle, boolean lifo) {
- _maxIdle = maxIdle;
- _maxActive = maxActive;
- _maxTotal = maxTotal;
- _minIdle = minIdle;
- _maxWait = maxWait;
- _whenExhaustedAction = whenExhaustedAction;
- _testOnBorrow = testOnBorrow;
- _testOnReturn = testOnReturn;
- _testWhileIdle = testWhileIdle;
- _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
- _numTestsPerEvictionRun = numTestsPerEvictionRun;
- _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+ public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory, GenericKeyedObjectPoolConfig 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");
+ }
_factory = factory;
- _lifo = lifo;
+ this.config = config;
}
/**
@@ -246,7 +69,7 @@ public class GenericKeyedObjectPoolFacto
* current property settings
*/
public KeyedObjectPool<K,V> createPool() {
- return new GenericKeyedObjectPool<K,V>(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_maxTotal,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle,_lifo);
+ return new GenericKeyedObjectPool<K,V>(_factory,this.config);
}
/**
@@ -254,7 +77,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public int getMaxIdle() {
- return _maxIdle;
+ return this.config.getMaxIdle();
}
/**
@@ -262,7 +85,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public int getMaxActive() {
- return _maxActive;
+ return this.config.getMaxActive();
}
/**
@@ -270,7 +93,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public int getMaxTotal() {
- return _maxTotal;
+ return this.config.getMaxTotal();
}
/**
@@ -278,7 +101,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public int getMinIdle() {
- return _minIdle;
+ return this.config.getMinIdle();
}
/**
@@ -286,7 +109,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public long getMaxWait() {
- return _maxWait;
+ return this.config.getMaxWait();
}
/**
@@ -294,7 +117,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public WhenExhaustedAction getWhenExhaustedAction() {
- return _whenExhaustedAction;
+ return this.config.getWhenExhaustedAction();
}
/**
@@ -302,7 +125,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public boolean getTestOnBorrow() {
- return _testOnBorrow;
+ return this.config.getTestOnBorrow();
}
/**
@@ -310,7 +133,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public boolean getTestOnReturn() {
- return _testOnReturn;
+ return this.config.getTestOnReturn();
}
/**
@@ -318,7 +141,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public boolean getTestWhileIdle() {
- return _testWhileIdle;
+ return this.config.getTestWhileIdle();
}
/**
@@ -327,7 +150,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public long getTimeBetweenEvictionRunsMillis() {
- return _timeBetweenEvictionRunsMillis;
+ return this.config.getTimeBetweenEvictionRunsMillis();
}
/**
@@ -336,7 +159,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public int getNumTestsPerEvictionRun() {
- return _numTestsPerEvictionRun;
+ return this.config.getNumTestsPerEvictionRun();
}
/**
@@ -345,7 +168,7 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public long getMinEvictableIdleTimeMillis() {
- return _minEvictableIdleTimeMillis;
+ return this.config.getMinEvictableIdleTimeMillis();
}
/**
@@ -361,96 +184,13 @@ public class GenericKeyedObjectPoolFacto
* @since 1.5.5
*/
public boolean getLifo() {
- return _lifo;
+ return this.config.getLifo();
}
- //--- protected attributes - deprecated, use getters to access these properties
-
- /**
- * The {@link GenericKeyedObjectPool#getMaxIdle() maxIdle} setting for pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getMaxIdle()}.
- */
- protected int _maxIdle = GenericKeyedObjectPool.DEFAULT_MAX_IDLE;
-
- /**
- * The {@link GenericKeyedObjectPool#getMaxActive() maxActive} setting for pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getMaxActive()}.
- */
- protected int _maxActive = GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE;
-
- /**
- * The {@link GenericKeyedObjectPool#getMaxTotal() maxTotal} setting for pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getMaxTotal()}.
- */
- protected int _maxTotal = GenericKeyedObjectPool.DEFAULT_MAX_TOTAL;
-
- /**
- * The {@link GenericKeyedObjectPool#getMinIdle() minIdle} setting for pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getMinIdle()}.
- */
- protected int _minIdle = GenericKeyedObjectPool.DEFAULT_MIN_IDLE;
-
- /**
- * The {@link GenericKeyedObjectPool#getMaxWait() maxWait} setting for pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getMaxWait()}.
- */
- protected long _maxWait = GenericKeyedObjectPool.DEFAULT_MAX_WAIT;
-
- /**
- * The {@link GenericKeyedObjectPool#getWhenExhaustedAction() whenExhaustedAction} setting for pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getWhenExhaustedAction()}.
- */
- protected WhenExhaustedAction _whenExhaustedAction = GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
-
- /**
- * The {@link GenericKeyedObjectPool#getTestOnBorrow() testOnBorrow} setting for pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getTestOnBorrow()}.
- */
- protected boolean _testOnBorrow = GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW;
+ //--- private attributes
- /**
- * The {@link GenericKeyedObjectPool#getTestOnReturn() testOnReturn} setting for pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getTestOnReturn()}.
- */
- protected boolean _testOnReturn = GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN;
+ private final KeyedPoolableObjectFactory<K,V> _factory;
- /**
- * The {@link GenericKeyedObjectPool#getTestWhileIdle() testWhileIdle} setting for pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getTestWhileIdle()}.
- */
- protected boolean _testWhileIdle = GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE;
-
- /**
- * The {@link GenericKeyedObjectPool#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis} setting for
- * pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getTimeBetweenEvictionRunsMillis()}.
- */
- protected long _timeBetweenEvictionRunsMillis = GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
-
- /**
- * The {@link GenericKeyedObjectPool#getNumTestsPerEvictionRun() numTestsPerEvictionRun} setting for
- * pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getNumTestsPerEvictionRun()}.
- */
- protected int _numTestsPerEvictionRun = GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
-
- /**
- * The {@link GenericKeyedObjectPool#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis} setting for
- * pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getMinEvictableIdleTimeMillis()}.
- */
- protected long _minEvictableIdleTimeMillis = GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
-
- /**
- * The {@link KeyedPoolableObjectFactory} used by pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getFactory()}.
- */
- protected KeyedPoolableObjectFactory<K,V> _factory = null;
-
- /**
- * The {@link GenericKeyedObjectPool#getLifo() lifo} setting for pools created by this factory.
- * @deprecated to be removed in pool 2.0. Use {@link #getLifo()}.
- */
- protected boolean _lifo = GenericKeyedObjectPool.DEFAULT_LIFO;
+ private final GenericKeyedObjectPoolConfig config;
}
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=1027112&r1=1027111&r2=1027112&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPool.java Mon Oct 25 13:35:44 2010
@@ -187,364 +187,33 @@ import org.apache.commons.pool2.impl.Gen
*/
public class GenericObjectPool<T> extends BaseObjectPool<T> implements ObjectPool<T> {
- //--- public constants -------------------------------------------
-
- /**
- * The default cap on the number of "sleeping" instances in the pool.
- * @see #getMaxIdle
- * @see #setMaxIdle
- */
- public static final int DEFAULT_MAX_IDLE = 8;
-
- /**
- * The default minimum number of "sleeping" instances in the pool
- * before before the evictor thread (if active) spawns new objects.
- * @see #getMinIdle
- * @see #setMinIdle
- */
- public static final int DEFAULT_MIN_IDLE = 0;
-
- /**
- * The default cap on the total number of active instances from the pool.
- * @see #getMaxActive
- */
- public static final int DEFAULT_MAX_ACTIVE = 8;
-
- /**
- * The default "when exhausted action" for the pool.
- * @see WhenExhaustedAction#BLOCK
- * @see WhenExhaustedAction#FAIL
- * @see WhenExhaustedAction#GROW
- * @see #setWhenExhaustedAction
- */
- public static final WhenExhaustedAction DEFAULT_WHEN_EXHAUSTED_ACTION = WhenExhaustedAction.BLOCK;
-
- /**
- * The default LIFO status. True means that borrowObject returns the
- * most recently used ("last in") idle object in the pool (if there are
- * idle instances available). False means that the pool behaves as a FIFO
- * queue - objects are taken from the idle object pool in the order that
- * they are returned to the pool.
- * @see #setLifo
- * @since 1.4
- */
- public static final boolean DEFAULT_LIFO = true;
-
- /**
- * The default maximum amount of time (in milliseconds) the
- * {@link #borrowObject} method should block before throwing
- * an exception when the pool is exhausted and the
- * {@link #getWhenExhaustedAction "when exhausted" action} is
- * {@link WhenExhaustedAction#BLOCK}.
- * @see #getMaxWait
- * @see #setMaxWait
- */
- public static final long DEFAULT_MAX_WAIT = -1L;
-
- /**
- * The default "test on borrow" value.
- * @see #getTestOnBorrow
- * @see #setTestOnBorrow
- */
- public static final boolean DEFAULT_TEST_ON_BORROW = false;
-
- /**
- * The default "test on return" value.
- * @see #getTestOnReturn
- * @see #setTestOnReturn
- */
- public static final boolean DEFAULT_TEST_ON_RETURN = false;
-
- /**
- * The default "test while idle" value.
- * @see #getTestWhileIdle
- * @see #setTestWhileIdle
- * @see #getTimeBetweenEvictionRunsMillis
- * @see #setTimeBetweenEvictionRunsMillis
- */
- public static final boolean DEFAULT_TEST_WHILE_IDLE = false;
-
- /**
- * The default "time between eviction runs" value.
- * @see #getTimeBetweenEvictionRunsMillis
- * @see #setTimeBetweenEvictionRunsMillis
- */
- public static final long DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS = -1L;
-
- /**
- * The default number of objects to examine per run in the
- * idle object evictor.
- * @see #getNumTestsPerEvictionRun
- * @see #setNumTestsPerEvictionRun
- * @see #getTimeBetweenEvictionRunsMillis
- * @see #setTimeBetweenEvictionRunsMillis
- */
- public static final int DEFAULT_NUM_TESTS_PER_EVICTION_RUN = 3;
-
- /**
- * The default value for {@link #getMinEvictableIdleTimeMillis}.
- * @see #getMinEvictableIdleTimeMillis
- * @see #setMinEvictableIdleTimeMillis
- */
- public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS = 1000L * 60L * 30L;
-
- /**
- * The default value for {@link #getSoftMinEvictableIdleTimeMillis}.
- * @see #getSoftMinEvictableIdleTimeMillis
- * @see #setSoftMinEvictableIdleTimeMillis
- */
- public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;
-
//--- constructors -----------------------------------------------
/**
- * Create a new <tt>GenericObjectPool</tt> using the specified factory.
+ * Create a new <tt>GenericObjectPool</tt> using the specified factory and a default {@link GenericObjectPoolConfig}.
* @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
*/
public GenericObjectPool(PoolableObjectFactory<T> factory) {
- this(factory, DEFAULT_MAX_ACTIVE, DEFAULT_WHEN_EXHAUSTED_ACTION, DEFAULT_MAX_WAIT, DEFAULT_MAX_IDLE,
- DEFAULT_MIN_IDLE, DEFAULT_TEST_ON_BORROW, DEFAULT_TEST_ON_RETURN, DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
- DEFAULT_NUM_TESTS_PER_EVICTION_RUN, DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, DEFAULT_TEST_WHILE_IDLE);
+ this(factory, new GenericObjectPoolConfig());
}
/**
* Create a new <tt>GenericObjectPool</tt> using the specified values.
* @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
- * @param config a non-<tt>null</tt> {@link GenericObjectPool.Config} describing my configuration
+ * @param config a non-<tt>null</tt> {@link GenericObjectPoolConfig} describing my configuration
*/
- public GenericObjectPool(PoolableObjectFactory<T> factory, GenericObjectPool.Config config) {
- this(factory, config.maxActive, config.whenExhaustedAction, config.maxWait, config.maxIdle, config.minIdle,
- config.testOnBorrow, config.testOnReturn, config.timeBetweenEvictionRunsMillis,
- config.numTestsPerEvictionRun, config.minEvictableIdleTimeMillis, config.testWhileIdle,
- config.softMinEvictableIdleTimeMillis, config.lifo);
- }
-
- /**
- * Create a new <tt>GenericObjectPool</tt> using the specified values.
- * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
- * @param maxActive the maximum number of objects that can be borrowed from me at one time (see {@link #setMaxActive})
- */
- public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive) {
- this(factory, maxActive, DEFAULT_WHEN_EXHAUSTED_ACTION, DEFAULT_MAX_WAIT, DEFAULT_MAX_IDLE, DEFAULT_MIN_IDLE,
- DEFAULT_TEST_ON_BORROW, DEFAULT_TEST_ON_RETURN, DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
- DEFAULT_NUM_TESTS_PER_EVICTION_RUN, DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new <tt>GenericObjectPool</tt> using the specified values.
- * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
- * @param maxActive the maximum number of objects that can be borrowed from me at one time (see {@link #setMaxActive})
- * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #getWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted an and
- * <i>whenExhaustedAction</i> is {@link WhenExhaustedAction#BLOCK} (otherwise ignored) (see {@link #getMaxWait})
- */
- public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction, long maxWait) {
- this(factory, maxActive, whenExhaustedAction, maxWait, DEFAULT_MAX_IDLE, DEFAULT_MIN_IDLE, DEFAULT_TEST_ON_BORROW,
- DEFAULT_TEST_ON_RETURN, DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
- DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new <tt>GenericObjectPool</tt> using the specified values.
- * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
- * @param maxActive the maximum number of objects that can be borrowed at one time (see {@link #setMaxActive})
- * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #getWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted an and
- * <i>whenExhaustedAction</i> is {@link WhenExhaustedAction#BLOCK} (otherwise ignored) (see {@link #getMaxWait})
- * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject} method
- * (see {@link #getTestOnBorrow})
- * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method
- * (see {@link #getTestOnReturn})
- */
- public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction,
- long maxWait, boolean testOnBorrow, boolean testOnReturn) {
- this(factory, maxActive, whenExhaustedAction, maxWait, DEFAULT_MAX_IDLE, DEFAULT_MIN_IDLE, testOnBorrow,
- testOnReturn, DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
- DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new <tt>GenericObjectPool</tt> using the specified values.
- * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
- * @param maxActive the maximum number of objects that can be borrowed at one time (see {@link #setMaxActive})
- * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #getWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <i>whenExhaustedAction</i> is {@link WhenExhaustedAction#BLOCK} (otherwise ignored) (see {@link #getMaxWait})
- * @param maxIdle the maximum number of idle objects in my pool (see {@link #getMaxIdle})
- */
- public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction,
- long maxWait, int maxIdle) {
- this(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, DEFAULT_MIN_IDLE, DEFAULT_TEST_ON_BORROW,
- DEFAULT_TEST_ON_RETURN, DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
- DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new <tt>GenericObjectPool</tt> using the specified values.
- * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
- * @param maxActive the maximum number of objects that can be borrowed at one time (see {@link #setMaxActive})
- * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #getWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <i>whenExhaustedAction</i> is {@link WhenExhaustedAction#BLOCK} (otherwise ignored) (see {@link #getMaxWait})
- * @param maxIdle the maximum number of idle objects in my pool (see {@link #getMaxIdle})
- * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject} method
- * (see {@link #getTestOnBorrow})
- * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method
- * (see {@link #getTestOnReturn})
- */
- public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction,
- long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn) {
- this(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, DEFAULT_MIN_IDLE, testOnBorrow, testOnReturn,
- DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, DEFAULT_NUM_TESTS_PER_EVICTION_RUN,
- DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, DEFAULT_TEST_WHILE_IDLE);
- }
-
- /**
- * Create a new <tt>GenericObjectPool</tt> using the specified values.
- * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
- * @param maxActive the maximum number of objects that can be borrowed at one time (see {@link #setMaxActive})
- * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #setWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <i>whenExhaustedAction</i> is {@link WhenExhaustedAction#BLOCK} (otherwise ignored) (see {@link #setMaxWait})
- * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})
- * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject}
- * method (see {@link #setTestOnBorrow})
- * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method
- * (see {@link #setTestOnReturn})
- * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep between examining idle objects
- * for eviction (see {@link #setTimeBetweenEvictionRunsMillis})
- * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread
- * (if any) (see {@link #setNumTestsPerEvictionRun})
- * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it
- * is eligible for eviction (see {@link #setMinEvictableIdleTimeMillis})
- * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any
- * (see {@link #setTestWhileIdle})
- */
- public GenericObjectPool(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, DEFAULT_MIN_IDLE, testOnBorrow, testOnReturn,
- timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle);
- }
-
- /**
- * Create a new <tt>GenericObjectPool</tt> using the specified values.
- * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
- * @param maxActive the maximum number of objects that can be borrowed at one time (see {@link #setMaxActive})
- * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #setWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <i>whenExhaustedAction</i> is {@link WhenExhaustedAction#BLOCK} (otherwise ignored) (see {@link #setMaxWait})
- * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})
- * @param minIdle the minimum number of idle objects in my pool (see {@link #setMinIdle})
- * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject} method
- * (see {@link #setTestOnBorrow})
- * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method
- * (see {@link #setTestOnReturn})
- * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep between examining idle objects
- * for eviction (see {@link #setTimeBetweenEvictionRunsMillis})
- * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread
- * (if any) (see {@link #setNumTestsPerEvictionRun})
- * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before
- * it is eligible for eviction (see {@link #setMinEvictableIdleTimeMillis})
- * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any
- * (see {@link #setTestWhileIdle})
- */
- public GenericObjectPool(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,
- DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
- }
-
- /**
- * Create a new <tt>GenericObjectPool</tt> using the specified values.
- * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
- * @param maxActive the maximum number of objects that can be borrowed at one time (see {@link #setMaxActive})
- * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #setWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <i>whenExhaustedAction</i> is {@link WhenExhaustedAction#BLOCK} (otherwise ignored) (see {@link #setMaxWait})
- * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})
- * @param minIdle the minimum number of idle objects in my pool (see {@link #setMinIdle})
- * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject}
- * method (see {@link #setTestOnBorrow})
- * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject}
- * method (see {@link #setTestOnReturn})
- * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep between examining idle objects
- * for eviction (see {@link #setTimeBetweenEvictionRunsMillis})
- * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread
- * (if any) (see {@link #setNumTestsPerEvictionRun})
- * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before
- * it is eligible for eviction (see {@link #setMinEvictableIdleTimeMillis})
- * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any
- * (see {@link #setTestWhileIdle})
- * @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.
- * (see {@link #setSoftMinEvictableIdleTimeMillis})
- * @since Pool 1.3
- */
- public GenericObjectPool(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, DEFAULT_LIFO);
- }
-
- /**
- * Create a new <tt>GenericObjectPool</tt> using the specified values.
- * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
- * @param maxActive the maximum number of objects that can be borrowed at one time (see {@link #setMaxActive})
- * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #setWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <i>whenExhaustedAction</i> is {@link WhenExhaustedAction#BLOCK} (otherwise ignored) (see {@link #setMaxWait})
- * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})
- * @param minIdle the minimum number of idle objects in my pool (see {@link #setMinIdle})
- * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject}
- * method (see {@link #setTestOnBorrow})
- * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject}
- * method (see {@link #setTestOnReturn})
- * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep between examining idle
- * objects for eviction (see {@link #setTimeBetweenEvictionRunsMillis})
- * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction
- * thread (if any) (see {@link #setNumTestsPerEvictionRun})
- * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before
- * it is eligible for eviction (see {@link #setMinEvictableIdleTimeMillis})
- * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any
- * (see {@link #setTestWhileIdle})
- * @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. (see {@link #setSoftMinEvictableIdleTimeMillis})
- * @param lifo whether or not objects are returned in last-in-first-out order from the idle object pool
- * (see {@link #setLifo})
- * @throws IllegalArgumentException if the factory is null
- * @since Pool 1.4
- */
- public GenericObjectPool(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) {
+ public GenericObjectPool(PoolableObjectFactory<T> factory, GenericObjectPoolConfig config) {
if (factory == null) {
throw new IllegalArgumentException("factory must not be null");
}
- _factory = factory;
- _maxActive = maxActive;
- _lifo = lifo;
- _whenExhaustedAction = whenExhaustedAction;
- _maxWait = maxWait;
- _maxIdle = maxIdle;
- _minIdle = minIdle;
- _testOnBorrow = testOnBorrow;
- _testOnReturn = testOnReturn;
- _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
- _numTestsPerEvictionRun = numTestsPerEvictionRun;
- _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
- _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
- _testWhileIdle = testWhileIdle;
+ if (config == null) {
+ throw new IllegalArgumentException("config must not be null");
+ }
+ this._factory = factory;
+ this.config = config;
_pool = new CursorableLinkedList<ObjectTimestampPair<T>>();
- startEvictor(_timeBetweenEvictionRunsMillis);
+ startEvictor(config.getTimeBetweenEvictionRunsMillis());
}
//--- public methods ---------------------------------------------
@@ -561,7 +230,7 @@ public class GenericObjectPool<T> extend
* @see #setMaxActive
*/
public synchronized int getMaxActive() {
- return _maxActive;
+ return this.config.getMaxActive();
}
/**
@@ -575,7 +244,7 @@ public class GenericObjectPool<T> extend
* @see #getMaxActive
*/
public synchronized void setMaxActive(int maxActive) {
- _maxActive = maxActive;
+ this.config.setMaxActive(maxActive);
allocate();
}
@@ -588,7 +257,7 @@ public class GenericObjectPool<T> extend
* @see #setWhenExhaustedAction
*/
public synchronized WhenExhaustedAction getWhenExhaustedAction() {
- return _whenExhaustedAction;
+ return this.config.getWhenExhaustedAction();
}
/**
@@ -602,7 +271,7 @@ public class GenericObjectPool<T> extend
* @see #getWhenExhaustedAction
*/
public synchronized void setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
- _whenExhaustedAction = whenExhaustedAction;
+ this.config.setWhenExhaustedAction(whenExhaustedAction);
allocate();
}
@@ -623,7 +292,7 @@ public class GenericObjectPool<T> extend
* @see WhenExhaustedAction#BLOCK
*/
public synchronized long getMaxWait() {
- return _maxWait;
+ return this.config.getMaxWait();
}
/**
@@ -642,7 +311,7 @@ public class GenericObjectPool<T> extend
* @see WhenExhaustedAction#BLOCK
*/
public synchronized void setMaxWait(long maxWait) {
- _maxWait = maxWait;
+ this.config.setMaxWait(maxWait);
allocate();
}
@@ -652,7 +321,7 @@ public class GenericObjectPool<T> extend
* @see #setMaxIdle
*/
public synchronized int getMaxIdle() {
- return _maxIdle;
+ return this.config.getMaxIdle();
}
/**
@@ -669,7 +338,7 @@ public class GenericObjectPool<T> extend
* @see #getMaxIdle
*/
public synchronized void setMaxIdle(int maxIdle) {
- _maxIdle = maxIdle;
+ this.config.setMaxIdle(maxIdle);
allocate();
}
@@ -686,7 +355,7 @@ public class GenericObjectPool<T> extend
* @see #getTimeBetweenEvictionRunsMillis()
*/
public synchronized void setMinIdle(int minIdle) {
- _minIdle = minIdle;
+ this.config.setMinIdle(minIdle);
allocate();
}
@@ -699,7 +368,7 @@ public class GenericObjectPool<T> extend
* @see #setMinIdle
*/
public synchronized int getMinIdle() {
- return _minIdle;
+ return this.config.getMinIdle();
}
/**
@@ -714,7 +383,7 @@ public class GenericObjectPool<T> extend
* @see #setTestOnBorrow
*/
public boolean getTestOnBorrow() {
- return _testOnBorrow;
+ return this.config.getTestOnBorrow();
}
/**
@@ -729,7 +398,7 @@ public class GenericObjectPool<T> extend
* @see #getTestOnBorrow
*/
public void setTestOnBorrow(boolean testOnBorrow) {
- _testOnBorrow = testOnBorrow;
+ this.config.setTestOnBorrow(testOnBorrow);
}
/**
@@ -742,7 +411,7 @@ public class GenericObjectPool<T> extend
* @see #setTestOnReturn
*/
public boolean getTestOnReturn() {
- return _testOnReturn;
+ return this.config.getTestOnReturn();
}
/**
@@ -755,7 +424,7 @@ public class GenericObjectPool<T> extend
* @see #getTestOnReturn
*/
public void setTestOnReturn(boolean testOnReturn) {
- _testOnReturn = testOnReturn;
+ this.config.setTestOnReturn(testOnReturn);
}
/**
@@ -768,7 +437,7 @@ public class GenericObjectPool<T> extend
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized long getTimeBetweenEvictionRunsMillis() {
- return _timeBetweenEvictionRunsMillis;
+ return this.config.getTimeBetweenEvictionRunsMillis();
}
/**
@@ -781,8 +450,8 @@ public class GenericObjectPool<T> extend
* @see #getTimeBetweenEvictionRunsMillis
*/
public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
- _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
- startEvictor(_timeBetweenEvictionRunsMillis);
+ this.config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
+ startEvictor(this.config.getTimeBetweenEvictionRunsMillis());
}
/**
@@ -794,7 +463,7 @@ public class GenericObjectPool<T> extend
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized int getNumTestsPerEvictionRun() {
- return _numTestsPerEvictionRun;
+ return this.config.getNumTestsPerEvictionRun();
}
/**
@@ -812,7 +481,7 @@ public class GenericObjectPool<T> extend
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
- _numTestsPerEvictionRun = numTestsPerEvictionRun;
+ this.config.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
}
/**
@@ -825,7 +494,7 @@ public class GenericObjectPool<T> extend
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized long getMinEvictableIdleTimeMillis() {
- return _minEvictableIdleTimeMillis;
+ return this.config.getMinEvictableIdleTimeMillis();
}
/**
@@ -840,7 +509,7 @@ public class GenericObjectPool<T> extend
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
- _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+ this.config.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
}
/**
@@ -854,7 +523,7 @@ public class GenericObjectPool<T> extend
* @see #setSoftMinEvictableIdleTimeMillis
*/
public synchronized long getSoftMinEvictableIdleTimeMillis() {
- return _softMinEvictableIdleTimeMillis;
+ return this.config.getSoftMinEvictableIdleTimeMillis();
}
/**
@@ -871,7 +540,7 @@ public class GenericObjectPool<T> extend
* @see #getSoftMinEvictableIdleTimeMillis
*/
public synchronized void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {
- _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+ this.config.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis);
}
/**
@@ -885,7 +554,7 @@ public class GenericObjectPool<T> extend
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized boolean getTestWhileIdle() {
- return _testWhileIdle;
+ return this.config.getTestWhileIdle();
}
/**
@@ -899,7 +568,7 @@ public class GenericObjectPool<T> extend
* @see #setTimeBetweenEvictionRunsMillis
*/
public synchronized void setTestWhileIdle(boolean testWhileIdle) {
- _testWhileIdle = testWhileIdle;
+ this.config.setTestWhileIdle(testWhileIdle);
}
/**
@@ -913,7 +582,7 @@ public class GenericObjectPool<T> extend
* @since 1.4
*/
public synchronized boolean getLifo() {
- return _lifo;
+ return this.config.getLifo();
}
/**
@@ -927,7 +596,7 @@ public class GenericObjectPool<T> extend
* @since 1.4
*/
public synchronized void setLifo(boolean lifo) {
- this._lifo = lifo;
+ this.config.setLifo(lifo);
}
/**
@@ -936,20 +605,8 @@ public class GenericObjectPool<T> extend
* @param conf configuration to use.
* @see GenericObjectPool.Config
*/
- public synchronized void setConfig(GenericObjectPool.Config conf) {
- setMaxIdle(conf.maxIdle);
- setMinIdle(conf.minIdle);
- setMaxActive(conf.maxActive);
- setMaxWait(conf.maxWait);
- setWhenExhaustedAction(conf.whenExhaustedAction);
- setTestOnBorrow(conf.testOnBorrow);
- setTestOnReturn(conf.testOnReturn);
- setTestWhileIdle(conf.testWhileIdle);
- setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun);
- setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis);
- setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis);
- setSoftMinEvictableIdleTimeMillis(conf.softMinEvictableIdleTimeMillis);
- setLifo(conf.lifo);
+ public synchronized void setConfig(GenericObjectPoolConfig conf) {
+ this.config = conf;
allocate();
}
@@ -992,8 +649,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 = _whenExhaustedAction;
- maxWait = _maxWait;
+ whenExhaustedAction = this.config.getWhenExhaustedAction();
+ maxWait = this.config.getMaxWait();
// Add this request to the queue
_allocationQueue.add(latch);
@@ -1115,7 +772,7 @@ public class GenericObjectPool<T> extend
// activate & validate the object
try {
_factory.activateObject(latch.getPair().getValue());
- if(_testOnBorrow &&
+ if(this.config.getTestOnBorrow() &&
!_factory.validateObject(latch.getPair().getValue())) {
throw new Exception("ValidateObject failed");
}
@@ -1176,7 +833,7 @@ public class GenericObjectPool<T> extend
// Second utilise any spare capacity to create new objects
for(;;) {
- if((!_allocationQueue.isEmpty()) && (_maxActive < 0 || (_numActive + _numInternalProcessing) < _maxActive)) {
+ if((!_allocationQueue.isEmpty()) && (this.config.getMaxActive() < 0 || (_numActive + _numInternalProcessing) < this.config.getMaxActive())) {
Latch latch = _allocationQueue.removeFirst();
latch.setMayCreate(true);
_numInternalProcessing++;
@@ -1332,7 +989,7 @@ public class GenericObjectPool<T> extend
*/
private void addObjectToPool(T obj, boolean decrementNumActive) throws Exception {
boolean success = true;
- if(_testOnReturn && !(_factory.validateObject(obj))) {
+ if(this.config.getTestOnReturn() && !(_factory.validateObject(obj))) {
success = false;
} else {
_factory.passivateObject(obj);
@@ -1346,12 +1003,12 @@ public class GenericObjectPool<T> extend
if (isClosed()) {
shouldDestroy = true;
} else {
- if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) {
+ if((this.config.getMaxIdle() >= 0) && (_pool.size() >= this.config.getMaxIdle())) {
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 (_lifo) {
+ if (this.getLifo()) {
_pool.addFirst(new ObjectTimestampPair<T>(obj));
} else {
_pool.addLast(new ObjectTimestampPair<T>(obj));
@@ -1421,20 +1078,20 @@ public class GenericObjectPool<T> extend
return;
}
if (null == _evictionCursor) {
- _evictionCursor = (_pool.cursor(_lifo ? _pool.size() : 0));
+ _evictionCursor = (_pool.cursor(this.config.getLifo() ? _pool.size() : 0));
}
}
for (int i=0,m=getNumTests();i<m;i++) {
final ObjectTimestampPair<T> pair;
synchronized (this) {
- if ((_lifo && !_evictionCursor.hasPrevious()) ||
- !_lifo && !_evictionCursor.hasNext()) {
+ if ((this.config.getLifo() && !_evictionCursor.hasPrevious()) ||
+ !this.config.getLifo() && !_evictionCursor.hasNext()) {
_evictionCursor.close();
- _evictionCursor = _pool.cursor(_lifo ? _pool.size() : 0);
+ _evictionCursor = _pool.cursor(this.config.getLifo() ? _pool.size() : 0);
}
- pair = _lifo ? _evictionCursor.previous() : _evictionCursor.next();
+ pair = this.config.getLifo() ? _evictionCursor.previous() : _evictionCursor.next();
_evictionCursor.remove();
_numInternalProcessing++;
@@ -1481,7 +1138,7 @@ public class GenericObjectPool<T> extend
synchronized (this) {
if(!removeObject) {
_evictionCursor.add(pair);
- if (_lifo) {
+ if (this.config.getLifo()) {
// Skip over the element we just added back
_evictionCursor.previous();
}
@@ -1528,7 +1185,7 @@ public class GenericObjectPool<T> extend
*/
private synchronized int calculateDeficit(boolean incrementInternal) {
int objectDeficit = getMinIdle() - getNumIdle();
- if (_maxActive > 0) {
+ if (this.config.getMaxActive() > 0) {
int growLimit = Math.max(0,
getMaxActive() - getNumActive() - getNumIdle() - _numInternalProcessing);
objectDeficit = Math.min(objectDeficit, growLimit);
@@ -1607,10 +1264,11 @@ public class GenericObjectPool<T> extend
* @return the number of tests for the Evictor to run
*/
private int getNumTests() {
- if(_numTestsPerEvictionRun >= 0) {
- return Math.min(_numTestsPerEvictionRun, _pool.size());
+ int numTestsPerEvictionRun = this.config.getNumTestsPerEvictionRun();
+ if(numTestsPerEvictionRun >= 0) {
+ return Math.min(numTestsPerEvictionRun, _pool.size());
} else {
- return(int)(Math.ceil(_pool.size()/Math.abs((double)_numTestsPerEvictionRun)));
+ return(int)(Math.ceil(_pool.size()/Math.abs((double)numTestsPerEvictionRun)));
}
}
@@ -1645,172 +1303,6 @@ public class GenericObjectPool<T> extend
}
/**
- * A simple "struct" encapsulating the
- * configuration information for a {@link GenericObjectPool}.
- * @see GenericObjectPool#GenericObjectPool(org.apache.commons.pool2.PoolableObjectFactory,
- * org.apache.commons.pool2.impl.GenericObjectPool.Config)
- * @see GenericObjectPool#setConfig
- */
- public static class Config {
- /**
- * @see GenericObjectPool#setMaxIdle
- */
- private int maxIdle = GenericObjectPool.DEFAULT_MAX_IDLE;
- /**
- * @see GenericObjectPool#setMinIdle
- */
- private int minIdle = GenericObjectPool.DEFAULT_MIN_IDLE;
- /**
- * @see GenericObjectPool#setMaxActive
- */
- private int maxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE;
- /**
- * @see GenericObjectPool#setMaxWait
- */
- private long maxWait = GenericObjectPool.DEFAULT_MAX_WAIT;
- /**
- * @see GenericObjectPool#setWhenExhaustedAction
- */
- private WhenExhaustedAction whenExhaustedAction = GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
- /**
- * @see GenericObjectPool#setTestOnBorrow
- */
- private boolean testOnBorrow = GenericObjectPool.DEFAULT_TEST_ON_BORROW;
- /**
- * @see GenericObjectPool#setTestOnReturn
- */
- private boolean testOnReturn = GenericObjectPool.DEFAULT_TEST_ON_RETURN;
- /**
- * @see GenericObjectPool#setTestWhileIdle
- */
- private boolean testWhileIdle = GenericObjectPool.DEFAULT_TEST_WHILE_IDLE;
- /**
- * @see GenericObjectPool#setTimeBetweenEvictionRunsMillis
- */
- private long timeBetweenEvictionRunsMillis = GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
- /**
- * @see GenericObjectPool#setNumTestsPerEvictionRun
- */
- private int numTestsPerEvictionRun = GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
- /**
- * @see GenericObjectPool#setMinEvictableIdleTimeMillis
- */
- private long minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
- /**
- * @see GenericObjectPool#setSoftMinEvictableIdleTimeMillis
- */
- private long softMinEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
- /**
- * @see GenericObjectPool#setLifo
- */
- private boolean lifo = GenericObjectPool.DEFAULT_LIFO;
-
- public int getMaxIdle() {
- return maxIdle;
- }
-
- public void setMaxIdle(int maxIdle) {
- this.maxIdle = maxIdle;
- }
-
- public int getMinIdle() {
- return minIdle;
- }
-
- public void setMinIdle(int minIdle) {
- this.minIdle = minIdle;
- }
-
- public int getMaxActive() {
- return maxActive;
- }
-
- public void setMaxActive(int maxActive) {
- this.maxActive = maxActive;
- }
-
- public long getMaxWait() {
- return maxWait;
- }
-
- public void setMaxWait(long maxWait) {
- this.maxWait = maxWait;
- }
-
- public WhenExhaustedAction getWhenExhaustedAction() {
- return whenExhaustedAction;
- }
-
- public void setWhenExhaustedAction(WhenExhaustedAction whenExhaustedAction) {
- this.whenExhaustedAction = whenExhaustedAction;
- }
-
- public boolean getTestOnBorrow() {
- return testOnBorrow;
- }
-
- public void setTestOnBorrow(boolean testOnBorrow) {
- this.testOnBorrow = testOnBorrow;
- }
-
- public boolean getTestOnReturn() {
- return testOnReturn;
- }
-
- public void setTestOnReturn(boolean testOnReturn) {
- this.testOnReturn = testOnReturn;
- }
-
- public boolean getTestWhileIdle() {
- return testWhileIdle;
- }
-
- public void setTestWhileIdle(boolean testWhileIdle) {
- this.testWhileIdle = testWhileIdle;
- }
-
- public long getTimeBetweenEvictionRunsMillis() {
- return timeBetweenEvictionRunsMillis;
- }
-
- public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
- this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
- }
-
- public int getNumTestsPerEvictionRun() {
- return numTestsPerEvictionRun;
- }
-
- public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
- this.numTestsPerEvictionRun = numTestsPerEvictionRun;
- }
-
- public long getMinEvictableIdleTimeMillis() {
- return minEvictableIdleTimeMillis;
- }
-
- public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
- this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
- }
-
- public long getSoftMinEvictableIdleTimeMillis() {
- return softMinEvictableIdleTimeMillis;
- }
-
- public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {
- this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
- }
-
- public boolean getLifo() {
- return lifo;
- }
-
- public void setLifo(boolean lifo) {
- this.lifo = lifo;
- }
- }
-
- /**
* Latch used to control allocation order of objects to threads to ensure
* fairness. That is, objects are allocated to threads in the order that
* threads request objects.
@@ -1868,151 +1360,8 @@ public class GenericObjectPool<T> extend
//--- private attributes ---------------------------------------
- /**
- * The cap on the number of idle instances in the pool.
- * @see #setMaxIdle
- * @see #getMaxIdle
- */
- private int _maxIdle = DEFAULT_MAX_IDLE;
-
- /**
- * The cap on the minimum number of idle instances in the pool.
- * @see #setMinIdle
- * @see #getMinIdle
- */
- private int _minIdle = DEFAULT_MIN_IDLE;
-
- /**
- * The cap on the total number of active instances from the pool.
- * @see #setMaxActive
- * @see #getMaxActive
- */
- private int _maxActive = DEFAULT_MAX_ACTIVE;
-
- /**
- * The maximum amount of time (in millis) 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}.
- *
- * When less than or equal to 0, the {@link #borrowObject} method
- * may block indefinitely.
- *
- * @see #setMaxWait
- * @see #getMaxWait
- * @see WhenExhaustedAction#BLOCK
- * @see #setWhenExhaustedAction
- * @see #getWhenExhaustedAction
- */
- private long _maxWait = DEFAULT_MAX_WAIT;
-
- /**
- * The action to take when the {@link #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
- * @see #getWhenExhaustedAction
- */
- private WhenExhaustedAction _whenExhaustedAction = DEFAULT_WHEN_EXHAUSTED_ACTION;
-
- /**
- * When <tt>true</tt>, objects will be
- * {@link PoolableObjectFactory#validateObject validated}
- * before being returned by the {@link #borrowObject}
- * method. If the object fails to validate,
- * it will be dropped from the pool, and we will attempt
- * to borrow another.
- *
- * @see #setTestOnBorrow
- * @see #getTestOnBorrow
- */
- private volatile boolean _testOnBorrow = DEFAULT_TEST_ON_BORROW;
-
- /**
- * When <tt>true</tt>, objects will be
- * {@link PoolableObjectFactory#validateObject validated}
- * before being returned to the pool within the
- * {@link #returnObject}.
- *
- * @see #getTestOnReturn
- * @see #setTestOnReturn
- */
- private volatile boolean _testOnReturn = DEFAULT_TEST_ON_RETURN;
-
- /**
- * When <tt>true</tt>, objects will be
- * {@link PoolableObjectFactory#validateObject validated}
- * by the idle object evictor (if any). If an object
- * fails to validate, it will be dropped from the pool.
- *
- * @see #setTestWhileIdle
- * @see #getTestWhileIdle
- * @see #getTimeBetweenEvictionRunsMillis
- * @see #setTimeBetweenEvictionRunsMillis
- */
- private boolean _testWhileIdle = DEFAULT_TEST_WHILE_IDLE;
-
- /**
- * The number of milliseconds to sleep between runs of the
- * idle object evictor thread.
- * When non-positive, no idle object evictor thread will be
- * run.
- *
- * @see #setTimeBetweenEvictionRunsMillis
- * @see #getTimeBetweenEvictionRunsMillis
- */
- private long _timeBetweenEvictionRunsMillis = DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
-
- /**
- * 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 #getNumTestsPerEvictionRun
- * @see #getTimeBetweenEvictionRunsMillis
- * @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 #getMinEvictableIdleTimeMillis
- * @see #getTimeBetweenEvictionRunsMillis
- * @see #setTimeBetweenEvictionRunsMillis
- */
- private long _minEvictableIdleTimeMillis = DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
-
- /**
- * 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
- * @see #getSoftMinEvictableIdleTimeMillis
- */
- private long _softMinEvictableIdleTimeMillis = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
-
- /** Whether or not the pool behaves as a LIFO queue (last in first out) */
- private boolean _lifo = DEFAULT_LIFO;
+ /** Pool configuration */
+ private GenericObjectPoolConfig config;
/** My pool. */
private CursorableLinkedList<ObjectTimestampPair<T>> _pool = null;
Added: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java?rev=1027112&view=auto
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java (added)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java Mon Oct 25 13:35:44 2010
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+/**
+ * Configuration class for {@link GenericObjectPool} and {@link GenericObjectPoolFactory} instances.
+ *
+ * @since Pool 2.0
+ * @version $Revision$ $Date$
+ */
+public class GenericObjectPoolConfig extends AbstractGenericObjectPoolConfig {
+
+ /**
+ * The default value for {@link #getSoftMinEvictableIdleTimeMillis}.
+ *
+ * @see #getSoftMinEvictableIdleTimeMillis
+ * @see #setSoftMinEvictableIdleTimeMillis
+ */
+ public static final long DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS = -1;
+
+ /**
+ * 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
+ * @see #getSoftMinEvictableIdleTimeMillis
+ */
+ private long softMinEvictableIdleTimeMillis = DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+
+ public final synchronized long getSoftMinEvictableIdleTimeMillis() {
+ return softMinEvictableIdleTimeMillis;
+ }
+
+ public final synchronized void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {
+ this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+ }
+
+}
Propchange: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericObjectPoolConfig.java
------------------------------------------------------------------------------
svn:mime-type = text/plain