You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2011/12/21 14:03:55 UTC
svn commit: r1221705 [4/9] - in /commons/proper/pool/branches/POOL_1_X: ./
src/java/org/apache/commons/pool/ src/java/org/apache/commons/pool/impl/
src/site/ src/site/xdoc/ src/test/org/apache/commons/pool/
src/test/org/apache/commons/pool/impl/ src/te...
Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPoolFactory.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPoolFactory.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericKeyedObjectPoolFactory.java Wed Dec 21 13:03:54 2011
@@ -32,14 +32,14 @@ import org.apache.commons.pool.KeyedPool
* @version $Revision$ $Date$
* @since Pool 1.0
*/
-public class GenericKeyedObjectPoolFactory implements KeyedObjectPoolFactory {
+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 factory) {
+ 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);
}
@@ -51,7 +51,7 @@ public class GenericKeyedObjectPoolFacto
* @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, GenericKeyedObjectPool.Config)
* @throws NullPointerException when config is <code>null</code>.
*/
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, GenericKeyedObjectPool.Config config) throws NullPointerException {
+ 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);
}
@@ -62,7 +62,7 @@ public class GenericKeyedObjectPoolFacto
* @param maxActive the maximum number of objects that can be borrowed from pools at one time.
* @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int)
*/
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxActive) {
+ 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);
}
@@ -75,7 +75,7 @@ public class GenericKeyedObjectPoolFacto
* @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 factory, int maxActive, byte whenExhaustedAction, long maxWait) {
+ public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxActive, byte 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);
}
@@ -90,7 +90,7 @@ public class GenericKeyedObjectPoolFacto
* @param testOnReturn whether to validate objects after they are returned to returnObject.
* @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, byte, long, boolean, boolean)
*/
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn) {
+ public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxActive, byte 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);
}
@@ -104,7 +104,7 @@ public class GenericKeyedObjectPoolFacto
* @param maxIdle the maximum number of idle objects in the pools.
* @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, byte, long, int)
*/
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle) {
+ public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxActive, byte 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);
}
@@ -118,7 +118,7 @@ public class GenericKeyedObjectPoolFacto
* @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 factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int maxTotal) {
+ public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxActive, byte 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);
}
@@ -134,7 +134,7 @@ public class GenericKeyedObjectPoolFacto
* @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 factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn) {
+ public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxActive, byte 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);
}
@@ -154,7 +154,7 @@ public class GenericKeyedObjectPoolFacto
* @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 factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
+ public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxActive, byte 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);
}
@@ -175,7 +175,7 @@ public class GenericKeyedObjectPoolFacto
* @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 factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
+ public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxActive, byte 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);
}
@@ -198,7 +198,7 @@ public class GenericKeyedObjectPoolFacto
* @since Pool 1.3
* @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, byte, long, int, int, int, boolean, boolean, long, int, long, boolean)
*/
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
+ public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxActive, byte 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);
}
@@ -222,7 +222,7 @@ public class GenericKeyedObjectPoolFacto
* @since Pool 1.4
* @see GenericKeyedObjectPool#GenericKeyedObjectPool(KeyedPoolableObjectFactory, int, byte, long, int, int, int, boolean, boolean, long, int, long, boolean, boolean)
*/
- public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle, boolean lifo) {
+ public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxActive, byte 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;
@@ -245,8 +245,8 @@ public class GenericKeyedObjectPoolFacto
* @return GenericKeyedObjectPool with {@link GenericKeyedObjectPool.Config Configuration} determined by
* current property settings
*/
- public KeyedObjectPool createPool() {
- return new GenericKeyedObjectPool(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_maxTotal,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle,_lifo);
+ public KeyedObjectPool<K, V> createPool() {
+ return new GenericKeyedObjectPool<K, V>(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_maxTotal,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle,_lifo);
}
/**
@@ -352,7 +352,7 @@ public class GenericKeyedObjectPoolFacto
* @return the {@link KeyedPoolableObjectFactory} used by pools created by this factory.
* @since 1.5.5
*/
- public KeyedPoolableObjectFactory getFactory() {
+ public KeyedPoolableObjectFactory<K, V> getFactory() {
return _factory;
}
@@ -445,7 +445,7 @@ public class GenericKeyedObjectPoolFacto
* The {@link KeyedPoolableObjectFactory} used by pools created by this factory.
* @deprecated to be removed in pool 2.0. Use {@link #getFactory()}.
*/
- protected KeyedPoolableObjectFactory _factory = null;
+ protected KeyedPoolableObjectFactory<K, V> _factory = null;
/**
* The {@link GenericKeyedObjectPool#getLifo() lifo} setting for pools created by this factory.
Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPool.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPool.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPool.java Wed Dec 21 13:03:54 2011
@@ -187,7 +187,7 @@ import org.apache.commons.pool.impl.Gene
* @version $Revision$ $Date$
* @since Pool 1.0
*/
-public class GenericObjectPool extends BaseObjectPool implements ObjectPool {
+public class GenericObjectPool<T> extends BaseObjectPool<T> implements ObjectPool<T> {
//--- public constants -------------------------------------------
@@ -348,7 +348,7 @@ public class GenericObjectPool extends B
* Create a new <tt>GenericObjectPool</tt> using the specified factory.
* @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects
*/
- public GenericObjectPool(PoolableObjectFactory factory) {
+ 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);
@@ -359,7 +359,7 @@ public class GenericObjectPool extends B
* @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
*/
- public GenericObjectPool(PoolableObjectFactory factory, GenericObjectPool.Config config) {
+ 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,
@@ -371,7 +371,7 @@ public class GenericObjectPool extends B
* @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 factory, int maxActive) {
+ 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);
@@ -385,7 +385,7 @@ public class GenericObjectPool extends B
* @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 #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #getMaxWait})
*/
- public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait) {
+ public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, byte 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);
@@ -403,7 +403,7 @@ public class GenericObjectPool extends B
* @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method
* (see {@link #getTestOnReturn})
*/
- public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait,
+ public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, byte 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,
@@ -419,7 +419,7 @@ public class GenericObjectPool extends B
* <i>whenExhaustedAction</i> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #getMaxWait})
* @param maxIdle the maximum number of idle objects in my pool (see {@link #getMaxIdle})
*/
- public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle) {
+ public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, byte 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);
@@ -438,7 +438,7 @@ public class GenericObjectPool extends B
* @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method
* (see {@link #getTestOnReturn})
*/
- public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait,
+ public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, byte 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,
@@ -466,7 +466,7 @@ public class GenericObjectPool extends B
* @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any
* (see {@link #setTestWhileIdle})
*/
- public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait,
+ public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, byte 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,
@@ -495,7 +495,7 @@ public class GenericObjectPool extends B
* @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any
* (see {@link #setTestWhileIdle})
*/
- public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait,
+ public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, byte 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,
@@ -529,7 +529,7 @@ public class GenericObjectPool extends B
* (see {@link #setSoftMinEvictableIdleTimeMillis})
* @since Pool 1.3
*/
- public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait,
+ public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, byte whenExhaustedAction, long maxWait,
int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle,
long softMinEvictableIdleTimeMillis) {
@@ -566,7 +566,7 @@ public class GenericObjectPool extends B
* (see {@link #setLifo})
* @since Pool 1.4
*/
- public GenericObjectPool(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait,
+ public GenericObjectPool(PoolableObjectFactory<T> factory, int maxActive, byte whenExhaustedAction, long maxWait,
int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle,
long softMinEvictableIdleTimeMillis, boolean lifo) {
@@ -593,7 +593,7 @@ public class GenericObjectPool extends B
_softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
_testWhileIdle = testWhileIdle;
- _pool = new CursorableLinkedList();
+ _pool = new CursorableLinkedList<ObjectTimestampPair<T>>();
startEvictor(_timeBetweenEvictionRunsMillis);
}
@@ -1052,9 +1052,9 @@ public class GenericObjectPool extends B
* @return object instance
* @throws NoSuchElementException if an instance cannot be returned
*/
- public Object borrowObject() throws Exception {
+ public T borrowObject() throws Exception {
long starttime = System.currentTimeMillis();
- Latch latch = new Latch();
+ Latch<T> latch = new Latch<T>();
byte whenExhaustedAction;
long maxWait;
synchronized (this) {
@@ -1182,8 +1182,8 @@ public class GenericObjectPool extends B
boolean newlyCreated = false;
if(null == latch.getPair()) {
try {
- Object obj = _factory.makeObject();
- latch.setPair(new ObjectTimestampPair(obj));
+ T obj = _factory.makeObject();
+ latch.setPair(new ObjectTimestampPair<T>(obj));
newlyCreated = true;
} finally {
if (!newlyCreated) {
@@ -1248,8 +1248,8 @@ public class GenericObjectPool extends B
// First use any objects in the pool to clear the queue
for (;;) {
if (!_pool.isEmpty() && !_allocationQueue.isEmpty()) {
- Latch latch = (Latch) _allocationQueue.removeFirst();
- latch.setPair((ObjectTimestampPair) _pool.removeFirst());
+ Latch<T> latch = _allocationQueue.removeFirst();
+ latch.setPair( _pool.removeFirst());
_numInternalProcessing++;
synchronized (latch) {
latch.notify();
@@ -1262,7 +1262,7 @@ public class GenericObjectPool extends B
// Second utilise any spare capacity to create new objects
for(;;) {
if((!_allocationQueue.isEmpty()) && (_maxActive < 0 || (_numActive + _numInternalProcessing) < _maxActive)) {
- Latch latch = (Latch) _allocationQueue.removeFirst();
+ Latch<T> latch = _allocationQueue.removeFirst();
latch.setMayCreate(true);
_numInternalProcessing++;
synchronized (latch) {
@@ -1280,7 +1280,7 @@ public class GenericObjectPool extends B
*
* @throws Exception if the configured {@link PoolableObjectFactory} throws an exception destroying obj
*/
- public void invalidateObject(Object obj) throws Exception {
+ public void invalidateObject(T obj) throws Exception {
try {
if (_factory != null) {
_factory.destroyObject(obj);
@@ -1309,7 +1309,7 @@ public class GenericObjectPool extends B
* <li>Exceptions encountered destroying idle instances are swallowed.</li></ul></p>
*/
public void clear() {
- List toDestroy = new ArrayList();
+ List<ObjectTimestampPair<T>> toDestroy = new ArrayList<ObjectTimestampPair<T>>();
synchronized(this) {
toDestroy.addAll(_pool);
@@ -1328,10 +1328,10 @@ public class GenericObjectPool extends B
* @param c Collection of objects to destroy
* @param factory PoolableConnectionFactory used to destroy the objects
*/
- private void destroy(Collection c, PoolableObjectFactory factory) {
- for (Iterator it = c.iterator(); it.hasNext();) {
+ private void destroy(Collection<ObjectTimestampPair<T>> c, PoolableObjectFactory<T> factory) {
+ for (Iterator<ObjectTimestampPair<T>> it = c.iterator(); it.hasNext();) {
try {
- factory.destroyObject(((ObjectTimestampPair)(it.next())).value);
+ factory.destroyObject(it.next().value);
} catch(Exception e) {
// ignore error, keep destroying the rest
} finally {
@@ -1380,7 +1380,7 @@ public class GenericObjectPool extends B
*
* @param obj instance to return to the pool
*/
- public void returnObject(Object obj) throws Exception {
+ public void returnObject(T obj) throws Exception {
try {
addObjectToPool(obj, true);
} catch (Exception e) {
@@ -1414,7 +1414,7 @@ public class GenericObjectPool extends B
* @param decrementNumActive whether or not to decrement the active count
* @throws Exception
*/
- private void addObjectToPool(Object obj, boolean decrementNumActive) throws Exception {
+ private void addObjectToPool(T obj, boolean decrementNumActive) throws Exception {
boolean success = true;
if(_testOnReturn && !(_factory.validateObject(obj))) {
success = false;
@@ -1437,9 +1437,9 @@ public class GenericObjectPool extends B
// borrowObject always takes the first element from the queue,
// so for LIFO, push on top, FIFO add to end
if (_lifo) {
- _pool.addFirst(new ObjectTimestampPair(obj));
+ _pool.addFirst(new ObjectTimestampPair<T>(obj));
} else {
- _pool.addLast(new ObjectTimestampPair(obj));
+ _pool.addLast(new ObjectTimestampPair<T>(obj));
}
if (decrementNumActive) {
_numActive--;
@@ -1487,7 +1487,7 @@ public class GenericObjectPool extends B
startEvictor(-1L);
while(_allocationQueue.size() > 0) {
- Latch l = (Latch) _allocationQueue.removeFirst();
+ Latch<T> l = _allocationQueue.removeFirst();
synchronized (l) {
// notify the waiting thread
@@ -1509,9 +1509,9 @@ public class GenericObjectPool extends B
* @throws IllegalStateException when the factory cannot be set at this time
* @deprecated to be removed in version 2.0
*/
- public void setFactory(PoolableObjectFactory factory) throws IllegalStateException {
- List toDestroy = new ArrayList();
- final PoolableObjectFactory oldFactory = _factory;
+ public void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException {
+ List<ObjectTimestampPair<T>> toDestroy = new ArrayList<ObjectTimestampPair<T>>();
+ final PoolableObjectFactory<T> oldFactory = _factory;
synchronized (this) {
assertOpen();
if(0 < getNumActive()) {
@@ -1546,12 +1546,12 @@ public class GenericObjectPool extends B
return;
}
if (null == _evictionCursor) {
- _evictionCursor = (_pool.cursor(_lifo ? _pool.size() : 0));
+ _evictionCursor = _pool.cursor(_lifo ? _pool.size() : 0);
}
}
for (int i=0,m=getNumTests();i<m;i++) {
- final ObjectTimestampPair pair;
+ final ObjectTimestampPair<T> pair;
synchronized (this) {
if ((_lifo && !_evictionCursor.hasPrevious()) ||
!_lifo && !_evictionCursor.hasNext()) {
@@ -1560,8 +1560,8 @@ public class GenericObjectPool extends B
}
pair = _lifo ?
- (ObjectTimestampPair) _evictionCursor.previous() :
- (ObjectTimestampPair) _evictionCursor.next();
+ _evictionCursor.previous() :
+ _evictionCursor.next();
_evictionCursor.remove();
_numInternalProcessing++;
@@ -1676,7 +1676,7 @@ public class GenericObjectPool extends B
if (_factory == null) {
throw new IllegalStateException("Cannot add objects without a factory.");
}
- Object obj = _factory.makeObject();
+ T obj = _factory.makeObject();
try {
assertOpen();
addObjectToPool(obj, false);
@@ -1721,10 +1721,10 @@ public class GenericObjectPool extends B
buf.append("Active: ").append(getNumActive()).append("\n");
buf.append("Idle: ").append(getNumIdle()).append("\n");
buf.append("Idle Objects:\n");
- Iterator it = _pool.iterator();
+ Iterator<ObjectTimestampPair<T>> it = _pool.iterator();
long time = System.currentTimeMillis();
while(it.hasNext()) {
- ObjectTimestampPair pair = (ObjectTimestampPair)(it.next());
+ ObjectTimestampPair<T> pair = it.next();
buf.append("\t").append(pair.value).append("\t").append(time - pair.tstamp).append("\n");
}
return buf.toString();
@@ -1844,10 +1844,10 @@ public class GenericObjectPool extends B
* fairness. That is, objects are allocated to threads in the order that
* threads request objects.
*/
- private static final class Latch {
+ private static final class Latch<T> {
/** object timestamp pair allocated to this latch */
- private ObjectTimestampPair _pair;
+ private ObjectTimestampPair<T> _pair;
/** Whether or not this latch may create an object instance */
private boolean _mayCreate = false;
@@ -1856,7 +1856,7 @@ public class GenericObjectPool extends B
* Returns ObjectTimestampPair allocated to this latch
* @return ObjectTimestampPair allocated to this latch
*/
- private synchronized ObjectTimestampPair getPair() {
+ private synchronized ObjectTimestampPair<T> getPair() {
return _pair;
}
@@ -1864,7 +1864,7 @@ public class GenericObjectPool extends B
* Sets ObjectTimestampPair on this latch
* @param pair ObjectTimestampPair allocated to this latch
*/
- private synchronized void setPair(ObjectTimestampPair pair) {
+ private synchronized void setPair(ObjectTimestampPair<T> pair) {
_pair = pair;
}
@@ -2044,13 +2044,13 @@ public class GenericObjectPool extends B
private boolean _lifo = DEFAULT_LIFO;
/** My pool. */
- private CursorableLinkedList _pool = null;
+ private CursorableLinkedList<ObjectTimestampPair<T>> _pool = null;
/** Eviction cursor - keeps track of idle object evictor position */
- private CursorableLinkedList.Cursor _evictionCursor = null;
+ private CursorableLinkedList<ObjectTimestampPair<T>>.Cursor _evictionCursor = null;
/** My {@link PoolableObjectFactory}. */
- private PoolableObjectFactory _factory = null;
+ private PoolableObjectFactory<T> _factory = null;
/**
* The number of objects {@link #borrowObject} borrowed
@@ -2075,6 +2075,6 @@ public class GenericObjectPool extends B
* that objects can be allocated in the order in which the threads requested
* them.
*/
- private final LinkedList _allocationQueue = new LinkedList();
+ private final LinkedList<Latch<T>> _allocationQueue = new LinkedList<Latch<T>>();
}
Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPoolFactory.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPoolFactory.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/GenericObjectPoolFactory.java Wed Dec 21 13:03:54 2011
@@ -31,14 +31,14 @@ import org.apache.commons.pool.PoolableO
* @version $Revision$ $Date$
* @since Pool 1.0
*/
-public class GenericObjectPoolFactory implements ObjectPoolFactory {
+public class GenericObjectPoolFactory<T> implements ObjectPoolFactory<T> {
/**
* Create a new GenericObjectPoolFactory.
*
* @param factory the PoolableObjectFactory used by created pools.
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory) {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory) {
this(factory,GenericObjectPool.DEFAULT_MAX_ACTIVE,GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,GenericObjectPool.DEFAULT_MAX_WAIT,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
}
@@ -50,7 +50,7 @@ public class GenericObjectPoolFactory im
* @throws NullPointerException when config is <code>null</code>.
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, GenericObjectPool.Config)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory, GenericObjectPool.Config config) throws NullPointerException {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, GenericObjectPool.Config config) throws NullPointerException {
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);
}
@@ -61,7 +61,7 @@ public class GenericObjectPoolFactory im
* @param maxActive maximum number of objects that can be borrowed from created pools at one time.
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive) {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive) {
this(factory,maxActive,GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,GenericObjectPool.DEFAULT_MAX_WAIT,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
}
@@ -74,7 +74,7 @@ public class GenericObjectPoolFactory im
* @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted.
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, byte, long)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait) {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, byte whenExhaustedAction, long maxWait) {
this(factory,maxActive,whenExhaustedAction,maxWait,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
}
@@ -89,7 +89,7 @@ public class GenericObjectPoolFactory im
* @param testOnReturn whether to validate objects after they are returned to the returnObject.
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, byte, long, boolean, boolean)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn) {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, byte whenExhaustedAction, long maxWait, boolean testOnBorrow, boolean testOnReturn) {
this(factory,maxActive,whenExhaustedAction,maxWait,GenericObjectPool.DEFAULT_MAX_IDLE,GenericObjectPool.DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
}
@@ -103,7 +103,7 @@ public class GenericObjectPoolFactory im
* @param maxIdle the maximum number of idle objects in my pool.
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, byte, long, int)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle) {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle) {
this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,GenericObjectPool.DEFAULT_MIN_IDLE,GenericObjectPool.DEFAULT_TEST_ON_BORROW,GenericObjectPool.DEFAULT_TEST_ON_RETURN,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
}
@@ -119,7 +119,7 @@ public class GenericObjectPoolFactory im
* @param testOnReturn whether to validate objects after they are returned to the returnObject.
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, byte, long, int, boolean, boolean)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn) {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn) {
this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,GenericObjectPool.DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN,GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,GenericObjectPool.DEFAULT_TEST_WHILE_IDLE);
}
@@ -139,7 +139,7 @@ public class GenericObjectPoolFactory im
* @param testWhileIdle whether or not to validate objects in the idle object eviction thread.
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, byte, long, int, boolean, boolean, long, int, long, boolean)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,GenericObjectPool.DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,timeBetweenEvictionRunsMillis,numTestsPerEvictionRun,minEvictableIdleTimeMillis,testWhileIdle, GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
}
@@ -160,7 +160,7 @@ public class GenericObjectPoolFactory im
* @param testWhileIdle whether or not to validate objects in the idle object eviction thread.
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, byte, long, int, int, boolean, boolean, long, int, long, boolean)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle) {
this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,minIdle,testOnBorrow,testOnReturn,timeBetweenEvictionRunsMillis,numTestsPerEvictionRun,minEvictableIdleTimeMillis,testWhileIdle, GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
}
@@ -183,7 +183,7 @@ public class GenericObjectPoolFactory im
* @since Pool 1.3
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, byte, long, int, int, boolean, boolean, long, int, long, boolean, long)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle, long softMinEvictableIdleTimeMillis) {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle, long softMinEvictableIdleTimeMillis) {
this(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,minIdle,testOnBorrow,testOnReturn,timeBetweenEvictionRunsMillis,numTestsPerEvictionRun,minEvictableIdleTimeMillis,testWhileIdle,softMinEvictableIdleTimeMillis, GenericObjectPool.DEFAULT_LIFO);
}
@@ -207,7 +207,7 @@ public class GenericObjectPoolFactory im
* @since Pool 1.4
* @see GenericObjectPool#GenericObjectPool(PoolableObjectFactory, int, byte, long, int, int, boolean, boolean, long, int, long, boolean, long, boolean)
*/
- public GenericObjectPoolFactory(PoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle, long softMinEvictableIdleTimeMillis, boolean lifo) {
+ public GenericObjectPoolFactory(PoolableObjectFactory<T> factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int minIdle, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle, long softMinEvictableIdleTimeMillis, boolean lifo) {
_maxIdle = maxIdle;
_minIdle = minIdle;
_maxActive = maxActive;
@@ -227,8 +227,8 @@ public class GenericObjectPoolFactory im
/**
* {@inheritDoc}
*/
- public ObjectPool createPool() {
- return new GenericObjectPool(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle,_softMinEvictableIdleTimeMillis,_lifo);
+ public ObjectPool<T> createPool() {
+ return new GenericObjectPool<T>(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle,_softMinEvictableIdleTimeMillis,_lifo);
}
@@ -347,7 +347,7 @@ public class GenericObjectPoolFactory im
/**
* @return the {@link PoolableObjectFactory} used by pools created by this factory
*/
- public PoolableObjectFactory getFactory() {
+ public PoolableObjectFactory<T> getFactory() {
return _factory;
}
@@ -438,6 +438,6 @@ public class GenericObjectPoolFactory im
* The {@link PoolableObjectFactory} used by pools created by this factory.
* @deprecated to be removed in pool 2.0. Use {@link #getFactory()}.
*/
- protected PoolableObjectFactory _factory = null;
+ protected PoolableObjectFactory<T> _factory = null;
}
Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/SoftReferenceObjectPool.java Wed Dec 21 13:03:54 2011
@@ -39,7 +39,7 @@ import org.apache.commons.pool.PoolUtils
* @version $Revision$ $Date$
* @since Pool 1.0
*/
-public class SoftReferenceObjectPool extends BaseObjectPool implements ObjectPool {
+public class SoftReferenceObjectPool<T> extends BaseObjectPool<T> implements ObjectPool<T> {
/**
* Create a <code>SoftReferenceObjectPool</code> without a factory.
* {@link #setFactory(PoolableObjectFactory) setFactory} should be called
@@ -50,7 +50,7 @@ public class SoftReferenceObjectPool ext
* @deprecated to be removed in pool 2.0. Use {@link #SoftReferenceObjectPool(PoolableObjectFactory)}.
*/
public SoftReferenceObjectPool() {
- _pool = new ArrayList();
+ _pool = new ArrayList<SoftReference<T>>();
_factory = null;
}
@@ -59,8 +59,8 @@ public class SoftReferenceObjectPool ext
*
* @param factory object factory to use.
*/
- public SoftReferenceObjectPool(PoolableObjectFactory factory) {
- _pool = new ArrayList();
+ public SoftReferenceObjectPool(PoolableObjectFactory<T> factory) {
+ _pool = new ArrayList<SoftReference<T>>();
_factory = factory;
}
@@ -74,11 +74,11 @@ public class SoftReferenceObjectPool ext
* @deprecated because this is a SoftReference pool, prefilled idle obejects may be garbage collected before they are used.
* To be removed in Pool 2.0.
*/
- public SoftReferenceObjectPool(PoolableObjectFactory factory, int initSize) throws Exception, IllegalArgumentException {
+ public SoftReferenceObjectPool(PoolableObjectFactory<T> factory, int initSize) throws Exception, IllegalArgumentException {
if (factory == null) {
throw new IllegalArgumentException("factory required to prefill the pool.");
}
- _pool = new ArrayList(initSize);
+ _pool = new ArrayList<SoftReference<T>>(initSize);
_factory = factory;
PoolUtils.prefill(this, initSize);
}
@@ -104,9 +104,9 @@ public class SoftReferenceObjectPool ext
* @throws Exception if an exception occurs creating a new instance
* @return a valid, activated object instance
*/
- public synchronized Object borrowObject() throws Exception {
+ public synchronized T borrowObject() throws Exception {
assertOpen();
- Object obj = null;
+ T obj = null;
boolean newlyCreated = false;
while(null == obj) {
if(_pool.isEmpty()) {
@@ -117,7 +117,7 @@ public class SoftReferenceObjectPool ext
obj = _factory.makeObject();
}
} else {
- SoftReference ref = (SoftReference)(_pool.remove(_pool.size() - 1));
+ SoftReference<T> ref = _pool.remove(_pool.size() - 1);
obj = ref.get();
ref.clear(); // prevent this ref from being enqueued with refQueue.
}
@@ -163,7 +163,7 @@ public class SoftReferenceObjectPool ext
*
* @param obj instance to return to the pool
*/
- public synchronized void returnObject(Object obj) throws Exception {
+ public synchronized void returnObject(T obj) throws Exception {
boolean success = !isClosed();
if (_factory != null) {
if(!_factory.validateObject(obj)) {
@@ -180,7 +180,7 @@ public class SoftReferenceObjectPool ext
boolean shouldDestroy = !success;
_numActive--;
if(success) {
- _pool.add(new SoftReference(obj, refQueue));
+ _pool.add(new SoftReference<T>(obj, refQueue));
}
notifyAll(); // _numActive has changed
@@ -196,7 +196,7 @@ public class SoftReferenceObjectPool ext
/**
* {@inheritDoc}
*/
- public synchronized void invalidateObject(Object obj) throws Exception {
+ public synchronized void invalidateObject(T obj) throws Exception {
_numActive--;
if (_factory != null) {
_factory.destroyObject(obj);
@@ -223,7 +223,7 @@ public class SoftReferenceObjectPool ext
if (_factory == null) {
throw new IllegalStateException("Cannot add objects without a factory.");
}
- Object obj = _factory.makeObject();
+ T obj = _factory.makeObject();
boolean success = true;
if(!_factory.validateObject(obj)) {
@@ -234,7 +234,7 @@ public class SoftReferenceObjectPool ext
boolean shouldDestroy = !success;
if(success) {
- _pool.add(new SoftReference(obj, refQueue));
+ _pool.add(new SoftReference<T>(obj, refQueue));
notifyAll(); // _numActive has changed
}
@@ -271,10 +271,10 @@ public class SoftReferenceObjectPool ext
*/
public synchronized void clear() {
if(null != _factory) {
- Iterator iter = _pool.iterator();
+ Iterator<SoftReference<T>> iter = _pool.iterator();
while(iter.hasNext()) {
try {
- Object obj = ((SoftReference)iter.next()).get();
+ T obj = iter.next().get();
if(null != obj) {
_factory.destroyObject(obj);
}
@@ -312,7 +312,7 @@ public class SoftReferenceObjectPool ext
* @throws IllegalStateException when the factory cannot be set at this time
* @deprecated to be removed in pool 2.0
*/
- public synchronized void setFactory(PoolableObjectFactory factory) throws IllegalStateException {
+ public synchronized void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException {
assertOpen();
if(0 < getNumActive()) {
throw new IllegalStateException("Objects are already active");
@@ -327,7 +327,7 @@ public class SoftReferenceObjectPool ext
* {@link Reference} wrappers from the idle object pool.
*/
private void pruneClearedReferences() {
- Reference ref;
+ Reference<? extends T> ref;
while ((ref = refQueue.poll()) != null) {
try {
_pool.remove(ref);
@@ -343,22 +343,22 @@ public class SoftReferenceObjectPool ext
* @return the factory
* @since 1.5.5
*/
- public synchronized PoolableObjectFactory getFactory() {
+ public synchronized PoolableObjectFactory<T> getFactory() {
return _factory;
}
/** My pool. */
- private final List _pool;
+ private final List<SoftReference<T>> _pool;
/** My {@link PoolableObjectFactory}. */
- private PoolableObjectFactory _factory = null;
+ private PoolableObjectFactory<T> _factory = null;
/**
* Queue of broken references that might be able to be removed from <code>_pool</code>.
* This is used to help {@link #getNumIdle()} be more accurate with minimial
* performance overhead.
*/
- private final ReferenceQueue refQueue = new ReferenceQueue();
+ private final ReferenceQueue<T> refQueue = new ReferenceQueue<T>();
/** Number of active objects. */
private int _numActive = 0; //@GuardeBy("this")
Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java Wed Dec 21 13:03:54 2011
@@ -47,7 +47,7 @@ import java.util.Stack;
* @see Stack
* @since Pool 1.0
*/
-public class StackKeyedObjectPool extends BaseKeyedObjectPool implements KeyedObjectPool {
+public class StackKeyedObjectPool<K, V> extends BaseKeyedObjectPool<K, V> implements KeyedObjectPool<K, V> {
/**
* Create a new pool using no factory.
* Clients must first set the {@link #setFactory factory} or
@@ -58,7 +58,7 @@ public class StackKeyedObjectPool extend
* @see #setFactory(KeyedPoolableObjectFactory)
*/
public StackKeyedObjectPool() {
- this((KeyedPoolableObjectFactory)null,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY);
+ this(null,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY);
}
/**
@@ -72,7 +72,7 @@ public class StackKeyedObjectPool extend
* @see #setFactory(KeyedPoolableObjectFactory)
*/
public StackKeyedObjectPool(int max) {
- this((KeyedPoolableObjectFactory)null,max,DEFAULT_INIT_SLEEPING_CAPACITY);
+ this(null,max,DEFAULT_INIT_SLEEPING_CAPACITY);
}
/**
@@ -88,7 +88,7 @@ public class StackKeyedObjectPool extend
* @see #setFactory(KeyedPoolableObjectFactory)
*/
public StackKeyedObjectPool(int max, int init) {
- this((KeyedPoolableObjectFactory)null,max,init);
+ this(null,max,init);
}
/**
@@ -97,7 +97,7 @@ public class StackKeyedObjectPool extend
*
* @param factory the {@link KeyedPoolableObjectFactory} used to populate the pool
*/
- public StackKeyedObjectPool(KeyedPoolableObjectFactory factory) {
+ public StackKeyedObjectPool(KeyedPoolableObjectFactory<K, V> factory) {
this(factory,DEFAULT_MAX_SLEEPING);
}
@@ -109,7 +109,7 @@ public class StackKeyedObjectPool extend
* @param factory the {@link KeyedPoolableObjectFactory} used to populate the pool
* @param max cap on the number of "sleeping" instances in the pool
*/
- public StackKeyedObjectPool(KeyedPoolableObjectFactory factory, int max) {
+ public StackKeyedObjectPool(KeyedPoolableObjectFactory<K, V> factory, int max) {
this(factory,max,DEFAULT_INIT_SLEEPING_CAPACITY);
}
@@ -125,12 +125,12 @@ public class StackKeyedObjectPool extend
* @param init initial size of the pool (this specifies the size of the container,
* it does not cause the pool to be pre-populated.)
*/
- public StackKeyedObjectPool(KeyedPoolableObjectFactory factory, int max, int init) {
+ public StackKeyedObjectPool(KeyedPoolableObjectFactory<K, V> factory, int max, int init) {
_factory = factory;
_maxSleeping = (max < 0 ? DEFAULT_MAX_SLEEPING : max);
_initSleepingCapacity = (init < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : init);
- _pools = new HashMap();
- _activeCount = new HashMap();
+ _pools = new HashMap<K, Stack<V>>();
+ _activeCount = new HashMap<K, Integer>();
}
/**
@@ -140,15 +140,15 @@ public class StackKeyedObjectPool extend
* @param key the pool key
* @return keyed poolable object instance
*/
- public synchronized Object borrowObject(Object key) throws Exception {
+ public synchronized V borrowObject(K key) throws Exception {
assertOpen();
- Stack stack = (Stack)(_pools.get(key));
+ Stack<V> stack = (_pools.get(key));
if(null == stack) {
- stack = new Stack();
+ stack = new Stack<V>();
stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity);
_pools.put(key,stack);
}
- Object obj = null;
+ V obj = null;
do {
boolean newlyMade = false;
if (!stack.empty()) {
@@ -199,7 +199,7 @@ public class StackKeyedObjectPool extend
* @param key the pool key
* @param obj returning instance
*/
- public synchronized void returnObject(Object key, Object obj) throws Exception {
+ public synchronized void returnObject(K key, V obj) throws Exception {
decrementActiveCount(key);
if (null != _factory) {
if (_factory.validateObject(key, obj)) {
@@ -225,15 +225,15 @@ public class StackKeyedObjectPool extend
return;
}
- Stack stack = (Stack)_pools.get(key);
+ Stack<V> stack = _pools.get(key);
if(null == stack) {
- stack = new Stack();
+ stack = new Stack<V>();
stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity);
_pools.put(key,stack);
}
final int stackSize = stack.size();
if (stackSize >= _maxSleeping) {
- final Object staleObj;
+ final V staleObj;
if (stackSize > 0) {
staleObj = stack.remove(0);
_totIdle--;
@@ -255,7 +255,7 @@ public class StackKeyedObjectPool extend
/**
* {@inheritDoc}
*/
- public synchronized void invalidateObject(Object key, Object obj) throws Exception {
+ public synchronized void invalidateObject(K key, V obj) throws Exception {
decrementActiveCount(key);
if(null != _factory) {
_factory.destroyObject(key,obj);
@@ -272,12 +272,12 @@ public class StackKeyedObjectPool extend
* @throws Exception when {@link KeyedPoolableObjectFactory#makeObject} fails.
* @throws IllegalStateException when no {@link #setFactory factory} has been set or after {@link #close} has been called on this pool.
*/
- public synchronized void addObject(Object key) throws Exception {
+ public synchronized void addObject(K key) throws Exception {
assertOpen();
if (_factory == null) {
throw new IllegalStateException("Cannot add objects without a factory.");
}
- Object obj = _factory.makeObject(key);
+ V obj = _factory.makeObject(key);
try {
if (!_factory.validateObject(key, obj)) {
return;
@@ -292,16 +292,16 @@ public class StackKeyedObjectPool extend
}
_factory.passivateObject(key, obj);
- Stack stack = (Stack)_pools.get(key);
+ Stack<V> stack = _pools.get(key);
if(null == stack) {
- stack = new Stack();
+ stack = new Stack<V>();
stack.ensureCapacity( _initSleepingCapacity > _maxSleeping ? _maxSleeping : _initSleepingCapacity);
_pools.put(key,stack);
}
final int stackSize = stack.size();
if (stackSize >= _maxSleeping) {
- final Object staleObj;
+ final V staleObj;
if (stackSize > 0) {
staleObj = stack.remove(0);
_totIdle--;
@@ -347,7 +347,7 @@ public class StackKeyedObjectPool extend
* @param key the key to query
* @return the number of instances corresponding to the given <code>key</code> currently borrowed in this pool
*/
- public synchronized int getNumActive(Object key) {
+ public synchronized int getNumActive(K key) {
return getActiveCount(key);
}
@@ -357,9 +357,9 @@ public class StackKeyedObjectPool extend
* @param key the key to query
* @return the number of instances corresponding to the given <code>key</code> currently idle in this pool
*/
- public synchronized int getNumIdle(Object key) {
+ public synchronized int getNumIdle(K key) {
try {
- return((Stack)(_pools.get(key))).size();
+ return(_pools.get(key)).size();
} catch(Exception e) {
return 0;
}
@@ -369,10 +369,10 @@ public class StackKeyedObjectPool extend
* Clears the pool, removing all pooled instances.
*/
public synchronized void clear() {
- Iterator it = _pools.keySet().iterator();
+ Iterator<K> it = _pools.keySet().iterator();
while(it.hasNext()) {
- Object key = it.next();
- Stack stack = (Stack)(_pools.get(key));
+ K key = it.next();
+ Stack<V> stack = _pools.get(key);
destroyStack(key,stack);
}
_totIdle = 0;
@@ -385,8 +385,8 @@ public class StackKeyedObjectPool extend
*
* @param key the key to clear
*/
- public synchronized void clear(Object key) {
- Stack stack = (Stack)(_pools.remove(key));
+ public synchronized void clear(K key) {
+ Stack<V> stack = _pools.remove(key);
destroyStack(key,stack);
}
@@ -396,12 +396,12 @@ public class StackKeyedObjectPool extend
* @param key key passed to factory when destroying instances
* @param stack stack to destroy
*/
- private synchronized void destroyStack(Object key, Stack stack) {
+ private synchronized void destroyStack(K key, Stack<V> stack) {
if(null == stack) {
return;
} else {
if(null != _factory) {
- Iterator it = stack.iterator();
+ Iterator<V> it = stack.iterator();
while(it.hasNext()) {
try {
_factory.destroyObject(key,it.next());
@@ -426,11 +426,11 @@ public class StackKeyedObjectPool extend
StringBuffer buf = new StringBuffer();
buf.append(getClass().getName());
buf.append(" contains ").append(_pools.size()).append(" distinct pools: ");
- Iterator it = _pools.keySet().iterator();
+ Iterator<K> it = _pools.keySet().iterator();
while(it.hasNext()) {
- Object key = it.next();
+ K key = it.next();
buf.append(" |").append(key).append("|=");
- Stack s = (Stack)(_pools.get(key));
+ Stack<V> s = _pools.get(key);
buf.append(s.size());
}
return buf.toString();
@@ -460,7 +460,7 @@ public class StackKeyedObjectPool extend
* @throws IllegalStateException when the factory cannot be set at this time
* @deprecated to be removed in pool 2.0
*/
- public synchronized void setFactory(KeyedPoolableObjectFactory factory) throws IllegalStateException {
+ public synchronized void setFactory(KeyedPoolableObjectFactory<K, V> factory) throws IllegalStateException {
if(0 < getNumActive()) {
throw new IllegalStateException("Objects are already active");
} else {
@@ -473,7 +473,7 @@ public class StackKeyedObjectPool extend
* @return the {@link KeyedPoolableObjectFactory} used by this pool to manage object instances.
* @since 1.5.5
*/
- public synchronized KeyedPoolableObjectFactory getFactory() {
+ public synchronized KeyedPoolableObjectFactory<K, V> getFactory() {
return _factory;
}
@@ -483,9 +483,9 @@ public class StackKeyedObjectPool extend
* @param key pool key
* @return active count
*/
- private int getActiveCount(Object key) {
+ private int getActiveCount(K key) {
try {
- return ((Integer)_activeCount.get(key)).intValue();
+ return _activeCount.get(key).intValue();
} catch(NoSuchElementException e) {
return 0;
} catch(NullPointerException e) {
@@ -499,9 +499,9 @@ public class StackKeyedObjectPool extend
*
* @param key pool key
*/
- private void incrementActiveCount(Object key) {
+ private void incrementActiveCount(K key) {
_totActive++;
- Integer old = (Integer)(_activeCount.get(key));
+ Integer old = _activeCount.get(key);
if(null == old) {
_activeCount.put(key,new Integer(1));
} else {
@@ -515,9 +515,9 @@ public class StackKeyedObjectPool extend
*
* @param key pool key
*/
- private void decrementActiveCount(Object key) {
+ private void decrementActiveCount(K key) {
_totActive--;
- Integer active = (Integer)(_activeCount.get(key));
+ Integer active = _activeCount.get(key);
if(null == active) {
// do nothing, either null or zero is OK
} else if(active.intValue() <= 1) {
@@ -532,7 +532,7 @@ public class StackKeyedObjectPool extend
* @return map of keyed pools
* @since 1.5.5
*/
- public Map getPools() {
+ public Map<K, Stack<V>> getPools() {
return _pools;
}
@@ -570,7 +570,7 @@ public class StackKeyedObjectPool extend
* @return the _activeCount
* @since 1.5.5
*/
- public Map getActiveCount() {
+ public Map<K, Integer> getActiveCount() {
return _activeCount;
}
@@ -589,13 +589,13 @@ public class StackKeyedObjectPool extend
* My named-set of pools.
* @deprecated to be removed in pool 2.0. Use {@link #getPools()}
*/
- protected HashMap _pools = null;
+ protected HashMap<K, Stack<V>> _pools = null;
/**
* My {@link KeyedPoolableObjectFactory}.
* @deprecated to be removed in pool 2.0. Use {@link #getFactory()}
*/
- protected KeyedPoolableObjectFactory _factory = null;
+ protected KeyedPoolableObjectFactory<K, V> _factory = null;
/**
* The cap on the number of "sleeping" instances in <code>each</code> pool.
@@ -625,6 +625,6 @@ public class StackKeyedObjectPool extend
* Number of active objects borrowed and not yet returned by pool
* @deprecated to be removed in pool 2.0. Use {@link #getActiveCount()}.
*/
- protected HashMap _activeCount = null;
+ protected HashMap<K, Integer> _activeCount = null;
}
Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPoolFactory.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPoolFactory.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackKeyedObjectPoolFactory.java Wed Dec 21 13:03:54 2011
@@ -31,14 +31,14 @@ import org.apache.commons.pool.KeyedPool
* @version $Revision$ $Date$
* @since Pool 1.0
*/
-public class StackKeyedObjectPoolFactory implements KeyedObjectPoolFactory {
+public class StackKeyedObjectPoolFactory<K, V> implements KeyedObjectPoolFactory<K, V> {
/**
* Create a new StackKeyedObjectPoolFactory.
*
* @see StackKeyedObjectPool#StackKeyedObjectPool()
*/
public StackKeyedObjectPoolFactory() {
- this((KeyedPoolableObjectFactory)null,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
+ this(null,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
}
/**
@@ -48,7 +48,7 @@ public class StackKeyedObjectPoolFactory
* @see StackKeyedObjectPool#StackKeyedObjectPool(int)
*/
public StackKeyedObjectPoolFactory(int maxSleeping) {
- this((KeyedPoolableObjectFactory)null,maxSleeping,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
+ this(null,maxSleeping,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
}
/**
@@ -60,7 +60,7 @@ public class StackKeyedObjectPoolFactory
* @see StackKeyedObjectPool#StackKeyedObjectPool(int, int)
*/
public StackKeyedObjectPoolFactory(int maxSleeping, int initialCapacity) {
- this((KeyedPoolableObjectFactory)null,maxSleeping,initialCapacity);
+ this(null,maxSleeping,initialCapacity);
}
/**
@@ -69,7 +69,7 @@ public class StackKeyedObjectPoolFactory
* @param factory the KeyedPoolableObjectFactory used by created pools.
* @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory)
*/
- public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory) {
+ public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory) {
this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
}
@@ -80,7 +80,7 @@ public class StackKeyedObjectPoolFactory
* @param maxSleeping cap on the number of "sleeping" instances in the pool.
* @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int)
*/
- public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxSleeping) {
+ public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxSleeping) {
this(factory,maxSleeping,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
}
@@ -93,7 +93,7 @@ public class StackKeyedObjectPoolFactory
* it does not cause the pool to be pre-populated.)
* @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory, int, int)
*/
- public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxSleeping, int initialCapacity) {
+ public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K, V> factory, int maxSleeping, int initialCapacity) {
_factory = factory;
_maxSleeping = maxSleeping;
_initCapacity = initialCapacity;
@@ -104,15 +104,15 @@ public class StackKeyedObjectPoolFactory
*
* @return a new StackKeyedObjectPool with the configured factory, maxSleeping and initialCapacity
*/
- public KeyedObjectPool createPool() {
- return new StackKeyedObjectPool(_factory,_maxSleeping,_initCapacity);
+ public KeyedObjectPool<K, V> createPool() {
+ return new StackKeyedObjectPool<K, V>(_factory,_maxSleeping,_initCapacity);
}
/**
* KeyedPoolableObjectFactory used by StackKeyedObjectPools created by this factory
* @deprecated to be removed in pool 2.0
*/
- protected KeyedPoolableObjectFactory _factory = null;
+ protected KeyedPoolableObjectFactory<K, V> _factory = null;
/**
* Maximum number of idle instances in each keyed pool for StackKeyedObjectPools created by this factory
@@ -132,7 +132,7 @@ public class StackKeyedObjectPoolFactory
* @return factory setting for created pools
* @since 1.5.5
*/
- public KeyedPoolableObjectFactory getFactory() {
+ public KeyedPoolableObjectFactory<K, V> getFactory() {
return _factory;
}
Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackObjectPool.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackObjectPool.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackObjectPool.java Wed Dec 21 13:03:54 2011
@@ -44,7 +44,7 @@ import org.apache.commons.pool.PoolableO
* @version $Revision$ $Date$
* @since Pool 1.0
*/
-public class StackObjectPool extends BaseObjectPool implements ObjectPool {
+public class StackObjectPool<T> extends BaseObjectPool<T> implements ObjectPool<T> {
/**
* Create a new pool using no factory. Clients must first
* {@link #setFactory(PoolableObjectFactory) set the factory} or
@@ -56,7 +56,7 @@ public class StackObjectPool extends Bas
* @deprecated to be removed in pool 2.0 - use {@link #StackObjectPool(PoolableObjectFactory)}
*/
public StackObjectPool() {
- this((PoolableObjectFactory)null,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY);
+ this(null,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY);
}
/**
@@ -71,7 +71,7 @@ public class StackObjectPool extends Bas
* @deprecated to be removed in pool 2.0 - use {@link #StackObjectPool(PoolableObjectFactory, int)}
*/
public StackObjectPool(int maxIdle) {
- this((PoolableObjectFactory)null,maxIdle,DEFAULT_INIT_SLEEPING_CAPACITY);
+ this(null,maxIdle,DEFAULT_INIT_SLEEPING_CAPACITY);
}
/**
@@ -88,7 +88,7 @@ public class StackObjectPool extends Bas
* @deprecated to be removed in pool 2.0 - use {@link #StackObjectPool(PoolableObjectFactory, int, int)}
*/
public StackObjectPool(int maxIdle, int initIdleCapacity) {
- this((PoolableObjectFactory)null,maxIdle,initIdleCapacity);
+ this(null,maxIdle,initIdleCapacity);
}
/**
@@ -96,7 +96,7 @@ public class StackObjectPool extends Bas
*
* @param factory the {@link PoolableObjectFactory} used to populate the pool
*/
- public StackObjectPool(PoolableObjectFactory factory) {
+ public StackObjectPool(PoolableObjectFactory<T> factory) {
this(factory,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY);
}
@@ -107,7 +107,7 @@ public class StackObjectPool extends Bas
* @param factory the {@link PoolableObjectFactory} used to populate the pool
* @param maxIdle cap on the number of "sleeping" instances in the pool
*/
- public StackObjectPool(PoolableObjectFactory factory, int maxIdle) {
+ public StackObjectPool(PoolableObjectFactory<T> factory, int maxIdle) {
this(factory,maxIdle,DEFAULT_INIT_SLEEPING_CAPACITY);
}
@@ -126,11 +126,11 @@ public class StackObjectPool extends Bas
* @param initIdleCapacity initial size of the pool (this specifies the size of the container,
* it does not cause the pool to be pre-populated.)
*/
- public StackObjectPool(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) {
+ public StackObjectPool(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) {
_factory = factory;
_maxSleeping = (maxIdle < 0 ? DEFAULT_MAX_SLEEPING : maxIdle);
int initcapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY : initIdleCapacity);
- _pool = new Stack();
+ _pool = new Stack<T>();
_pool.ensureCapacity( initcapacity > _maxSleeping ? _maxSleeping : initcapacity);
}
@@ -156,9 +156,9 @@ public class StackObjectPool extends Bas
*
* @return an instance from the pool
*/
- public synchronized Object borrowObject() throws Exception {
+ public synchronized T borrowObject() throws Exception {
assertOpen();
- Object obj = null;
+ T obj = null;
boolean newlyCreated = false;
while (null == obj) {
if (!_pool.empty()) {
@@ -218,7 +218,7 @@ public class StackObjectPool extends Bas
*
* @param obj instance to return to the pool
*/
- public synchronized void returnObject(Object obj) throws Exception {
+ public synchronized void returnObject(T obj) throws Exception {
boolean success = !isClosed();
if(null != _factory) {
if(!_factory.validateObject(obj)) {
@@ -236,7 +236,7 @@ public class StackObjectPool extends Bas
_numActive--;
if (success) {
- Object toBeDestroyed = null;
+ T toBeDestroyed = null;
if(_pool.size() >= _maxSleeping) {
shouldDestroy = true;
toBeDestroyed = _pool.remove(0); // remove the stalest object
@@ -258,7 +258,7 @@ public class StackObjectPool extends Bas
/**
* {@inheritDoc}
*/
- public synchronized void invalidateObject(Object obj) throws Exception {
+ public synchronized void invalidateObject(T obj) throws Exception {
_numActive--;
if (null != _factory) {
_factory.destroyObject(obj);
@@ -291,7 +291,7 @@ public class StackObjectPool extends Bas
*/
public synchronized void clear() {
if(null != _factory) {
- Iterator it = _pool.iterator();
+ Iterator<T> it = _pool.iterator();
while(it.hasNext()) {
try {
_factory.destroyObject(it.next());
@@ -341,7 +341,7 @@ public class StackObjectPool extends Bas
if (_factory == null) {
throw new IllegalStateException("Cannot add objects without a factory.");
}
- Object obj = _factory.makeObject();
+ T obj = _factory.makeObject();
boolean success = true;
if(!_factory.validateObject(obj)) {
@@ -353,7 +353,7 @@ public class StackObjectPool extends Bas
boolean shouldDestroy = !success;
if (success) {
- Object toBeDestroyed = null;
+ T toBeDestroyed = null;
if(_pool.size() >= _maxSleeping) {
shouldDestroy = true;
toBeDestroyed = _pool.remove(0); // remove the stalest object
@@ -382,7 +382,7 @@ public class StackObjectPool extends Bas
* @throws IllegalStateException when the factory cannot be set at this time
* @deprecated to be removed in pool 2.0
*/
- public synchronized void setFactory(PoolableObjectFactory factory) throws IllegalStateException {
+ public synchronized void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException {
assertOpen();
if(0 < getNumActive()) {
throw new IllegalStateException("Objects are already active");
@@ -408,13 +408,13 @@ public class StackObjectPool extends Bas
* My pool.
* @deprecated to be made private in pool 2.0
*/
- protected Stack _pool = null;
+ protected Stack<T> _pool = null;
/**
* My {@link PoolableObjectFactory}.
* @deprecated to be made private in pool 2.0 - use {@link #getFactory()}
*/
- protected PoolableObjectFactory _factory = null;
+ protected PoolableObjectFactory<T> _factory = null;
/**
* The cap on the number of "sleeping" instances in the pool.
@@ -434,7 +434,7 @@ public class StackObjectPool extends Bas
* @return the factory
* @since 1.5.5
*/
- public synchronized PoolableObjectFactory getFactory() {
+ public synchronized PoolableObjectFactory<T> getFactory() {
return _factory;
}
Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackObjectPoolFactory.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackObjectPoolFactory.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/impl/StackObjectPoolFactory.java Wed Dec 21 13:03:54 2011
@@ -31,7 +31,7 @@ import org.apache.commons.pool.PoolableO
* @version $Revision$ $Date$
* @since Pool 1.0
*/
-public class StackObjectPoolFactory implements ObjectPoolFactory {
+public class StackObjectPoolFactory<T> implements ObjectPoolFactory<T> {
/**
* Create a new StackObjectPoolFactory.
*
@@ -39,7 +39,7 @@ public class StackObjectPoolFactory impl
* @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory)}
*/
public StackObjectPoolFactory() {
- this((PoolableObjectFactory)null,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
+ this(null,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
}
/**
@@ -50,7 +50,7 @@ public class StackObjectPoolFactory impl
* @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory, int)}
*/
public StackObjectPoolFactory(int maxIdle) {
- this((PoolableObjectFactory)null,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
+ this(null,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
}
/**
@@ -63,7 +63,7 @@ public class StackObjectPoolFactory impl
* @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory, int, int)}
*/
public StackObjectPoolFactory(int maxIdle, int initIdleCapacity) {
- this((PoolableObjectFactory)null,maxIdle,initIdleCapacity);
+ this(null,maxIdle,initIdleCapacity);
}
/**
@@ -72,7 +72,7 @@ public class StackObjectPoolFactory impl
* @param factory the PoolableObjectFactory used by created pools.
* @see StackObjectPool#StackObjectPool(PoolableObjectFactory)
*/
- public StackObjectPoolFactory(PoolableObjectFactory factory) {
+ public StackObjectPoolFactory(PoolableObjectFactory<T> factory) {
this(factory,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
}
@@ -82,7 +82,7 @@ public class StackObjectPoolFactory impl
* @param factory the PoolableObjectFactory used by created pools.
* @param maxIdle cap on the number of "sleeping" instances in the pool.
*/
- public StackObjectPoolFactory(PoolableObjectFactory factory, int maxIdle) {
+ public StackObjectPoolFactory(PoolableObjectFactory<T> factory, int maxIdle) {
this(factory,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
}
@@ -94,7 +94,7 @@ public class StackObjectPoolFactory impl
* @param initIdleCapacity - initial size of the pool (this specifies the size of the container,
* it does not cause the pool to be pre-populated.)
*/
- public StackObjectPoolFactory(PoolableObjectFactory factory, int maxIdle, int initIdleCapacity) {
+ public StackObjectPoolFactory(PoolableObjectFactory<T> factory, int maxIdle, int initIdleCapacity) {
_factory = factory;
_maxSleeping = maxIdle;
_initCapacity = initIdleCapacity;
@@ -105,15 +105,15 @@ public class StackObjectPoolFactory impl
*
* @return a new StackObjectPool with the configured factory, maxIdle and initial capacity settings
*/
- public ObjectPool createPool() {
- return new StackObjectPool(_factory,_maxSleeping,_initCapacity);
+ public ObjectPool<T> createPool() {
+ return new StackObjectPool<T>(_factory,_maxSleeping,_initCapacity);
}
/**
* The PoolableObjectFactory used by created pools.
* @deprecated to be made private in pool 2.0
*/
- protected PoolableObjectFactory _factory = null;
+ protected PoolableObjectFactory<T> _factory = null;
/**
* The maximum number of idle instances in created pools.
@@ -133,7 +133,7 @@ public class StackObjectPoolFactory impl
* @return the PoolableObjectFactory used by created pools
* @since 1.5.5
*/
- public PoolableObjectFactory getFactory() {
+ public PoolableObjectFactory<T> getFactory() {
return _factory;
}
Modified: commons/proper/pool/branches/POOL_1_X/src/site/site.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/site/site.xml?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/site/site.xml (original)
+++ commons/proper/pool/branches/POOL_1_X/src/site/site.xml Wed Dec 21 13:03:54 2011
@@ -42,7 +42,7 @@
<item name="Mailing Lists" href="/mail-lists.html"/>
<item name="Issue Tracking" href="/issue-tracking.html"/>
<item name="Source Repository" href="/source-repository.html"/>
- <item name="Javadoc (1.5.8-SNAPSHOT)" href="apidocs/index.html"/>
+ <item name="Javadoc (1.6-SNAPSHOT)" href="apidocs/index.html"/>
</menu>
</body>