You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2011/06/03 17:23:30 UTC
svn commit: r1131071 [1/2] - in /commons/proper/pool/trunk/src:
java/org/apache/commons/pool2/ java/org/apache/commons/pool2/impl/
test/org/apache/commons/pool2/ test/org/apache/commons/pool2/impl/
Author: markt
Date: Fri Jun 3 15:23:29 2011
New Revision: 1131071
URL: http://svn.apache.org/viewvc?rev=1131071&view=rev
Log:
KeyedObjectPool re-factoring
- remove deprecation of setFactory
- rename maxActive to maxTotalPerKey
- remove default constants from pool impl (they are in the config class)
- remove internal config class from pool impl
- use config to simplify constructors
- make factory immutable once set
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/KeyedObjectPool.java
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestGenericKeyedObjectPoolFactory.java
Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/KeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/KeyedObjectPool.java?rev=1131071&r1=1131070&r2=1131071&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/KeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/KeyedObjectPool.java Fri Jun 3 15:23:29 2011
@@ -219,15 +219,11 @@ public interface KeyedObjectPool<K,V> {
/**
* Sets the {@link KeyedPoolableObjectFactory factory} the pool uses
* to create new instances (optional operation).
- * Trying to change the <code>factory</code> after a pool has been used will frequently
- * throw an {@link UnsupportedOperationException}. It is up to the pool
- * implementation to determine when it is acceptable to call this method.
+ * Once set, the factory cannot be changed.
*
* @param factory the {@link KeyedPoolableObjectFactory} used to create new instances.
- * @throws IllegalStateException when the factory cannot be set at this time
+ * @throws IllegalStateException when the factory has already been set
* @throws UnsupportedOperationException when this implementation doesn't support the operation
- * @deprecated to be removed in pool 2.0
*/
- @Deprecated
void setFactory(KeyedPoolableObjectFactory<K,V> factory) throws IllegalStateException, UnsupportedOperationException;
}
Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1131071&r1=1131070&r2=1131071&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java Fri Jun 3 15:23:29 2011
@@ -53,10 +53,10 @@ import org.apache.commons.pool2.PoolUtil
* parameters:</p>
* <ul>
* <li>
- * {@link #setMaxActive maxActive} controls the maximum number of objects
+ * {@link #setMaxTotalPerKey maxTotalPerKey} controls the maximum number of objects
* (per key) that can allocated by the pool (checked out to client threads,
* or idle in the pool) at one time. When non-positive, there is no limit
- * to the number of objects per key. When {@link #setMaxActive maxActive} is
+ * to the number of objects per key. When {@link #setMaxTotalPerKey maxTotalPerKey} is
* reached, the keyed pool is said to be exhausted. The default setting for
* this parameter is 8.
* </li>
@@ -90,7 +90,7 @@ import org.apache.commons.pool2.PoolUtil
* <li>
* When {@link #setWhenExhaustedAction whenExhaustedAction} is
* {@link #WHEN_EXHAUSTED_GROW}, {@link #borrowObject borrowObject} will create a new
- * object and return it (essentially making {@link #setMaxActive maxActive}
+ * object and return it (essentially making {@link #setMaxTotalPerKey maxTotalPerKey}
* meaningless.)
* </li>
* <li>
@@ -209,390 +209,47 @@ import org.apache.commons.pool2.PoolUtil
*/
public class GenericKeyedObjectPool<K,T> extends BaseKeyedObjectPool<K,T> {
- //--- public constants -------------------------------------------
-
- /**
- * The default cap on the number of idle instances (per key) in the pool.
- * @see #getMaxIdle
- * @see #setMaxIdle
- */
- public static final int DEFAULT_MAX_IDLE = 8;
-
- /**
- * The default cap on the total number of active instances (per key)
- * from the pool.
- * @see #getMaxActive
- * @see #setMaxActive
- */
- public static final int DEFAULT_MAX_ACTIVE = 8;
-
- /**
- * The default cap on the the overall maximum number of objects that can
- * exist at one time.
- * @see #getMaxTotal
- * @see #setMaxTotal
- */
- public static final int DEFAULT_MAX_TOTAL = -1;
-
- /**
- * The default "when exhausted action" for the pool.
- * @see #setWhenExhaustedAction
- */
- public static final WhenExhaustedAction DEFAULT_WHEN_EXHAUSTED_ACTION =
- WhenExhaustedAction.BLOCK;
-
- /**
- * 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 #WHEN_EXHAUSTED_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 minimum level of idle objects in the pool.
- * @since Pool 1.3
- * @see #setMinIdle
- * @see #getMinIdle
- */
- public static final int DEFAULT_MIN_IDLE = 0;
-
- /**
- * The default LIFO status. True means that borrowObject returns the
- * most recently used ("last in") idle object in a pool (if there are
- * idle instances available). False means that pools behave as FIFO
- * queues - objects are taken from idle object pools in the order that
- * they are returned.
- * @see #setLifo
- */
- public static final boolean DEFAULT_LIFO = true;
-
//--- constructors -----------------------------------------------
/**
- * Create a new <code>GenericKeyedObjectPool</code> with no factory.
- *
- * @see #GenericKeyedObjectPool(KeyedPoolableObjectFactory)
- * @see #setFactory(KeyedPoolableObjectFactory)
+ * Create a new <code>GenericKeyedObjectPool</code> using defaults and no
+ * factory.
*/
public GenericKeyedObjectPool() {
- this(null, DEFAULT_MAX_ACTIVE, DEFAULT_WHEN_EXHAUSTED_ACTION, DEFAULT_MAX_WAIT, DEFAULT_MAX_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 <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy
- * objects if not <code>null</code>
- */
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> factory) {
- this(factory, DEFAULT_MAX_ACTIVE, DEFAULT_WHEN_EXHAUSTED_ACTION, DEFAULT_MAX_WAIT, DEFAULT_MAX_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 <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects
- * if not <code>null</code>
- * @param config a non-<code>null</code> {@link GenericKeyedObjectPool.Config} describing the configuration
- */
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> factory, GenericKeyedObjectPool.Config config) {
- this(factory, config.maxActive, config.whenExhaustedAction, config.maxWait, config.maxIdle, config.maxTotal,
- config.minIdle, config.testOnBorrow, config.testOnReturn, config.timeBetweenEvictionRunsMillis,
- config.numTestsPerEvictionRun, config.minEvictableIdleTimeMillis, config.testWhileIdle, config.lifo);
- }
-
- /**
- * Create a new <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects
- * if not <code>null</code>
- * @param maxActive the maximum number of objects that can be borrowed from me at one time (see {@link #setMaxActive})
- */
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> factory, int maxActive) {
- this(factory,maxActive, DEFAULT_WHEN_EXHAUSTED_ACTION, DEFAULT_MAX_WAIT, DEFAULT_MAX_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 <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects
- * if not <code>null</code>
- * @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 #setWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <code>whenExhaustedAction</code> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})
- */
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction,
- long maxWait) {
- this(factory, maxActive, whenExhaustedAction, maxWait, DEFAULT_MAX_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 <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects
- * if not <code>null</code>
- * @param maxActive the maximum number of objects that can be borrowed from me at one time (see {@link #setMaxActive})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <code>whenExhaustedAction</code> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})
- * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #setWhenExhaustedAction})
- * @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})
- */
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction,
- long maxWait, boolean testOnBorrow, boolean testOnReturn) {
- this(factory, maxActive, whenExhaustedAction, maxWait, DEFAULT_MAX_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 <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects
- * if not <code>null</code>
- * @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 #setWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <code>whenExhaustedAction</code> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})
- * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})
- */
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction,
- long maxWait, int maxIdle) {
- this(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, 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 <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects
- * if not <code>null</code>
- * @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 #setWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <code>whenExhaustedAction</code> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #getMaxWait})
- * @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})
- */
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> factory, int maxActive, WhenExhaustedAction whenExhaustedAction,
- long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn) {
- this(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, 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 <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects
- * if not <code>null</code>
- * @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 #setWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <code>whenExhaustedAction</code> is {@link #WHEN_EXHAUSTED_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 GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,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, GenericKeyedObjectPool.DEFAULT_MAX_TOTAL,
- testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
- minEvictableIdleTimeMillis, testWhileIdle);
- }
-
- /**
- * Create a new <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects
- * if not <code>null</code>
- * @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 #setWhenExhaustedAction})
- * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted and
- * <code>whenExhaustedAction</code> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})
- * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})
- * @param maxTotal the maximum number of objects that can exists at one time (see {@link #setMaxTotal})
- * @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 GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> 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 <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects
- * if not <code>null</code>
- * @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
- * <code>whenExhaustedAction</code> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})
- * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})
- * @param maxTotal the maximum number of objects that can exists at one time (see {@link #setMaxTotal})
- * @param minIdle the minimum number of idle objects to have in the pool at any one time (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})
- * @since Pool 1.3
- */
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> 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,
- DEFAULT_LIFO);
+ this(new GenericKeyedObjectPoolConfig<K, T>());
}
/**
- * Create a new <code>GenericKeyedObjectPool</code> using the specified values.
- * @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy objects
- * if not <code>null</code>
- * @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
- * <code>whenExhaustedAction</code> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})
- * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})
- * @param maxTotal the maximum number of objects that can exists at one time (see {@link #setMaxTotal})
- * @param minIdle the minimum number of idle objects to have in the pool at any one time (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 lifo whether or not the pools behave as LIFO (last in first out) queues (see {@link #setLifo})
- * @since Pool 1.4
- */
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,T> 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) {
- _factory = factory;
- _maxActive = maxActive;
- _lifo = lifo;
- _whenExhaustedAction = whenExhaustedAction;
- _maxWait = maxWait;
- _maxIdle = maxIdle;
- _maxTotal = maxTotal;
- _minIdle = minIdle;
- _testOnBorrow = testOnBorrow;
- _testOnReturn = testOnReturn;
- _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
- _numTestsPerEvictionRun = numTestsPerEvictionRun;
- _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
- _testWhileIdle = testWhileIdle;
+ * Create a new <code>GenericKeyedObjectPool</code> using a specific
+ * configuration.
+ *
+ * @param config The configuration to use for this pool instance. The
+ * configuration is used by value. Subsequent changes to
+ * the configuration object will not be reflected in the
+ * pool.
+ */
+ public GenericKeyedObjectPool(GenericKeyedObjectPoolConfig<K,T> config) {
+ // Copy the settings from the config
+ this._factory = config.getFactory();
+ this._lifo = config.getLifo();
+ this._maxIdle = config.getMaxIdle();
+ this._maxTotal = config.getMaxTotal();
+ this._maxTotalPerKey = config.getMaxTotalPerKey();
+ this._maxWait = config.getMaxWait();
+ this._minEvictableIdleTimeMillis =
+ config.getMinEvictableIdleTimeMillis();
+ this._minIdle = config.getMinIdle();
+ this._numTestsPerEvictionRun = config.getNumTestsPerEvictionRun();
+ this._testOnBorrow = config.getTestOnBorrow();
+ this._testOnReturn = config.getTestOnReturn();
+ this._testWhileIdle = config.getTestWhileIdle();
+ this._timeBetweenEvictionRunsMillis =
+ config.getTimeBetweenEvictionRunsMillis();
+ this._whenExhaustedAction = config.getWhenExhaustedAction();
- startEvictor(_timeBetweenEvictionRunsMillis);
+ startEvictor(getMinEvictableIdleTimeMillis());
}
- //--- public methods ---------------------------------------------
-
//--- configuration methods --------------------------------------
/**
@@ -601,21 +258,21 @@ public class GenericKeyedObjectPool<K,T>
* A negative value indicates no limit.
*
* @return the cap on the number of active instances per key.
- * @see #setMaxActive
+ * @see #setMaxTotalPerKey
*/
- public int getMaxActive() {
- return _maxActive;
+ public int getMaxTotalPerKey() {
+ return _maxTotalPerKey;
}
/**
* Sets the cap on the number of object instances managed by the pool per key.
- * @param maxActive The cap on the number of object instances per key.
+ * @param maxTotalPerKey The cap on the number of object instances per key.
* Use a negative value for no limit.
*
- * @see #getMaxActive
+ * @see #getMaxTotalPerKey
*/
- public void setMaxActive(int maxActive) {
- _maxActive = maxActive;
+ public void setMaxTotalPerKey(int maxTotalPerKey) {
+ _maxTotalPerKey = maxTotalPerKey;
}
/**
@@ -940,19 +597,19 @@ public class GenericKeyedObjectPool<K,T>
* @param conf the new configuration to use.
* @see GenericKeyedObjectPool.Config
*/
- public void setConfig(GenericKeyedObjectPool.Config conf) {
- setMaxIdle(conf.maxIdle);
- setMaxActive(conf.maxActive);
- setMaxTotal(conf.maxTotal);
- setMinIdle(conf.minIdle);
- setMaxWait(conf.maxWait);
- setWhenExhaustedAction(conf.whenExhaustedAction);
- setTestOnBorrow(conf.testOnBorrow);
- setTestOnReturn(conf.testOnReturn);
- setTestWhileIdle(conf.testWhileIdle);
- setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun);
- setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis);
- setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis);
+ public void setConfig(GenericKeyedObjectPoolConfig<K,T> conf) {
+ setMaxIdle(conf.getMaxIdle());
+ setMaxTotalPerKey(conf.getMaxTotalPerKey());
+ setMaxTotal(conf.getMaxTotal());
+ setMinIdle(conf.getMinIdle());
+ setMaxWait(conf.getMaxWait());
+ setWhenExhaustedAction(conf.getWhenExhaustedAction());
+ setTestOnBorrow(conf.getTestOnBorrow());
+ setTestOnReturn(conf.getTestOnReturn());
+ setTestWhileIdle(conf.getTestWhileIdle());
+ setNumTestsPerEvictionRun(conf.getNumTestsPerEvictionRun());
+ setMinEvictableIdleTimeMillis(conf.getMinEvictableIdleTimeMillis());
+ setTimeBetweenEvictionRunsMillis(conf.getTimeBetweenEvictionRunsMillis());
}
/**
@@ -996,15 +653,15 @@ public class GenericKeyedObjectPool<K,T>
* are no more idle instances available.</p>
*
* <p>If there are no idle instances available in the pool associated with the given key, behavior
- * depends on the {@link #getMaxActive() maxActive}, {@link #getMaxTotal() maxTotal}, and (if applicable)
+ * depends on the {@link #getMaxTotalPerKey() maxTotalPerKey}, {@link #getMaxTotal() maxTotal}, and (if applicable)
* {@link #getWhenExhaustedAction() whenExhaustedAction} and {@link #getMaxWait() maxWait} properties. If the
- * number of instances checked out from the pool under the given key is less than <code>maxActive</code> and
+ * number of instances checked out from the pool under the given key is less than <code>maxTotalPerKey</code> and
* the total number of instances in circulation (under all keys) is less than <code>maxTotal</code>, a new instance
* is created, activated and (if applicable) validated and returned to the caller.</p>
*
* <p>If the associated keyed pool is exhausted (no available idle instances and no capacity to create new ones),
* this method will either block ({@link #WHEN_EXHAUSTED_BLOCK}), throw a <code>NoSuchElementException</code>
- * ({@link #WHEN_EXHAUSTED_FAIL}), or grow ({@link #WHEN_EXHAUSTED_GROW} - ignoring maxActive, maxTotal properties).
+ * ({@link #WHEN_EXHAUSTED_FAIL}), or grow ({@link #WHEN_EXHAUSTED_GROW} - ignoring maxTotalPerKey, maxTotal properties).
* The length of time that this method will block when <code>whenExhaustedAction == WHEN_EXHAUSTED_BLOCK</code>
* is determined by the {@link #getMaxWait() maxWait} property.</p>
*
@@ -1362,23 +1019,27 @@ public class GenericKeyedObjectPool<K,T>
/**
* <p>Sets the keyed poolable object factory associated with this pool.</p>
*
- * <p>If this method is called when objects are checked out of any of the keyed pools,
- * an IllegalStateException is thrown. Calling this method also has the side effect of
- * destroying any idle instances in existing keyed pools, using the original factory.</p>
+ * <p>If this method is called when the factory has previously been set an
+ * IllegalStateException is thrown.</p>
*
- * @param factory KeyedPoolableObjectFactory to use when creating keyed object pool instances
- * @throws IllegalStateException if there are active (checked out) instances associated with this keyed object pool
- * @deprecated to be removed in version 2.0
+ * @param factory KeyedPoolableObjectFactory to use when creating keyed
+ * object pool instances
+ * @throws IllegalStateException if the factory has already been set
*/
@Override
- @Deprecated
- public void setFactory(KeyedPoolableObjectFactory<K,T> factory) throws IllegalStateException {
- assertOpen();
- if (0 < getNumActive()) {
- throw new IllegalStateException("Objects are already active");
+ public void setFactory(KeyedPoolableObjectFactory<K,T> factory)
+ throws IllegalStateException {
+ if (this._factory == null) {
+ synchronized (factoryLock) {
+ if (this._factory == null) {
+ this._factory = factory;
+ } else {
+ throw new IllegalStateException("Factory already set");
+ }
+ }
+ } else {
+ throw new IllegalStateException("Factory already set");
}
- clear();
- _factory = factory;
}
@@ -1546,7 +1207,7 @@ public class GenericKeyedObjectPool<K,T>
private PooledObject<T> create(K key) throws Exception {
- int maxActive = getMaxActive(); // Per key
+ int maxTotalPerKey = getMaxTotalPerKey(); // Per key
int maxTotal = getMaxTotal(); // All keys
// Check against the overall limit
@@ -1570,7 +1231,7 @@ public class GenericKeyedObjectPool<K,T>
long newCreateCount = objectDeque.getCreateCount().incrementAndGet();
// Check against the per key limit
- if (maxActive > -1 && newCreateCount > maxActive ||
+ if (maxTotalPerKey > -1 && newCreateCount > maxTotalPerKey ||
newCreateCount > Integer.MAX_VALUE) {
numTotal.decrementAndGet();
return null;
@@ -1730,8 +1391,7 @@ public class GenericKeyedObjectPool<K,T>
* <p>Calls {@link #allocate()} on successful completion</p>
*
* @param key pool key
- * @param obj instance to add to the keyed pool
- * @param decrementNumActive whether or not to decrement the active count associated with the keyed pool
+ * @param p instance to add to the keyed pool
* @throws Exception
*/
private void addIdleObject(K key, PooledObject<T> p) throws Exception {
@@ -1842,7 +1502,7 @@ public class GenericKeyedObjectPool<K,T>
/**
* This returns the number of objects to create during the pool
* sustain cycle. This will ensure that the minimum number of idle
- * instances is maintained without going past the maxActive value.
+ * instances is maintained without going past the maxTotalPerKey value.
*
* @param pool the ObjectPool to calculate the deficit for
* @return The number of objects to be created
@@ -1854,12 +1514,12 @@ public class GenericKeyedObjectPool<K,T>
}
int objectDefecit = 0;
- //Calculate no of objects needed to be created, in order to have
- //the number of pooled objects < maxActive();
+ // Calculate no of objects needed to be created, in order to have
+ // the number of pooled objects < maxTotalPerKey();
objectDefecit = getMinIdle() - objectDeque.getIdleObjects().size();
- if (getMaxActive() > 0) {
+ if (getMaxTotalPerKey() > 0) {
int growLimit = Math.max(0,
- getMaxActive() - objectDeque.getIdleObjects().size());
+ getMaxTotalPerKey() - objectDeque.getIdleObjects().size());
objectDefecit = Math.min(objectDefecit, growLimit);
}
@@ -1935,70 +1595,6 @@ public class GenericKeyedObjectPool<K,T>
}
}
- /**
- * A simple "struct" encapsulating the
- * configuration information for a <code>GenericKeyedObjectPool</code>.
- * @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory,GenericKeyedObjectPool.Config)
- * @see GenericKeyedObjectPool#setConfig
- */
- public static class Config {
- //CHECKSTYLE: stop VisibilityModifier
- /**
- * @see GenericKeyedObjectPool#setMaxIdle
- */
- public int maxIdle = GenericKeyedObjectPool.DEFAULT_MAX_IDLE;
- /**
- * @see GenericKeyedObjectPool#setMaxActive
- */
- public int maxActive = GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE;
- /**
- * @see GenericKeyedObjectPool#setMaxTotal
- */
- public int maxTotal = GenericKeyedObjectPool.DEFAULT_MAX_TOTAL;
- /**
- * @see GenericKeyedObjectPool#setMinIdle
- */
- public int minIdle = GenericKeyedObjectPool.DEFAULT_MIN_IDLE;
- /**
- * @see GenericKeyedObjectPool#setMaxWait
- */
- public long maxWait = GenericKeyedObjectPool.DEFAULT_MAX_WAIT;
- /**
- * @see GenericKeyedObjectPool#setWhenExhaustedAction
- */
- public WhenExhaustedAction whenExhaustedAction = GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
- /**
- * @see GenericKeyedObjectPool#setTestOnBorrow
- */
- public boolean testOnBorrow = GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW;
- /**
- * @see GenericKeyedObjectPool#setTestOnReturn
- */
- public boolean testOnReturn = GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN;
- /**
- * @see GenericKeyedObjectPool#setTestWhileIdle
- */
- public boolean testWhileIdle = GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE;
- /**
- * @see GenericKeyedObjectPool#setTimeBetweenEvictionRunsMillis
- */
- public long timeBetweenEvictionRunsMillis = GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
- /**
- * @see GenericKeyedObjectPool#setNumTestsPerEvictionRun
- */
- public int numTestsPerEvictionRun = GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
- /**
- * @see GenericKeyedObjectPool#setMinEvictableIdleTimeMillis
- */
- public long minEvictableIdleTimeMillis = GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
- /**
- * @see GenericKeyedObjectPool#setLifo
- */
- public boolean lifo = GenericKeyedObjectPool.DEFAULT_LIFO;
- //CHECKSTYLE: resume VisibilityModifier
- }
-
-
//--- protected attributes ---------------------------------------
/**
@@ -2006,28 +1602,30 @@ public class GenericKeyedObjectPool<K,T>
* @see #setMaxIdle
* @see #getMaxIdle
*/
- private int _maxIdle = DEFAULT_MAX_IDLE;
+ private int _maxIdle = GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE;
/**
* The minimum no of idle objects to keep in the pool.
* @see #setMinIdle
* @see #getMinIdle
*/
- private volatile int _minIdle = DEFAULT_MIN_IDLE;
+ private volatile int _minIdle =
+ GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE;
/**
* The cap on the number of active instances from the pool.
- * @see #setMaxActive
- * @see #getMaxActive
+ * @see #setMaxTotalPerKey
+ * @see #getMaxTotalPerKey
*/
- private int _maxActive = DEFAULT_MAX_ACTIVE;
+ private int _maxTotalPerKey =
+ GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY;
/**
* The cap on the total number of instances from the pool if non-positive.
* @see #setMaxTotal
* @see #getMaxTotal
*/
- private int _maxTotal = DEFAULT_MAX_TOTAL;
+ private int _maxTotal = GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL;
/**
* The maximum amount of time (in millis) the
@@ -2045,7 +1643,7 @@ public class GenericKeyedObjectPool<K,T>
* @see #setWhenExhaustedAction
* @see #getWhenExhaustedAction
*/
- private long _maxWait = DEFAULT_MAX_WAIT;
+ private long _maxWait = GenericKeyedObjectPoolConfig.DEFAULT_MAX_WAIT;
/**
* The action to take when the {@link #borrowObject} method
@@ -2056,7 +1654,8 @@ public class GenericKeyedObjectPool<K,T>
* @see #setWhenExhaustedAction
* @see #getWhenExhaustedAction
*/
- private WhenExhaustedAction _whenExhaustedAction = DEFAULT_WHEN_EXHAUSTED_ACTION;
+ private WhenExhaustedAction _whenExhaustedAction =
+ GenericKeyedObjectPoolConfig.DEFAULT_WHEN_EXHAUSTED_ACTION;
/**
* When <code>true</code>, objects will be
@@ -2069,7 +1668,8 @@ public class GenericKeyedObjectPool<K,T>
* @see #setTestOnBorrow
* @see #getTestOnBorrow
*/
- private volatile boolean _testOnBorrow = DEFAULT_TEST_ON_BORROW;
+ private volatile boolean _testOnBorrow =
+ GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_BORROW;
/**
* When <code>true</code>, objects will be
@@ -2080,7 +1680,8 @@ public class GenericKeyedObjectPool<K,T>
* @see #getTestOnReturn
* @see #setTestOnReturn
*/
- private volatile boolean _testOnReturn = DEFAULT_TEST_ON_RETURN;
+ private volatile boolean _testOnReturn =
+ GenericKeyedObjectPoolConfig.DEFAULT_TEST_ON_RETURN;
/**
* When <code>true</code>, objects will be
@@ -2093,7 +1694,8 @@ public class GenericKeyedObjectPool<K,T>
* @see #getTimeBetweenEvictionRunsMillis
* @see #setTimeBetweenEvictionRunsMillis
*/
- private boolean _testWhileIdle = DEFAULT_TEST_WHILE_IDLE;
+ private boolean _testWhileIdle =
+ GenericKeyedObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE;
/**
* The number of milliseconds to sleep between runs of the
@@ -2104,7 +1706,8 @@ public class GenericKeyedObjectPool<K,T>
* @see #setTimeBetweenEvictionRunsMillis
* @see #getTimeBetweenEvictionRunsMillis
*/
- private long _timeBetweenEvictionRunsMillis = DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
+ private long _timeBetweenEvictionRunsMillis =
+ GenericKeyedObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
/**
* The number of objects to examine during each run of the
@@ -2119,7 +1722,8 @@ public class GenericKeyedObjectPool<K,T>
* @see #getTimeBetweenEvictionRunsMillis
* @see #setTimeBetweenEvictionRunsMillis
*/
- private int _numTestsPerEvictionRun = DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+ private int _numTestsPerEvictionRun =
+ GenericKeyedObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
/**
* The minimum amount of time an object may sit idle in the pool
@@ -2133,19 +1737,21 @@ public class GenericKeyedObjectPool<K,T>
* @see #getTimeBetweenEvictionRunsMillis
* @see #setTimeBetweenEvictionRunsMillis
*/
- private long _minEvictableIdleTimeMillis = DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+ private long _minEvictableIdleTimeMillis =
+ GenericKeyedObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+
+ /** Whether or not the pools behave as LIFO queues (last in first out) */
+ private boolean _lifo = GenericKeyedObjectPoolConfig.DEFAULT_LIFO;
/** My {@link KeyedPoolableObjectFactory}. */
- private KeyedPoolableObjectFactory<K,T> _factory = null;
+ private volatile KeyedPoolableObjectFactory<K,T> _factory = null;
+ private Object factoryLock = new Object();
/**
* My idle object eviction {@link TimerTask}, if any.
*/
private Evictor _evictor = null;
- /** Whether or not the pools behave as LIFO queues (last in first out) */
- private boolean _lifo = DEFAULT_LIFO;
-
/** My hash of pools (ObjectQueue). */
private Map<K,ObjectDeque<T>> poolMap =
new ConcurrentHashMap<K,ObjectDeque<T>>();
Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java?rev=1131071&r1=1131070&r2=1131071&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolConfig.java Fri Jun 3 15:23:29 2011
@@ -24,7 +24,8 @@ import org.apache.commons.pool2.KeyedPoo
*
* @since Pool 2.0
*/
-public class GenericKeyedObjectPoolConfig<K,T> extends BaseObjectPoolConfig {
+public class GenericKeyedObjectPoolConfig<K,T> extends BaseObjectPoolConfig
+ implements Cloneable {
public static final int DEFAULT_MAX_TOTAL_PER_KEY = 8;
@@ -57,4 +58,14 @@ public class GenericKeyedObjectPoolConfi
public void setMaxTotalPerKey(int maxTotalPerKey) {
this.maxTotalPerKey = maxTotalPerKey;
}
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public GenericKeyedObjectPoolConfig<K, T> clone() {
+ try {
+ return (GenericKeyedObjectPoolConfig<K, T>) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new AssertionError(); // Can't happen
+ }
+ }
}
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=1131071&r1=1131070&r2=1131071&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 Fri Jun 3 15:23:29 2011
@@ -19,427 +19,63 @@ package org.apache.commons.pool2.impl;
import org.apache.commons.pool2.KeyedObjectPool;
import org.apache.commons.pool2.KeyedObjectPoolFactory;
-import org.apache.commons.pool2.KeyedPoolableObjectFactory;
/**
- * A factory for creating {@link GenericKeyedObjectPool} instances.
- *
- * @see GenericKeyedObjectPool
- * @see KeyedObjectPoolFactory
+ * A factory for creating {@link GenericKeyedObjectPool} instances from a
+ * provided {@link GenericKeyedObjectPoolConfig configuration}.
*
* @param <K> The type of keys maintained by the built pool.
- * @param <V> Type of element pooled in the built pool.
+ * @param <T> Type of element pooled in the built pool.
*
- * @author Rodney Waldhoff
- * @author Dirk Verbeeck
- * @version $Revision$ $Date$
* @since Pool 1.0
*/
-public class GenericKeyedObjectPoolFactory<K,V> implements KeyedObjectPoolFactory<K,V> {
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @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);
- }
-
- /**
- * Create a new GenericKeyedObjectPoolFactory.
- *
- * @param factory the KeyedPoolableObjectFactory to used by created pools.
- * @param config a non-null GenericKeyedObjectPool.Config describing the configuration.
- * @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.maxActive,config.whenExhaustedAction,config.maxWait,config.maxIdle,config.maxTotal,config.minIdle,config.testOnBorrow,config.testOnReturn,config.timeBetweenEvictionRunsMillis,config.numTestsPerEvictionRun,config.minEvictableIdleTimeMillis,config.testWhileIdle,config.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.
- * @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, byte, 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, byte, 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, byte, 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, byte, 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, byte, 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);
- }
+public class GenericKeyedObjectPoolFactory<K,T>
+ implements KeyedObjectPoolFactory<K,T> {
- /**
- * 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, byte, 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);
- }
+ private GenericKeyedObjectPoolConfig<K, T> config;
/**
* 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, byte, long, int, int, int, boolean, boolean, long, int, long, boolean)
+ * @param config The configuration that will be used for all pools
+ * created by this factory. Note that the configuration is
+ * passed by value. Subsequent changes to config will not
+ * be reflected in this factory or the pools it creates.
*/
- 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);
+ public GenericKeyedObjectPoolFactory(
+ GenericKeyedObjectPoolConfig<K,T> config) {
+ this.config = config.clone();
}
- /**
- * 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, byte, 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;
- _factory = factory;
- _lifo = lifo;
- }
-
- /**
- * Create a new GenericKeyedObjectPool with the currently configured properties.
- *
- * @return GenericKeyedObjectPool with {@link GenericKeyedObjectPool.Config Configuration} determined by
- * 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 the {@link GenericKeyedObjectPool#getMaxIdle() maxIdle} setting for pools created by this factory.
- * @since 1.5.5
- */
- public int getMaxIdle() {
- return _maxIdle;
- }
-
- /**
- * @return the {@link GenericKeyedObjectPool#getMaxActive() maxActive} setting for pools created by this factory.
- * @since 1.5.5
- */
- public int getMaxActive() {
- return _maxActive;
- }
-
- /**
- * @return the {@link GenericKeyedObjectPool#getMaxTotal() maxTotal} setting for pools created by this factory.
- * @since 1.5.5
- */
- public int getMaxTotal() {
- return _maxTotal;
- }
-
- /**
- * @return the {@link GenericKeyedObjectPool#getMinIdle() minIdle} setting for pools created by this factory.
- * @since 1.5.5
- */
- public int getMinIdle() {
- return _minIdle;
- }
-
- /**
- * @return the {@link GenericKeyedObjectPool#getMaxWait() maxWait} setting for pools created by this factory.
- * @since 1.5.5
- */
- public long getMaxWait() {
- return _maxWait;
- }
-
- /**
- * @return the {@link GenericKeyedObjectPool#getWhenExhaustedAction() whenExhaustedAction} setting for pools created by this factory.
- * @since 1.5.5
+ * Obtain the configuration currently used by the factory allowing the
+ * current settings to be viewed and changed.
+ *
+ * @return The config object currently used by the factory
*/
- public WhenExhaustedAction getWhenExhaustedAction() {
- return _whenExhaustedAction;
+ public GenericKeyedObjectPoolConfig<K, T> getConfig() {
+ return config;
}
- /**
- * @return the {@link GenericKeyedObjectPool#getTestOnBorrow() testOnBorrow} setting for pools created by this factory.
- * @since 1.5.5
- */
- public boolean getTestOnBorrow() {
- return _testOnBorrow;
- }
/**
- * @return the {@link GenericKeyedObjectPool#getTestOnReturn() testOnReturn} setting for pools created by this factory.
- * @since 1.5.5
+ * Replace the configuration settings used by this factory.
+ *
+ * @param config The new settings which will be passed by value
*/
- public boolean getTestOnReturn() {
- return _testOnReturn;
+ public void setConfig(GenericKeyedObjectPoolConfig<K, T> config) {
+ this.config = config.clone();
}
- /**
- * @return the {@link GenericKeyedObjectPool#getTestWhileIdle() testWhileIdle} setting for pools created by this factory.
- * @since 1.5.5
- */
- public boolean getTestWhileIdle() {
- return _testWhileIdle;
- }
/**
- * @return the {@link GenericKeyedObjectPool#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis}
- * setting for pools created by this factory.
- * @since 1.5.5
- */
- public long getTimeBetweenEvictionRunsMillis() {
- return _timeBetweenEvictionRunsMillis;
- }
-
- /**
- * @return the {@link GenericKeyedObjectPool#getNumTestsPerEvictionRun() numTestsPerEvictionRun}
- * setting for pools created by this factory.
- * @since 1.5.5
- */
- public int getNumTestsPerEvictionRun() {
- return _numTestsPerEvictionRun;
- }
-
- /**
- * @return the {@link GenericKeyedObjectPool#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis}
- * setting for pools created by this factory.
- * @since 1.5.5
- */
- public long getMinEvictableIdleTimeMillis() {
- return _minEvictableIdleTimeMillis;
- }
-
- /**
- * @return the {@link KeyedPoolableObjectFactory} used by pools created by this factory.
- * @since 1.5.5
- */
- public KeyedPoolableObjectFactory<K,V> getFactory() {
- return _factory;
- }
-
- /**
- * @return the {@link GenericKeyedObjectPool#getLifo() lifo} setting for pools created by this factory.
- * @since 1.5.5
+ * Create a new GenericKeyedObjectPool with the currently configured
+ * properties.
+ *
+ * @return A pool configured with the current property settings
*/
- public boolean getLifo() {
- return _lifo;
+ public KeyedObjectPool<K,T> createPool() {
+ return new GenericKeyedObjectPool<K,T>(config);
}
-
- //--- private attributes - use getters to access these properties
-
- /**
- * The {@link GenericKeyedObjectPool#getMaxIdle() maxIdle} setting for pools created by this factory.
- */
- private int _maxIdle = GenericKeyedObjectPool.DEFAULT_MAX_IDLE;
-
- /**
- * The {@link GenericKeyedObjectPool#getMaxActive() maxActive} setting for pools created by this factory.
- */
- private int _maxActive = GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE;
-
- /**
- * The {@link GenericKeyedObjectPool#getMaxTotal() maxTotal} setting for pools created by this factory.
- */
- private int _maxTotal = GenericKeyedObjectPool.DEFAULT_MAX_TOTAL;
-
- /**
- * The {@link GenericKeyedObjectPool#getMinIdle() minIdle} setting for pools created by this factory.
- */
- private int _minIdle = GenericKeyedObjectPool.DEFAULT_MIN_IDLE;
-
- /**
- * The {@link GenericKeyedObjectPool#getMaxWait() maxWait} setting for pools created by this factory.
- */
- private long _maxWait = GenericKeyedObjectPool.DEFAULT_MAX_WAIT;
-
- /**
- * The {@link GenericKeyedObjectPool#getWhenExhaustedAction() whenExhaustedAction} setting for pools created by this factory.
- */
- private WhenExhaustedAction _whenExhaustedAction = GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION;
-
- /**
- * The {@link GenericKeyedObjectPool#getTestOnBorrow() testOnBorrow} setting for pools created by this factory.
- */
- private boolean _testOnBorrow = GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW;
-
- /**
- * The {@link GenericKeyedObjectPool#getTestOnReturn() testOnReturn} setting for pools created by this factory.
- */
- private boolean _testOnReturn = GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN;
-
- /**
- * The {@link GenericKeyedObjectPool#getTestWhileIdle() testWhileIdle} setting for pools created by this factory.
- */
- private boolean _testWhileIdle = GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE;
-
- /**
- * The {@link GenericKeyedObjectPool#getTimeBetweenEvictionRunsMillis() timeBetweenEvictionRunsMillis} setting for
- * pools created by this factory.
- */
- private long _timeBetweenEvictionRunsMillis = GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
-
- /**
- * The {@link GenericKeyedObjectPool#getNumTestsPerEvictionRun() numTestsPerEvictionRun} setting for
- * pools created by this factory.
- */
- private int _numTestsPerEvictionRun = GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
-
- /**
- * The {@link GenericKeyedObjectPool#getMinEvictableIdleTimeMillis() minEvictableIdleTimeMillis} setting for
- * pools created by this factory.
- */
- private long _minEvictableIdleTimeMillis = GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
-
- /**
- * The {@link KeyedPoolableObjectFactory} used by pools created by this factory.
- */
- private KeyedPoolableObjectFactory<K,V> _factory = null;
-
- /**
- * The {@link GenericKeyedObjectPool#getLifo() lifo} setting for pools created by this factory.
- */
- private boolean _lifo = GenericKeyedObjectPool.DEFAULT_LIFO;
-
}
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java?rev=1131071&r1=1131070&r2=1131071&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/TestPoolUtils.java Fri Jun 3 15:23:29 2011
@@ -153,7 +153,8 @@ public class TestPoolUtils {
// Test that the minIdle check doesn't add too many idle objects
final KeyedPoolableObjectFactory kpof = createProxy(KeyedPoolableObjectFactory.class, calledMethods);
- final KeyedObjectPool kop = new GenericKeyedObjectPool(kpof);
+ final KeyedObjectPool kop = new GenericKeyedObjectPool();
+ kop.setFactory(kpof);
PoolUtils.checkMinIdle(kop, key, 2, 100);
Thread.sleep(400);
assertEquals(2, kop.getNumIdle(key));
Re: svn commit: r1131071 [1/2] - in /commons/proper/pool/trunk/src:
java/org/apache/commons/pool2/ java/org/apache/commons/pool2/impl/ test/org/apache/commons/pool2/
test/org/apache/commons/pool2/impl/
Posted by Mark Thomas <ma...@apache.org>.
On 03/06/2011 16:23, markt@apache.org wrote:
> Author: markt
> Date: Fri Jun 3 15:23:29 2011
> New Revision: 1131071
>
> URL: http://svn.apache.org/viewvc?rev=1131071&view=rev
> Log:
> KeyedObjectPool re-factoring
> - remove deprecation of setFactory
> - rename maxActive to maxTotalPerKey
> - remove default constants from pool impl (they are in the config class)
> - remove internal config class from pool impl
> - use config to simplify constructors
> - make factory immutable once set
There are a lot of inter-related changed here. I'm going to pause for a
few days (at least, probably longer looking at my diary) before making
further changes to give folks a chance to review.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org