You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/04/24 22:04:36 UTC
svn commit: r1096365 - in
/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl:
GenericKeyedObjectPool.java GenericKeyedObjectPoolFactory.java
Author: simonetripodi
Date: Sun Apr 24 20:04:36 2011
New Revision: 1096365
URL: http://svn.apache.org/viewvc?rev=1096365&view=rev
Log:
restored generics to GenericKeyedObjectPool(Factory) classes
Modified:
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPoolFactory.java
Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1096365&r1=1096364&r2=1096365&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 Sun Apr 24 20:04:36 2011
@@ -26,9 +26,8 @@ import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
-import java.util.TreeMap;
import java.util.TimerTask;
-import java.util.Map.Entry;
+import java.util.TreeMap;
import org.apache.commons.pool2.BaseKeyedObjectPool;
import org.apache.commons.pool2.KeyedObjectPool;
@@ -201,7 +200,7 @@ import org.apache.commons.pool2.PoolUtil
* @version $Revision$ $Date$
* @since Pool 1.0
*/
-public class GenericKeyedObjectPool extends BaseKeyedObjectPool implements KeyedObjectPool {
+public class GenericKeyedObjectPool<K,V> extends BaseKeyedObjectPool<K,V> implements KeyedObjectPool<K,V> {
//--- public constants -------------------------------------------
@@ -368,7 +367,7 @@ public class GenericKeyedObjectPool exte
* @param factory the <code>KeyedPoolableObjectFactory</code> to use to create, validate, and destroy
* objects if not <code>null</code>
*/
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory) {
+ public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,V> 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);
@@ -380,7 +379,7 @@ public class GenericKeyedObjectPool exte
* if not <code>null</code>
* @param config a non-<code>null</code> {@link GenericKeyedObjectPool.Config} describing the configuration
*/
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, GenericKeyedObjectPool.Config config) {
+ public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,V> 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);
@@ -392,7 +391,7 @@ public class GenericKeyedObjectPool exte
* 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 factory, int maxActive) {
+ public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,V> 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);
@@ -407,7 +406,7 @@ public class GenericKeyedObjectPool exte
* @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 factory, int maxActive, byte whenExhaustedAction,
+ public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory, int maxActive, byte 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,
@@ -427,7 +426,7 @@ public class GenericKeyedObjectPool exte
* @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject}
* method (see {@link #setTestOnReturn})
*/
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
+ public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory, int maxActive, byte 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,
@@ -445,7 +444,7 @@ public class GenericKeyedObjectPool exte
* <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 factory, int maxActive, byte whenExhaustedAction,
+ public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory, int maxActive, byte 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,
@@ -467,7 +466,7 @@ public class GenericKeyedObjectPool exte
* @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject}
* method (see {@link #setTestOnReturn})
*/
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
+ public GenericKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory, int maxActive, byte 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,
@@ -498,7 +497,7 @@ public class GenericKeyedObjectPool exte
* @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any
* (see {@link #setTestWhileIdle})
*/
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
+ public GenericKeyedObjectPool(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,
@@ -530,7 +529,7 @@ public class GenericKeyedObjectPool exte
* @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any
* (see {@link #setTestWhileIdle})
*/
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
+ public GenericKeyedObjectPool(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) {
@@ -565,7 +564,7 @@ public class GenericKeyedObjectPool exte
* (see {@link #setTestWhileIdle})
* @since Pool 1.3
*/
- public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction,
+ public GenericKeyedObjectPool(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) {
@@ -601,7 +600,7 @@ public class GenericKeyedObjectPool exte
* @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 factory, int maxActive, byte whenExhaustedAction,
+ public GenericKeyedObjectPool(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) {
@@ -628,8 +627,8 @@ public class GenericKeyedObjectPool exte
_minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
_testWhileIdle = testWhileIdle;
- _poolMap = new HashMap();
- _poolList = new CursorableLinkedList();
+ _poolMap = new HashMap<K,ObjectQueue>();
+ _poolList = new CursorableLinkedList<K>();
startEvictor(_timeBetweenEvictionRunsMillis);
}
@@ -1085,7 +1084,8 @@ public class GenericKeyedObjectPool exte
* @return object instance from the keyed pool
* @throws NoSuchElementException if a keyed object instance cannot be returned.
*/
- public Object borrowObject(Object key) throws Exception {
+ @Override
+ public V borrowObject(K key) throws Exception {
long starttime = System.currentTimeMillis();
Latch latch = new Latch(key);
byte whenExhaustedAction;
@@ -1209,8 +1209,8 @@ public class GenericKeyedObjectPool exte
boolean newlyCreated = false;
if (null == latch.getPair()) {
try {
- Object obj = _factory.makeObject(key);
- latch.setPair(new ObjectTimestampPair(obj));
+ V obj = _factory.makeObject(key);
+ latch.setPair(new ObjectTimestampPair<V>(obj));
newlyCreated = true;
} finally {
if (!newlyCreated) {
@@ -1275,13 +1275,13 @@ public class GenericKeyedObjectPool exte
synchronized (this) {
if (isClosed()) return;
-
- Iterator allocationQueueIter = _allocationQueue.iterator();
-
+
+ Iterator<Latch> allocationQueueIter = _allocationQueue.iterator();
+
while (allocationQueueIter.hasNext()) {
// First use any objects in the pool to clear the queue
- Latch latch = (Latch) allocationQueueIter.next();
- ObjectQueue pool = (ObjectQueue)(_poolMap.get(latch.getkey()));
+ Latch latch = allocationQueueIter.next();
+ ObjectQueue pool = _poolMap.get(latch.getkey());
if (null == pool) {
pool = new ObjectQueue();
_poolMap.put(latch.getkey(), pool);
@@ -1290,8 +1290,7 @@ public class GenericKeyedObjectPool exte
latch.setPool(pool);
if (!pool.queue.isEmpty()) {
allocationQueueIter.remove();
- latch.setPair(
- (ObjectTimestampPair) pool.queue.removeFirst());
+ latch.setPair(pool.queue.removeFirst());
pool.incrementInternalProcessingCount();
_totalIdle--;
synchronized (latch) {
@@ -1360,15 +1359,16 @@ public class GenericKeyedObjectPool exte
* while removed items are being destroyed.</li>
* <li>Exceptions encountered destroying idle instances are swallowed.</li></ul></p>
*/
+ @Override
public void clear() {
- Map toDestroy = new HashMap();
+ Map<K,List<ObjectTimestampPair<V>>> toDestroy = new HashMap<K,List<ObjectTimestampPair<V>>>();
synchronized (this) {
- for (Iterator it = _poolMap.keySet().iterator(); it.hasNext();) {
- Object key = it.next();
- ObjectQueue pool = (ObjectQueue)_poolMap.get(key);
+ for (Iterator<K> it = _poolMap.keySet().iterator(); it.hasNext();) {
+ K key = it.next();
+ ObjectQueue pool = _poolMap.get(key);
// Copy objects to new list so pool.queue can be cleared inside
// the sync
- List objects = new ArrayList();
+ List<ObjectTimestampPair<V>> objects = new ArrayList<ObjectTimestampPair<V>>();
objects.addAll(pool.queue);
toDestroy.put(key, objects);
it.remove();
@@ -1390,15 +1390,15 @@ public class GenericKeyedObjectPool exte
*/
public void clearOldest() {
// Map of objects to destroy my key
- final Map toDestroy = new HashMap();
+ final Map<K, List<ObjectTimestampPair<V>>> toDestroy = new HashMap<K, List<ObjectTimestampPair<V>>>();
// build sorted map of idle objects
- final Map map = new TreeMap();
+ final Map<ObjectTimestampPair<V>, K> map = new TreeMap<ObjectTimestampPair<V>, K>();
synchronized (this) {
- for (Iterator keyiter = _poolMap.keySet().iterator(); keyiter.hasNext();) {
- final Object key = keyiter.next();
- final CursorableLinkedList list = ((ObjectQueue)_poolMap.get(key)).queue;
- for (Iterator it = list.iterator(); it.hasNext();) {
+ for (Iterator<K> keyiter = _poolMap.keySet().iterator(); keyiter.hasNext();) {
+ final K key = keyiter.next();
+ final CursorableLinkedList<ObjectTimestampPair<V>> list = _poolMap.get(key).queue;
+ for (Iterator<ObjectTimestampPair<V>> it = list.iterator(); it.hasNext();) {
// each item into the map uses the objectimestamppair object
// as the key. It then gets sorted based on the timstamp field
// each value in the map is the parent list it belongs in.
@@ -1407,30 +1407,35 @@ public class GenericKeyedObjectPool exte
}
// Now iterate created map and kill the first 15% plus one to account for zero
- Set setPairKeys = map.entrySet();
+ Set<Map.Entry<ObjectTimestampPair<V>, K>> setPairKeys = map.entrySet();
int itemsToRemove = ((int) (map.size() * 0.15)) + 1;
- Iterator iter = setPairKeys.iterator();
+ Iterator<Map.Entry<ObjectTimestampPair<V>, K>> iter = setPairKeys.iterator();
while (iter.hasNext() && itemsToRemove > 0) {
- Map.Entry entry = (Map.Entry) iter.next();
+ Map.Entry<ObjectTimestampPair<V>, K> entry = iter.next();
// kind of backwards on naming. In the map, each key is the objecttimestamppair
// because it has the ordering with the timestamp value. Each value that the
// key references is the key of the list it belongs to.
- Object key = entry.getValue();
- ObjectTimestampPair pairTimeStamp = (ObjectTimestampPair) entry.getKey();
- ObjectQueue objectQueue = (ObjectQueue)_poolMap.get(key);
- final CursorableLinkedList list = objectQueue.queue;
+ K key = entry.getValue();
+ ObjectTimestampPair<V> pairTimeStamp = entry.getKey();
+ ObjectQueue objectQueue = _poolMap.get(key);
+ final CursorableLinkedList<ObjectTimestampPair<V>> list = objectQueue.queue;
list.remove(pairTimeStamp);
if (toDestroy.containsKey(key)) {
- ((List)toDestroy.get(key)).add(pairTimeStamp);
+ toDestroy.get(key).add(pairTimeStamp);
} else {
- List listForKey = new ArrayList();
+ List<ObjectTimestampPair<V>> listForKey = new ArrayList<ObjectTimestampPair<V>>();
listForKey.add(pairTimeStamp);
toDestroy.put(key, listForKey);
}
- objectQueue.incrementInternalProcessingCount();
+ // if that was the last object for that key, drop that pool
+ if (list.isEmpty()) {
+ _poolMap.remove(key);
+ _poolList.remove(key);
+ }
_totalIdle--;
+ _totalInternalProcessing++;
itemsToRemove--;
}
@@ -1443,12 +1448,13 @@ public class GenericKeyedObjectPool exte
*
* @param key the key to clear
*/
- public void clear(Object key) {
- Map toDestroy = new HashMap();
+ @Override
+ public void clear(K key) {
+ Map<K, List<ObjectTimestampPair<V>>> toDestroy = new HashMap<K, List<ObjectTimestampPair<V>>>();
final ObjectQueue pool;
synchronized (this) {
- pool = (ObjectQueue)(_poolMap.remove(key));
+ pool = _poolMap.remove(key);
if (pool == null) {
return;
} else {
@@ -1456,7 +1462,7 @@ public class GenericKeyedObjectPool exte
}
// Copy objects to new list so pool.queue can be cleared inside
// the sync
- List objects = new ArrayList();
+ List<ObjectTimestampPair<V>> objects = new ArrayList<ObjectTimestampPair<V>>();
objects.addAll(pool.queue);
toDestroy.put(key, objects);
_totalIdle = _totalIdle - pool.queue.size();
@@ -1474,21 +1480,19 @@ public class GenericKeyedObjectPool exte
* @param m Map containing keyed pools to clear
* @param factory KeyedPoolableObjectFactory used to destroy the objects
*/
- private void destroy(Map m, KeyedPoolableObjectFactory factory) {
- for (Iterator entries = m.entrySet().iterator(); entries.hasNext();) {
- Map.Entry entry = (Entry) entries.next();
- Object key = entry.getKey();
- Collection c = (Collection) entry.getValue();
- for (Iterator it = c.iterator(); it.hasNext();) {
+ private void destroy(Map<K,List<ObjectTimestampPair<V>>> m, KeyedPoolableObjectFactory<K,V> factory) {
+ for (Iterator<Map.Entry<K,List<ObjectTimestampPair<V>>>> entries = m.entrySet().iterator(); entries.hasNext();) {
+ Map.Entry<K,List<ObjectTimestampPair<V>>> entry = entries.next();
+ K key = entry.getKey();
+ Collection<ObjectTimestampPair<V>> c = entry.getValue();
+ for (Iterator<ObjectTimestampPair<V>> it = c.iterator(); it.hasNext();) {
try {
- factory.destroyObject(
- key,((ObjectTimestampPair)(it.next())).value);
- } catch(Exception e) {
+ factory.destroyObject(key, it.next().value);
+ } catch (Exception e) {
// ignore error, keep destroying the rest
} finally {
synchronized(this) {
- ObjectQueue objectQueue =
- (ObjectQueue) _poolMap.get(key);
+ ObjectQueue objectQueue = _poolMap.get(key);
if (objectQueue != null) {
objectQueue.decrementInternalProcessingCount();
if (objectQueue.internalProcessingCount == 0 &&
@@ -1511,6 +1515,7 @@ public class GenericKeyedObjectPool exte
*
* @return the total number of instances currently borrowed from this pool
*/
+ @Override
public synchronized int getNumActive() {
return _totalActive;
}
@@ -1520,6 +1525,7 @@ public class GenericKeyedObjectPool exte
*
* @return the total number of instances currently idle in this pool
*/
+ @Override
public synchronized int getNumIdle() {
return _totalIdle;
}
@@ -1531,8 +1537,9 @@ public class GenericKeyedObjectPool exte
* @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) {
- final ObjectQueue pool = (ObjectQueue)(_poolMap.get(key));
+ @Override
+ public synchronized int getNumActive(K key) {
+ final ObjectQueue pool = (_poolMap.get(key));
return pool != null ? pool.activeCount : 0;
}
@@ -1542,8 +1549,9 @@ public class GenericKeyedObjectPool exte
* @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) {
- final ObjectQueue pool = (ObjectQueue)(_poolMap.get(key));
+ @Override
+ public synchronized int getNumIdle(K key) {
+ final ObjectQueue pool = (_poolMap.get(key));
return pool != null ? pool.queue.size() : 0;
}
@@ -1565,7 +1573,8 @@ public class GenericKeyedObjectPool exte
* @param obj instance to return to the keyed pool
* @throws Exception
*/
- public void returnObject(Object key, Object obj) throws Exception {
+ @Override
+ public void returnObject(K key, V obj) throws Exception {
try {
addObjectToPool(key, obj, true);
} catch (Exception e) {
@@ -1578,7 +1587,7 @@ public class GenericKeyedObjectPool exte
// TODO: Correctness here depends on control in addObjectToPool.
// These two methods should be refactored, removing the
// "behavior flag", decrementNumActive, from addObjectToPool.
- ObjectQueue pool = (ObjectQueue) (_poolMap.get(key));
+ ObjectQueue pool = _poolMap.get(key);
if (pool != null) {
synchronized(this) {
pool.decrementActiveCount();
@@ -1609,7 +1618,7 @@ public class GenericKeyedObjectPool exte
* @param decrementNumActive whether or not to decrement the active count associated with the keyed pool
* @throws Exception
*/
- private void addObjectToPool(Object key, Object obj,
+ private void addObjectToPool(K key, V obj,
boolean decrementNumActive) throws Exception {
// if we need to validate this object, do so
@@ -1628,7 +1637,7 @@ public class GenericKeyedObjectPool exte
boolean doAllocate = false;
synchronized (this) {
// grab the pool (list) of objects associated with the given key
- pool = (ObjectQueue) (_poolMap.get(key));
+ pool = _poolMap.get(key);
// if it doesn't exist, create it
if (null == pool) {
pool = new ObjectQueue();
@@ -1646,9 +1655,9 @@ public class GenericKeyedObjectPool exte
// borrowObject always takes the first element from the queue,
// so for LIFO, push on top, FIFO add to end
if (_lifo) {
- pool.queue.addFirst(new ObjectTimestampPair(obj));
+ pool.queue.addFirst(new ObjectTimestampPair<V>(obj));
} else {
- pool.queue.addLast(new ObjectTimestampPair(obj));
+ pool.queue.addLast(new ObjectTimestampPair<V>(obj));
}
_totalIdle++;
if (decrementNumActive) {
@@ -1694,12 +1703,13 @@ public class GenericKeyedObjectPool exte
* @param obj instance to invalidate
* @throws Exception if an exception occurs destroying the object
*/
- public void invalidateObject(Object key, Object obj) throws Exception {
+ @Override
+ public void invalidateObject(K key, V obj) throws Exception {
try {
_factory.destroyObject(key, obj);
} finally {
synchronized (this) {
- ObjectQueue pool = (ObjectQueue) (_poolMap.get(key));
+ ObjectQueue pool = _poolMap.get(key);
if (null == pool) {
pool = new ObjectQueue();
_poolMap.put(key, pool);
@@ -1721,12 +1731,13 @@ public class GenericKeyedObjectPool exte
* @throws IllegalStateException when no {@link #setFactory factory} has been set or after {@link #close} has been
* called on this pool.
*/
- public void addObject(Object key) throws Exception {
+ @Override
+ public 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 {
assertOpen();
addObjectToPool(key, obj, false);
@@ -1752,8 +1763,8 @@ public class GenericKeyedObjectPool exte
* will be populated immediately.
* @since Pool 1.3
*/
- public synchronized void preparePool(Object key, boolean populateImmediately) {
- ObjectQueue pool = (ObjectQueue)(_poolMap.get(key));
+ public synchronized void preparePool(K key, boolean populateImmediately) {
+ ObjectQueue pool = (_poolMap.get(key));
if (null == pool) {
pool = new ObjectQueue();
_poolMap.put(key,pool);
@@ -1781,6 +1792,7 @@ public class GenericKeyedObjectPool exte
*
* @throws Exception
*/
+ @Override
public void close() throws Exception {
super.close();
synchronized (this) {
@@ -1808,17 +1820,17 @@ public class GenericKeyedObjectPool exte
* @throws IllegalStateException if there are active (checked out) instances associated with this keyed object pool
* @deprecated to be removed in version 2.0
*/
- public void setFactory(KeyedPoolableObjectFactory factory) throws IllegalStateException {
+ public void setFactory(KeyedPoolableObjectFactory<K,V> factory) throws IllegalStateException {
Map toDestroy = new HashMap();
- final KeyedPoolableObjectFactory oldFactory = _factory;
+ final KeyedPoolableObjectFactory<K,V> oldFactory = _factory;
synchronized (this) {
assertOpen();
if (0 < getNumActive()) {
throw new IllegalStateException("Objects are already active");
} else {
- for (Iterator it = _poolMap.keySet().iterator(); it.hasNext();) {
- Object key = it.next();
- ObjectQueue pool = (ObjectQueue)_poolMap.get(key);
+ for (Iterator<K> it = _poolMap.keySet().iterator(); it.hasNext();) {
+ K key = it.next();
+ ObjectQueue pool = _poolMap.get(key);
if (pool != null) {
// Copy objects to new list so pool.queue can be cleared
// inside the sync
@@ -1854,7 +1866,7 @@ public class GenericKeyedObjectPool exte
* @throws Exception when there is a problem evicting idle objects.
*/
public void evict() throws Exception {
- Object key = null;
+ K key = null;
boolean testWhileIdle;
long minEvictableIdleTimeMillis;
@@ -1873,7 +1885,7 @@ public class GenericKeyedObjectPool exte
}
for (int i=0, m=getNumTests(); i<m; i++) {
- final ObjectTimestampPair pair;
+ final ObjectTimestampPair<V> pair;
synchronized (this) {
// make sure pool map is not empty; otherwise do nothing
if (_poolMap == null || _poolMap.size() == 0) {
@@ -1936,10 +1948,10 @@ public class GenericKeyedObjectPool exte
// if LIFO and the _evictionCursor has a previous object,
// or FIFO and _evictionCursor has a next object, test it
pair = _lifo ?
- (ObjectTimestampPair) _evictionCursor.previous() :
- (ObjectTimestampPair) _evictionCursor.next();
+ _evictionCursor.previous() :
+ _evictionCursor.next();
_evictionCursor.remove();
- ObjectQueue objectQueue = (ObjectQueue) _poolMap.get(key);
+ ObjectQueue objectQueue = _poolMap.get(key);
objectQueue.incrementInternalProcessingCount();
_totalIdle--;
}
@@ -1980,7 +1992,7 @@ public class GenericKeyedObjectPool exte
}
synchronized (this) {
ObjectQueue objectQueue =
- (ObjectQueue)_poolMap.get(key);
+ _poolMap.get(key);
objectQueue.decrementInternalProcessingCount();
if (removeObject) {
if (objectQueue.queue.isEmpty() &&
@@ -2022,16 +2034,16 @@ public class GenericKeyedObjectPool exte
*
* @param key eviction key
*/
- private void resetEvictionObjectCursor(Object key) {
+ private void resetEvictionObjectCursor(K key) {
if (_evictionCursor != null) {
_evictionCursor.close();
}
if (_poolMap == null) {
return;
}
- ObjectQueue pool = (ObjectQueue) (_poolMap.get(key));
+ ObjectQueue pool = (_poolMap.get(key));
if (pool != null) {
- CursorableLinkedList queue = pool.queue;
+ CursorableLinkedList<ObjectTimestampPair<V>> queue = pool.queue;
_evictionCursor = queue.cursor(_lifo ? queue.size() : 0);
}
}
@@ -2043,13 +2055,14 @@ public class GenericKeyedObjectPool exte
* @see #setMinIdle
* @throws Exception If there was an error whilst creating the pooled objects.
*/
+ @SuppressWarnings("unchecked") // OK, see (1)
private void ensureMinIdle() throws Exception {
//Check if should sustain the pool
if (_minIdle > 0) {
- Object[] keysCopy;
+ K[] keysCopy;
synchronized(this) {
// Get the current set of keys
- keysCopy = _poolMap.keySet().toArray();
+ keysCopy = (K[]) _poolMap.keySet().toArray(); // (1) keySet() is of type Set<T>
}
// Loop through all elements in _poolList
@@ -2073,11 +2086,11 @@ public class GenericKeyedObjectPool exte
* @param key The key to process
* @throws Exception If there was an error whilst creating the pooled objects
*/
- private void ensureMinIdle(Object key) throws Exception {
+ private void ensureMinIdle(K key) throws Exception {
// Calculate current pool objects
ObjectQueue pool;
synchronized(this) {
- pool = (ObjectQueue)(_poolMap.get(key));
+ pool = _poolMap.get(key);
}
if (pool == null) {
return;
@@ -2132,9 +2145,7 @@ public class GenericKeyedObjectPool exte
StringBuffer buf = new StringBuffer();
buf.append("Active: ").append(getNumActive()).append("\n");
buf.append("Idle: ").append(getNumIdle()).append("\n");
- Iterator it = _poolMap.keySet().iterator();
- while (it.hasNext()) {
- Object key = it.next();
+ for (K key : _poolMap.keySet()) {
buf.append("\t").append(key).append(" ").append(_poolMap.get(key)).append("\n");
}
return buf.toString();
@@ -2201,8 +2212,8 @@ public class GenericKeyedObjectPool exte
private int activeCount = 0;
/** Idle instance queue */
- private final CursorableLinkedList queue = new CursorableLinkedList();
-
+ private final CursorableLinkedList<ObjectTimestampPair<V>> queue = new CursorableLinkedList<ObjectTimestampPair<V>>();
+
/** Number of instances in process of being created */
private int internalProcessingCount = 0;
@@ -2248,13 +2259,13 @@ public class GenericKeyedObjectPool exte
*
* This is also used by {@link GenericObjectPool}.
*/
- static class ObjectTimestampPair implements Comparable {
+ static class ObjectTimestampPair<V> implements Comparable<ObjectTimestampPair<V>> {
//CHECKSTYLE: stop VisibilityModifier
/**
* Object instance
* @deprecated this field will be made private and final in version 2.0
*/
- Object value;
+ V value;
/**
* timestamp
@@ -2267,7 +2278,7 @@ public class GenericKeyedObjectPool exte
* Create a new ObjectTimestampPair using the given object and the current system time.
* @param val object instance
*/
- ObjectTimestampPair(Object val) {
+ ObjectTimestampPair(V val) {
this(val, System.currentTimeMillis());
}
@@ -2276,7 +2287,7 @@ public class GenericKeyedObjectPool exte
* @param val object instance
* @param time long representation of timestamp
*/
- ObjectTimestampPair(Object val, long time) {
+ ObjectTimestampPair(V val, long time) {
value = val;
tstamp = time;
}
@@ -2286,6 +2297,7 @@ public class GenericKeyedObjectPool exte
*
* @return String representing this ObjectTimestampPair
*/
+ @Override
public String toString() {
return value + ";" + tstamp;
}
@@ -2294,21 +2306,10 @@ public class GenericKeyedObjectPool exte
* Compares this to another object by casting the argument to an
* ObjectTimestampPair.
*
- * @param obj object to cmpare
- * @return result of comparison
- */
- public int compareTo(Object obj) {
- return compareTo((ObjectTimestampPair) obj);
- }
-
- /**
- * Compares this to another ObjectTimestampPair, using the timestamp as basis for comparison.
- * Implementation is consistent with equals.
- *
* @param other object to compare
* @return result of comparison
*/
- public int compareTo(ObjectTimestampPair other) {
+ public int compareTo(ObjectTimestampPair<V> other) {
final long tstampdiff = this.tstamp - other.tstamp;
if (tstampdiff == 0) {
// make sure the natural ordering is consistent with equals
@@ -2323,7 +2324,7 @@ public class GenericKeyedObjectPool exte
/**
* @return the value
*/
- public Object getValue() {
+ public V getValue() {
return value;
}
@@ -2344,6 +2345,7 @@ public class GenericKeyedObjectPool exte
* Run pool maintenance. Evict objects qualifying for eviction and then
* invoke {@link GenericKeyedObjectPool#ensureMinIdle()}.
*/
+ @Override
public void run() {
//Evict from the pool
try {
@@ -2434,17 +2436,17 @@ public class GenericKeyedObjectPool exte
*
* @since 1.5
*/
- private static final class Latch {
-
+ private final class Latch {
+
/** key of associated pool */
- private final Object _key;
-
+ private final K _key;
+
/** keyed pool associated with this latch */
private ObjectQueue _pool;
/** holds an ObjectTimestampPair when this latch has been allocated an instance */
- private ObjectTimestampPair _pair;
-
+ private ObjectTimestampPair<V> _pair;
+
/** indicates that this latch can create an instance */
private boolean _mayCreate = false;
@@ -2452,7 +2454,7 @@ public class GenericKeyedObjectPool exte
* Create a latch with the given key
* @param key key of the pool associated with this latch
*/
- private Latch(Object key) {
+ private Latch(K key) {
_key = key;
}
@@ -2460,7 +2462,7 @@ public class GenericKeyedObjectPool exte
* Retuns the key of the associated pool
* @return associated pool key
*/
- private synchronized Object getkey() {
+ private synchronized K getkey() {
return _key;
}
@@ -2485,7 +2487,7 @@ public class GenericKeyedObjectPool exte
* Returns null if this latch does not have an instance allocated to it.
* @return the associated ObjectTimestampPair
*/
- private synchronized ObjectTimestampPair getPair() {
+ private synchronized ObjectTimestampPair<V> getPair() {
return _pair;
}
@@ -2493,7 +2495,7 @@ public class GenericKeyedObjectPool exte
* Allocate an ObjectTimestampPair to this latch.
* @param pair ObjectTimestampPair on this latch
*/
- private synchronized void setPair(ObjectTimestampPair pair) {
+ private synchronized void setPair(ObjectTimestampPair<V> pair) {
_pair = pair;
}
@@ -2664,7 +2666,7 @@ public class GenericKeyedObjectPool exte
private long _minEvictableIdleTimeMillis = DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
/** My hash of pools (ObjectQueue). */
- private Map _poolMap = null;
+ private Map<K,ObjectQueue> _poolMap = null;
/** The total number of active instances. */
private int _totalActive = 0;
@@ -2680,7 +2682,7 @@ public class GenericKeyedObjectPool exte
private int _totalInternalProcessing = 0;
/** My {@link KeyedPoolableObjectFactory}. */
- private KeyedPoolableObjectFactory _factory = null;
+ private KeyedPoolableObjectFactory<K,V> _factory = null;
/**
* My idle object eviction {@link TimerTask}, if any.
@@ -2691,13 +2693,13 @@ public class GenericKeyedObjectPool exte
* A cursorable list of my pools.
* @see GenericKeyedObjectPool.Evictor#run
*/
- private CursorableLinkedList _poolList = null;
+ private CursorableLinkedList<K> _poolList = null;
/** Eviction cursor (over instances within-key) */
- private CursorableLinkedList.Cursor _evictionCursor = null;
+ private CursorableLinkedList<ObjectTimestampPair<V>>.Cursor _evictionCursor = null;
/** Eviction cursor (over keys) */
- private CursorableLinkedList.Cursor _evictionKeyCursor = null;
+ private CursorableLinkedList<K>.Cursor _evictionKeyCursor = null;
/** Whether or not the pools behave as LIFO queues (last in first out) */
private boolean _lifo = DEFAULT_LIFO;
@@ -2707,6 +2709,6 @@ public class GenericKeyedObjectPool exte
* that objects can be allocated in the order in which the threads requested
* them.
*/
- private LinkedList _allocationQueue = new LinkedList();
+ private LinkedList<Latch> _allocationQueue = new LinkedList<Latch>();
}
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=1096365&r1=1096364&r2=1096365&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 Sun Apr 24 20:04:36 2011
@@ -32,14 +32,14 @@ import org.apache.commons.pool2.KeyedPoo
* @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.