commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1221705 [2/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...
Date Wed, 21 Dec 2011 13:03:55 GMT
Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/PoolUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/PoolUtils.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/PoolUtils.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/PoolUtils.java Wed Dec 21 13:03:54 2011
@@ -18,13 +18,13 @@
 package org.apache.commons.pool;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Timer;
 import java.util.TimerTask;
-import java.util.Collections;
 
 /**
  * This class consists exclusively of static methods that operate on or return ObjectPool
@@ -81,7 +81,7 @@ public final class PoolUtils {
      * @see #adapt(KeyedPoolableObjectFactory, Object)
      * @since Pool 1.3
      */
-    public static PoolableObjectFactory adapt(final KeyedPoolableObjectFactory keyedFactory) throws IllegalArgumentException {
+    public static <V> PoolableObjectFactory<V> adapt(final KeyedPoolableObjectFactory<Object, V> keyedFactory) throws IllegalArgumentException {
         return adapt(keyedFactory, new Object());
     }
 
@@ -96,8 +96,8 @@ public final class PoolUtils {
      * @see #adapt(KeyedPoolableObjectFactory)
      * @since Pool 1.3
      */
-    public static PoolableObjectFactory adapt(final KeyedPoolableObjectFactory keyedFactory, final Object key) throws IllegalArgumentException {
-        return new PoolableObjectFactoryAdaptor(keyedFactory, key);
+    public static <K, V> PoolableObjectFactory<V> adapt(final KeyedPoolableObjectFactory<K, V> keyedFactory, final K key) throws IllegalArgumentException {
+        return new PoolableObjectFactoryAdaptor<K, V>(keyedFactory, key);
     }
 
     /**
@@ -109,8 +109,8 @@ public final class PoolUtils {
      * @throws IllegalArgumentException when <code>factory</code> is <code>null</code>.
      * @since Pool 1.3
      */
-    public static KeyedPoolableObjectFactory adapt(final PoolableObjectFactory factory) throws IllegalArgumentException {
-        return new KeyedPoolableObjectFactoryAdaptor(factory);
+    public static <K, V> KeyedPoolableObjectFactory<K, V> adapt(final PoolableObjectFactory<V> factory) throws IllegalArgumentException {
+        return new KeyedPoolableObjectFactoryAdaptor<K, V>(factory);
     }
 
     /**
@@ -123,7 +123,7 @@ public final class PoolUtils {
      * @see #adapt(KeyedObjectPool, Object)
      * @since Pool 1.3
      */
-    public static ObjectPool adapt(final KeyedObjectPool keyedPool) throws IllegalArgumentException {
+    public static <V> ObjectPool<V> adapt(final KeyedObjectPool<Object, V> keyedPool) throws IllegalArgumentException {
         return adapt(keyedPool, new Object());
     }
 
@@ -138,8 +138,8 @@ public final class PoolUtils {
      * @see #adapt(KeyedObjectPool)
      * @since Pool 1.3
      */
-    public static ObjectPool adapt(final KeyedObjectPool keyedPool, final Object key) throws IllegalArgumentException {
-        return new ObjectPoolAdaptor(keyedPool, key);
+    public static <V> ObjectPool<V> adapt(final KeyedObjectPool<Object, V> keyedPool, final Object key) throws IllegalArgumentException {
+        return new ObjectPoolAdaptor<V>(keyedPool, key);
     }
 
     /**
@@ -151,8 +151,8 @@ public final class PoolUtils {
      * @throws IllegalArgumentException when <code>pool</code> is <code>null</code>.
      * @since Pool 1.3
      */
-    public static KeyedObjectPool adapt(final ObjectPool pool) throws IllegalArgumentException {
-        return new KeyedObjectPoolAdaptor(pool);
+    public static <K, V> KeyedObjectPool<K, V> adapt(final ObjectPool<V> pool) throws IllegalArgumentException {
+        return new KeyedObjectPoolAdaptor<K, V>(pool);
     }
 
     /**
@@ -164,14 +164,14 @@ public final class PoolUtils {
      * @return an <code>ObjectPool</code> that will only allow objects of <code>type</code>
      * @since Pool 1.3
      */
-    public static ObjectPool checkedPool(final ObjectPool pool, final Class type) {
+    public static <T> ObjectPool<T> checkedPool(final ObjectPool<T> pool, final Class<T> type) {
         if (pool == null) {
             throw new IllegalArgumentException("pool must not be null.");
         }
         if (type == null) {
             throw new IllegalArgumentException("type must not be null.");
         }
-        return new CheckedObjectPool(pool, type);
+        return new CheckedObjectPool<T>(pool, type);
     }
 
     /**
@@ -183,14 +183,14 @@ public final class PoolUtils {
      * @return a <code>KeyedObjectPool</code> that will only allow objects of <code>type</code>
      * @since Pool 1.3
      */
-    public static KeyedObjectPool checkedPool(final KeyedObjectPool keyedPool, final Class type) {
+    public static <K, V> KeyedObjectPool<K, V> checkedPool(final KeyedObjectPool<K, V> keyedPool, final Class<V> type) {
         if (keyedPool == null) {
             throw new IllegalArgumentException("keyedPool must not be null.");
         }
         if (type == null) {
             throw new IllegalArgumentException("type must not be null.");
         }
-        return new CheckedKeyedObjectPool(keyedPool, type);
+        return new CheckedKeyedObjectPool<K, V>(keyedPool, type);
     }
 
     /**
@@ -207,14 +207,14 @@ public final class PoolUtils {
      *      valid for {@link Timer#schedule(TimerTask, long, long)}.
      * @since Pool 1.3
      */
-    public static TimerTask checkMinIdle(final ObjectPool pool, final int minIdle, final long period) throws IllegalArgumentException {
+    public static <T> TimerTask checkMinIdle(final ObjectPool<T> pool, final int minIdle, final long period) throws IllegalArgumentException {
         if (pool == null) {
             throw new IllegalArgumentException("keyedPool must not be null.");
         }
         if (minIdle < 0) {
             throw new IllegalArgumentException("minIdle must be non-negative.");
         }
-        final TimerTask task = new ObjectPoolMinIdleTimerTask(pool, minIdle);
+        final TimerTask task = new ObjectPoolMinIdleTimerTask<T>(pool, minIdle);
         getMinIdleTimer().schedule(task, 0L, period);
         return task;
     }
@@ -235,7 +235,7 @@ public final class PoolUtils {
      *      valid for {@link Timer#schedule(TimerTask, long, long)}.
      * @since Pool 1.3
      */
-    public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException {
+    public static <K, V> TimerTask checkMinIdle(final KeyedObjectPool<K, V> keyedPool, final K key, final int minIdle, final long period) throws IllegalArgumentException {
         if (keyedPool == null) {
             throw new IllegalArgumentException("keyedPool must not be null.");
         }
@@ -245,7 +245,7 @@ public final class PoolUtils {
         if (minIdle < 0) {
             throw new IllegalArgumentException("minIdle must be non-negative.");
         }
-        final TimerTask task = new KeyedObjectPoolMinIdleTimerTask(keyedPool, key, minIdle);
+        final TimerTask task = new KeyedObjectPoolMinIdleTimerTask<K, V>(keyedPool, key, minIdle);
         getMinIdleTimer().schedule(task, 0L, period);
         return task;
     }
@@ -266,14 +266,14 @@ public final class PoolUtils {
      * @see #checkMinIdle(KeyedObjectPool, Object, int, long)
      * @since Pool 1.3
      */
-    public static Map checkMinIdle(final KeyedObjectPool keyedPool, final Collection keys, final int minIdle, final long period) throws IllegalArgumentException {
+    public static <K, V> Map<K, TimerTask> checkMinIdle(final KeyedObjectPool<K, V> keyedPool, final Collection<? extends K> keys, final int minIdle, final long period) throws IllegalArgumentException {
         if (keys == null) {
             throw new IllegalArgumentException("keys must not be null.");
         }
-        final Map tasks = new HashMap(keys.size());
-        final Iterator iter = keys.iterator();
+        final Map<K, TimerTask> tasks = new HashMap<K, TimerTask>(keys.size());
+        final Iterator<? extends K> iter = keys.iterator();
         while (iter.hasNext()) {
-            final Object key = iter.next();
+            final K key = iter.next();
             final TimerTask task = checkMinIdle(keyedPool, key, minIdle, period);
             tasks.put(key, task);
         }
@@ -289,7 +289,7 @@ public final class PoolUtils {
      * @throws IllegalArgumentException when <code>pool</code> is <code>null</code>.
      * @since Pool 1.3
      */
-    public static void prefill(final ObjectPool pool, final int count) throws Exception, IllegalArgumentException {
+    public static <T> void prefill(final ObjectPool<T> pool, final int count) throws Exception, IllegalArgumentException {
         if (pool == null) {
             throw new IllegalArgumentException("pool must not be null.");
         }
@@ -309,7 +309,7 @@ public final class PoolUtils {
      * @throws IllegalArgumentException when <code>keyedPool</code> or <code>key</code> is <code>null</code>.
      * @since Pool 1.3
      */
-    public static void prefill(final KeyedObjectPool keyedPool, final Object key, final int count) throws Exception, IllegalArgumentException {
+    public static <K, V> void prefill(final KeyedObjectPool<K, V> keyedPool, final K key, final int count) throws Exception, IllegalArgumentException {
         if (keyedPool == null) {
             throw new IllegalArgumentException("keyedPool must not be null.");
         }
@@ -335,11 +335,11 @@ public final class PoolUtils {
      * @see #prefill(KeyedObjectPool, Object, int)
      * @since Pool 1.3
      */
-    public static void prefill(final KeyedObjectPool keyedPool, final Collection keys, final int count) throws Exception, IllegalArgumentException {
+    public static <K, V> void prefill(final KeyedObjectPool<K, V> keyedPool, final Collection<? extends K> keys, final int count) throws Exception, IllegalArgumentException {
         if (keys == null) {
             throw new IllegalArgumentException("keys must not be null.");
         }
-        final Iterator iter = keys.iterator();
+        final Iterator<? extends K> iter = keys.iterator();
         while (iter.hasNext()) {
             prefill(keyedPool, iter.next(), count);
         }
@@ -359,7 +359,7 @@ public final class PoolUtils {
      * @return a synchronized view of the specified ObjectPool.
      * @since Pool 1.3
      */
-    public static ObjectPool synchronizedPool(final ObjectPool pool) {
+    public static <T> ObjectPool<T> synchronizedPool(final ObjectPool<T> pool) {
         if (pool == null) {
             throw new IllegalArgumentException("pool must not be null.");
         }
@@ -373,7 +373,7 @@ public final class PoolUtils {
         assert !"org.apache.commons.pool.composite.CompositeObjectPool".equals(pool.getClass().getName())
                 : "CompositeObjectPools are already thread-safe";
         */
-        return new SynchronizedObjectPool(pool);
+        return new SynchronizedObjectPool<T>(pool);
     }
 
     /**
@@ -390,7 +390,7 @@ public final class PoolUtils {
      * @return a synchronized view of the specified KeyedObjectPool.
      * @since Pool 1.3
      */
-    public static KeyedObjectPool synchronizedPool(final KeyedObjectPool keyedPool) {
+    public static <K, V> KeyedObjectPool<K, V> synchronizedPool(final KeyedObjectPool<K, V> keyedPool) {
         if (keyedPool == null) {
             throw new IllegalArgumentException("keyedPool must not be null.");
         }
@@ -402,7 +402,7 @@ public final class PoolUtils {
         assert !"org.apache.commons.pool.composite.CompositeKeyedObjectPool".equals(keyedPool.getClass().getName())
                 : "CompositeKeyedObjectPools are already thread-safe";
         */
-        return new SynchronizedKeyedObjectPool(keyedPool);
+        return new SynchronizedKeyedObjectPool<K, V>(keyedPool);
     }
 
     /**
@@ -412,8 +412,8 @@ public final class PoolUtils {
      * @return a synchronized view of the specified PoolableObjectFactory.
      * @since Pool 1.3
      */
-    public static PoolableObjectFactory synchronizedPoolableFactory(final PoolableObjectFactory factory) {
-        return new SynchronizedPoolableObjectFactory(factory);
+    public static <T> PoolableObjectFactory<T> synchronizedPoolableFactory(final PoolableObjectFactory<T> factory) {
+        return new SynchronizedPoolableObjectFactory<T>(factory);
     }
 
     /**
@@ -423,8 +423,8 @@ public final class PoolUtils {
      * @return a synchronized view of the specified KeyedPoolableObjectFactory.
      * @since Pool 1.3
      */
-    public static KeyedPoolableObjectFactory synchronizedPoolableFactory(final KeyedPoolableObjectFactory keyedFactory) {
-        return new SynchronizedKeyedPoolableObjectFactory(keyedFactory);
+    public static <K, V> KeyedPoolableObjectFactory<K, V> synchronizedPoolableFactory(final KeyedPoolableObjectFactory<K, V> keyedFactory) {
+        return new SynchronizedKeyedPoolableObjectFactory<K, V>(keyedFactory);
     }
 
     /**
@@ -438,7 +438,7 @@ public final class PoolUtils {
      * @see #erodingPool(ObjectPool, float)
      * @since Pool 1.4
      */
-    public static ObjectPool erodingPool(final ObjectPool pool) {
+    public static <T> ObjectPool<T> erodingPool(final ObjectPool<T> pool) {
         return erodingPool(pool, 1f);
     }
 
@@ -462,14 +462,14 @@ public final class PoolUtils {
      * @see #erodingPool(ObjectPool)
      * @since Pool 1.4
      */
-    public static ObjectPool erodingPool(final ObjectPool pool, final float factor) {
+    public static <T> ObjectPool<T> erodingPool(final ObjectPool<T> pool, final float factor) {
         if (pool == null) {
             throw new IllegalArgumentException("pool must not be null.");
         }
         if (factor <= 0f) {
             throw new IllegalArgumentException("factor must be positive.");
         }
-        return new ErodingObjectPool(pool, factor);
+        return new ErodingObjectPool<T>(pool, factor);
     }
 
     /**
@@ -485,7 +485,7 @@ public final class PoolUtils {
      * @see #erodingPool(KeyedObjectPool, float, boolean)
      * @since Pool 1.4
      */
-    public static KeyedObjectPool erodingPool(final KeyedObjectPool keyedPool) {
+    public static <K, V> KeyedObjectPool<K, V> erodingPool(final KeyedObjectPool<K, V> keyedPool) {
         return erodingPool(keyedPool, 1f);
     }
 
@@ -510,7 +510,7 @@ public final class PoolUtils {
      * @see #erodingPool(KeyedObjectPool, float, boolean)
      * @since Pool 1.4
      */
-    public static KeyedObjectPool erodingPool(final KeyedObjectPool keyedPool, final float factor) {
+    public static <K, V> KeyedObjectPool<K, V> erodingPool(final KeyedObjectPool<K, V> keyedPool, final float factor) {
         return erodingPool(keyedPool, factor, false);
     }
 
@@ -543,7 +543,7 @@ public final class PoolUtils {
      * @see #erodingPool(KeyedObjectPool, float)
      * @since Pool 1.4
      */
-    public static KeyedObjectPool erodingPool(final KeyedObjectPool keyedPool, final float factor, final boolean perKey) {
+    public static <K, V> KeyedObjectPool<K, V> erodingPool(final KeyedObjectPool<K, V> keyedPool, final float factor, final boolean perKey) {
         if (keyedPool == null) {
             throw new IllegalArgumentException("keyedPool must not be null.");
         }
@@ -551,9 +551,9 @@ public final class PoolUtils {
             throw new IllegalArgumentException("factor must be positive.");
         }
         if (perKey) {
-            return new ErodingPerKeyKeyedObjectPool(keyedPool, factor);
+            return new ErodingPerKeyKeyedObjectPool<K, V>(keyedPool, factor);
         } else {
-            return new ErodingKeyedObjectPool(keyedPool, factor);
+            return new ErodingKeyedObjectPool<K, V>(keyedPool, factor);
         }
     }
 
@@ -574,12 +574,12 @@ public final class PoolUtils {
      * Adaptor class that wraps and converts a KeyedPoolableObjectFactory with a fixed
      * key to a PoolableObjectFactory.
      */
-    private static class PoolableObjectFactoryAdaptor implements PoolableObjectFactory {
+    private static class PoolableObjectFactoryAdaptor<K, V> implements PoolableObjectFactory<V> {
         /** Fixed key */
-        private final Object key;
+        private final K key;
         
         /** Wrapped factory */
-        private final KeyedPoolableObjectFactory keyedFactory;
+        private final KeyedPoolableObjectFactory<K, V> keyedFactory;
 
         /**
          * Create a PoolableObjectFactoryAdaptor wrapping the provided KeyedPoolableObjectFactory with the 
@@ -589,7 +589,7 @@ public final class PoolUtils {
          * @param key fixed key
          * @throws IllegalArgumentException if either of the parameters is null
          */
-        PoolableObjectFactoryAdaptor(final KeyedPoolableObjectFactory keyedFactory, final Object key)
+        PoolableObjectFactoryAdaptor(final KeyedPoolableObjectFactory<K, V> keyedFactory, final K key)
         throws IllegalArgumentException {
             if (keyedFactory == null) {
                 throw new IllegalArgumentException("keyedFactory must not be null.");
@@ -606,7 +606,7 @@ public final class PoolUtils {
          * 
          * @return new object instance
          */
-        public Object makeObject() throws Exception {
+        public V makeObject() throws Exception {
             return keyedFactory.makeObject(key);
         }
 
@@ -615,7 +615,7 @@ public final class PoolUtils {
          * 
          * @param obj object to destroy
          */
-        public void destroyObject(final Object obj) throws Exception {
+        public void destroyObject(final V obj) throws Exception {
             keyedFactory.destroyObject(key, obj);
         }
 
@@ -625,7 +625,7 @@ public final class PoolUtils {
          * @param obj object to validate
          * @return true if validation is successful
          */
-        public boolean validateObject(final Object obj) {
+        public boolean validateObject(final V obj) {
             return keyedFactory.validateObject(key, obj);
         }
 
@@ -634,7 +634,7 @@ public final class PoolUtils {
          * 
          * @param obj object to activate
          */
-        public void activateObject(final Object obj) throws Exception {
+        public void activateObject(final V obj) throws Exception {
             keyedFactory.activateObject(key, obj);
         }
 
@@ -643,7 +643,7 @@ public final class PoolUtils {
          * 
          * @param obj object to passivate
          */
-        public void passivateObject(final Object obj) throws Exception {
+        public void passivateObject(final V obj) throws Exception {
             keyedFactory.passivateObject(key, obj);
         }
 
@@ -664,10 +664,10 @@ public final class PoolUtils {
      * Adaptor class that turns a PoolableObjectFactory into a KeyedPoolableObjectFactory by
      * ignoring keys.
      */
-    private static class KeyedPoolableObjectFactoryAdaptor implements KeyedPoolableObjectFactory {
+    private static class KeyedPoolableObjectFactoryAdaptor<K, V> implements KeyedPoolableObjectFactory<K, V> {
         
         /** Underlying PoolableObjectFactory */
-        private final PoolableObjectFactory factory;
+        private final PoolableObjectFactory<V> factory;
 
         /**
          * Create a new KeyedPoolableObjectFactoryAdaptor using the given PoolableObjectFactory to
@@ -676,7 +676,7 @@ public final class PoolUtils {
          * @param factory wrapped PoolableObjectFactory 
          * @throws IllegalArgumentException if the factory is null
          */
-        KeyedPoolableObjectFactoryAdaptor(final PoolableObjectFactory factory) throws IllegalArgumentException {
+        KeyedPoolableObjectFactoryAdaptor(final PoolableObjectFactory<V> factory) throws IllegalArgumentException {
             if (factory == null) {
                 throw new IllegalArgumentException("factory must not be null.");
             }
@@ -689,7 +689,7 @@ public final class PoolUtils {
          * @param key ignored
          * @return newly created object instance
          */
-        public Object makeObject(final Object key) throws Exception {
+        public V makeObject(final K key) throws Exception {
             return factory.makeObject();
         }
 
@@ -699,7 +699,7 @@ public final class PoolUtils {
          * @param key ignored
          * @param obj instance to destroy
          */
-        public void destroyObject(final Object key, final Object obj) throws Exception {
+        public void destroyObject(final K key, final V obj) throws Exception {
             factory.destroyObject(obj);
         }
 
@@ -710,7 +710,7 @@ public final class PoolUtils {
          * @param obj object to validate
          * @return true if validation is successful
          */
-        public boolean validateObject(final Object key, final Object obj) {
+        public boolean validateObject(final K key, final V obj) {
             return factory.validateObject(obj);
         }
 
@@ -720,7 +720,7 @@ public final class PoolUtils {
          * @param key ignored
          * @param obj object to be activated
          */
-        public void activateObject(final Object key, final Object obj) throws Exception {
+        public void activateObject(final K key, final V obj) throws Exception {
             factory.activateObject(obj);
         }
 
@@ -730,7 +730,7 @@ public final class PoolUtils {
          * @param key ignored
          * @param obj object to passivate
          */
-        public void passivateObject(final Object key, final Object obj) throws Exception {
+        public void passivateObject(final K key, final V obj) throws Exception {
             factory.passivateObject(obj);
         }
 
@@ -750,13 +750,13 @@ public final class PoolUtils {
      * Adapts a KeyedObjectPool to make it an ObjectPool by fixing restricting to
      * a fixed key.
      */
-    private static class ObjectPoolAdaptor implements ObjectPool {
+    private static class ObjectPoolAdaptor<V> implements ObjectPool<V> {
         
         /** Fixed key */
         private final Object key;
         
         /** Underlying KeyedObjectPool */
-        private final KeyedObjectPool keyedPool;
+        private final KeyedObjectPool<Object, V> keyedPool;
 
         /**
          * Create a new ObjectPoolAdaptor using the provided KeyedObjectPool and fixed key.
@@ -765,7 +765,7 @@ public final class PoolUtils {
          * @param key fixed key
          * @throws IllegalArgumentException if either of the parameters is null
          */
-        ObjectPoolAdaptor(final KeyedObjectPool keyedPool, final Object key) throws IllegalArgumentException {
+        ObjectPoolAdaptor(final KeyedObjectPool<Object, V> keyedPool, final Object key) throws IllegalArgumentException {
             if (keyedPool == null) {
                 throw new IllegalArgumentException("keyedPool must not be null.");
             }
@@ -779,14 +779,14 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public Object borrowObject() throws Exception, NoSuchElementException, IllegalStateException {
+        public V borrowObject() throws Exception, NoSuchElementException, IllegalStateException {
             return keyedPool.borrowObject(key);
         }
 
         /**
          * {@inheritDoc}
          */
-        public void returnObject(final Object obj) {
+        public void returnObject(final V obj) {
             try {
                 keyedPool.returnObject(key, obj);
             } catch (Exception e) {
@@ -797,7 +797,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void invalidateObject(final Object obj) {
+        public void invalidateObject(final V obj) {
             try {
                 keyedPool.invalidateObject(key, obj);
             } catch (Exception e) {
@@ -850,7 +850,7 @@ public final class PoolUtils {
          * @param factory new PoolableObjectFactory 
          * @deprecated to be removed in version 2.0
          */
-        public void setFactory(final PoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException {
+        public void setFactory(final PoolableObjectFactory<V> factory) throws IllegalStateException, UnsupportedOperationException {
             keyedPool.setFactory(adapt(factory));
         }
 
@@ -870,10 +870,10 @@ public final class PoolUtils {
     /**
      * Adapts an ObjectPool to implement KeyedObjectPool by ignoring key arguments.
      */
-    private static class KeyedObjectPoolAdaptor implements KeyedObjectPool {
+    private static class KeyedObjectPoolAdaptor<K, V> implements KeyedObjectPool<K, V> {
        
         /** Underlying pool */
-        private final ObjectPool pool;
+        private final ObjectPool<V> pool;
 
         /**
          * Create a new KeyedObjectPoolAdaptor wrapping the given ObjectPool
@@ -881,7 +881,7 @@ public final class PoolUtils {
          * @param pool underlying object pool
          * @throws IllegalArgumentException if pool is null
          */
-        KeyedObjectPoolAdaptor(final ObjectPool pool) throws IllegalArgumentException {
+        KeyedObjectPoolAdaptor(final ObjectPool<V> pool) throws IllegalArgumentException {
             if (pool == null) {
                 throw new IllegalArgumentException("pool must not be null.");
             }
@@ -894,7 +894,7 @@ public final class PoolUtils {
          * @param key ignored
          * @return newly created object instance
          */
-        public Object borrowObject(final Object key) throws Exception, NoSuchElementException, IllegalStateException {
+        public V borrowObject(final K key) throws Exception, NoSuchElementException, IllegalStateException {
             return pool.borrowObject();
         }
 
@@ -904,7 +904,7 @@ public final class PoolUtils {
          * @param key ignored
          * @param obj object to return
          */
-        public void returnObject(final Object key, final Object obj) {
+        public void returnObject(final K key, final V obj) {
             try {
                 pool.returnObject(obj);
             } catch (Exception e) {
@@ -918,7 +918,7 @@ public final class PoolUtils {
          * @param obj object to invalidate
          * @param key ignored
          */
-        public void invalidateObject(final Object key, final Object obj) {
+        public void invalidateObject(final K key, final V obj) {
             try {
                 pool.invalidateObject(obj);
             } catch (Exception e) {
@@ -931,7 +931,7 @@ public final class PoolUtils {
          * 
          * @param key ignored
          */
-        public void addObject(final Object key) throws Exception, IllegalStateException {
+        public void addObject(final K key) throws Exception, IllegalStateException {
             pool.addObject();
         }
 
@@ -941,7 +941,7 @@ public final class PoolUtils {
          * @param key ignored
          * @return idle instance count
          */
-        public int getNumIdle(final Object key) throws UnsupportedOperationException {
+        public int getNumIdle(final K key) throws UnsupportedOperationException {
             return pool.getNumIdle();
         }
 
@@ -951,7 +951,7 @@ public final class PoolUtils {
          * @param key ignored
          * @return active instance count
          */
-        public int getNumActive(final Object key) throws UnsupportedOperationException {
+        public int getNumActive(final K key) throws UnsupportedOperationException {
             return pool.getNumActive();
         }
 
@@ -981,7 +981,7 @@ public final class PoolUtils {
          * 
          * @param key ignored.
          */
-        public void clear(final Object key) throws Exception, UnsupportedOperationException {
+        public void clear(final K key) throws Exception, UnsupportedOperationException {
             pool.clear();
         }
 
@@ -1002,8 +1002,9 @@ public final class PoolUtils {
          * @param factory new factory to use managing object instances
          * @deprecated to be removed in version 2.0
          */
-        public void setFactory(final KeyedPoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException {
-            pool.setFactory(adapt(factory));
+        @SuppressWarnings("unchecked")
+        public void setFactory(final KeyedPoolableObjectFactory<K, V> factory) throws IllegalStateException, UnsupportedOperationException {
+            pool.setFactory(adapt((KeyedPoolableObjectFactory<Object, V>)factory));
         }
 
         /**
@@ -1023,15 +1024,15 @@ public final class PoolUtils {
      * to pool methods.
      *
      */
-    private static class CheckedObjectPool implements ObjectPool {
+    private static class CheckedObjectPool<T> implements ObjectPool<T> {
         /** 
          * Type of objects allowed in the pool. This should be a subtype of the return type of
          * the underlying pool's associated object factory.
          */
-        private final Class type;
+        private final Class<T> type;
        
         /** Underlying object pool */
-        private final ObjectPool pool;
+        private final ObjectPool<T> pool;
 
         /**
          * Create a CheckedObjectPool accepting objects of the given type using
@@ -1041,7 +1042,7 @@ public final class PoolUtils {
          * @param type expected pooled object type
          * @throws IllegalArgumentException if either parameter is null
          */
-        CheckedObjectPool(final ObjectPool pool, final Class type) {
+        CheckedObjectPool(final ObjectPool<T> pool, final Class<T> type) {
             if (pool == null) {
                 throw new IllegalArgumentException("pool must not be null.");
             }
@@ -1058,8 +1059,8 @@ public final class PoolUtils {
          * @return a type-checked object from the pool
          * @throws ClassCastException if the object returned by the pool is not of the expected type
          */
-        public Object borrowObject() throws Exception, NoSuchElementException, IllegalStateException {
-            final Object obj = pool.borrowObject();
+        public T borrowObject() throws Exception, NoSuchElementException, IllegalStateException {
+            final T obj = pool.borrowObject();
             if (type.isInstance(obj)) {
                 return obj;
             } else {
@@ -1073,7 +1074,7 @@ public final class PoolUtils {
          * @param obj object to return
          * @throws ClassCastException if obj is not of the expected type
          */
-        public void returnObject(final Object obj) {
+        public void returnObject(final T obj) {
             if (type.isInstance(obj)) {
                 try {
                     pool.returnObject(obj);
@@ -1091,7 +1092,7 @@ public final class PoolUtils {
          * @param obj object to invalidate
          * @throws ClassCastException if obj is not of the expected type
          */
-        public void invalidateObject(final Object obj) {
+        public void invalidateObject(final T obj) {
             if (type.isInstance(obj)) {
                 try {
                     pool.invalidateObject(obj);
@@ -1148,7 +1149,7 @@ public final class PoolUtils {
          * @param factory object factory
          * @deprecated to be removed in version 2.0
          */
-        public void setFactory(final PoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException {
+        public void setFactory(final PoolableObjectFactory<T> factory) throws IllegalStateException, UnsupportedOperationException {
             pool.setFactory(factory);
         }
 
@@ -1170,15 +1171,15 @@ public final class PoolUtils {
      * to pool methods.
      *
      */
-    private static class CheckedKeyedObjectPool implements KeyedObjectPool {
+    private static class CheckedKeyedObjectPool<K, V> implements KeyedObjectPool<K, V> {
         /** 
          * Expected type of objects managed by the pool.  This should be
          * a subtype of the return type of the object factory used by the pool.
          */
-        private final Class type;
+        private final Class<V> type;
         
         /** Underlying pool */
-        private final KeyedObjectPool keyedPool;
+        private final KeyedObjectPool<K, V> keyedPool;
 
         /**
          * Create a new CheckedKeyedObjectPool from the given pool with given expected object type.
@@ -1187,7 +1188,7 @@ public final class PoolUtils {
          * @param type expected object type
          * @throws IllegalArgumentException if either parameter is null
          */
-        CheckedKeyedObjectPool(final KeyedObjectPool keyedPool, final Class type) {
+        CheckedKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool, final Class<V> type) {
             if (keyedPool == null) {
                 throw new IllegalArgumentException("keyedPool must not be null.");
             }
@@ -1205,8 +1206,8 @@ public final class PoolUtils {
          * @return type-checked object from the pool under the given key
          * @throws ClassCastException if the object returned by the pool is not of the expected type
          */
-        public Object borrowObject(final Object key) throws Exception, NoSuchElementException, IllegalStateException {
-            Object obj = keyedPool.borrowObject(key);
+        public V borrowObject(final K key) throws Exception, NoSuchElementException, IllegalStateException {
+            V obj = keyedPool.borrowObject(key);
             if (type.isInstance(obj)) {
                 return obj;
             } else {
@@ -1221,7 +1222,7 @@ public final class PoolUtils {
          * @param obj the object to return (type-checked)
          * @throws ClassCastException if obj is not of the expected type
          */
-        public void returnObject(final Object key, final Object obj) {
+        public void returnObject(final K key, final V obj) {
             if (type.isInstance(obj)) {
                 try {
                     keyedPool.returnObject(key, obj);
@@ -1240,7 +1241,7 @@ public final class PoolUtils {
          * @param obj the object to return (type-checked)
          * @throws ClassCastException if obj is not of the expected type
          */
-        public void invalidateObject(final Object key, final Object obj) {
+        public void invalidateObject(final K key, final V obj) {
             if (type.isInstance(obj)) {
                 try {
                     keyedPool.invalidateObject(key, obj);
@@ -1255,21 +1256,21 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void addObject(final Object key) throws Exception, IllegalStateException, UnsupportedOperationException {
+        public void addObject(final K key) throws Exception, IllegalStateException, UnsupportedOperationException {
             keyedPool.addObject(key);
         }
         
         /**
          * {@inheritDoc}
          */
-        public int getNumIdle(final Object key) throws UnsupportedOperationException {
+        public int getNumIdle(final K key) throws UnsupportedOperationException {
             return keyedPool.getNumIdle(key);
         }
 
         /**
          * {@inheritDoc}
          */
-        public int getNumActive(final Object key) throws UnsupportedOperationException {
+        public int getNumActive(final K key) throws UnsupportedOperationException {
             return keyedPool.getNumActive(key);
         }
 
@@ -1297,7 +1298,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void clear(final Object key) throws Exception, UnsupportedOperationException {
+        public void clear(final K key) throws Exception, UnsupportedOperationException {
             keyedPool.clear(key);
         }
 
@@ -1318,7 +1319,7 @@ public final class PoolUtils {
          * @param factory object factory
          * @deprecated to be removed in version 2.0
          */
-        public void setFactory(final KeyedPoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException {
+        public void setFactory(final KeyedPoolableObjectFactory<K, V> factory) throws IllegalStateException, UnsupportedOperationException {
             keyedPool.setFactory(factory);
         }
 
@@ -1341,13 +1342,13 @@ public final class PoolUtils {
      * same as the pool's minIdle setting.
      * 
      */
-    private static class ObjectPoolMinIdleTimerTask extends TimerTask {
+    private static class ObjectPoolMinIdleTimerTask<T> extends TimerTask {
         
         /** Minimum number of idle instances.  Not the same as pool.getMinIdle(). */
         private final int minIdle;
         
         /** Object pool */
-        private final ObjectPool pool;
+        private final ObjectPool<T> pool;
 
         /**
          * Create a new ObjectPoolMinIdleTimerTask for the given pool with the given minIdle setting.
@@ -1356,7 +1357,7 @@ public final class PoolUtils {
          * @param minIdle number of idle instances to maintain
          * @throws IllegalArgumentException if the pool is null
          */
-        ObjectPoolMinIdleTimerTask(final ObjectPool pool, final int minIdle) throws IllegalArgumentException {
+        ObjectPoolMinIdleTimerTask(final ObjectPool<T> pool, final int minIdle) throws IllegalArgumentException {
             if (pool == null) {
                 throw new IllegalArgumentException("pool must not be null.");
             }
@@ -1405,15 +1406,15 @@ public final class PoolUtils {
      * same as the pool's minIdle setting.
      * 
      */
-    private static class KeyedObjectPoolMinIdleTimerTask extends TimerTask {
+    private static class KeyedObjectPoolMinIdleTimerTask<K, V> extends TimerTask {
         /** Minimum number of idle instances.  Not the same as pool.getMinIdle(). */
         private final int minIdle;
         
         /** Key to ensure minIdle for */
-        private final Object key;
+        private final K key;
         
         /** Keyed object pool */
-        private final KeyedObjectPool keyedPool;
+        private final KeyedObjectPool<K, V> keyedPool;
 
         /**
          * Create a new KeyedObjecPoolMinIdleTimerTask.
@@ -1423,7 +1424,7 @@ public final class PoolUtils {
          * @param minIdle minimum number of idle instances 
          * @throws IllegalArgumentException if the key is null
          */
-        KeyedObjectPoolMinIdleTimerTask(final KeyedObjectPool keyedPool, final Object key, final int minIdle) throws IllegalArgumentException {
+        KeyedObjectPoolMinIdleTimerTask(final KeyedObjectPool<K, V> keyedPool, final K key, final int minIdle) throws IllegalArgumentException {
             if (keyedPool == null) {
                 throw new IllegalArgumentException("keyedPool must not be null.");
             }
@@ -1478,13 +1479,13 @@ public final class PoolUtils {
      * borrowed with another layer of synchronization will cause liveliness issues or a deadlock.
      * </p>
      */
-    private static class SynchronizedObjectPool implements ObjectPool {
+    private static class SynchronizedObjectPool<T> implements ObjectPool<T> {
         
         /** Object whose monitor is used to synchronize methods on the wrapped pool. */
         private final Object lock;
         
         /** the underlying object pool */
-        private final ObjectPool pool;
+        private final ObjectPool<T> pool;
 
         /**
          * Create a new SynchronizedObjectPool wrapping the given pool.
@@ -1492,7 +1493,7 @@ public final class PoolUtils {
          * @param pool the ObjectPool to be "wrapped" in a synchronized ObjectPool.
          * @throws IllegalArgumentException if the pool is null
          */
-        SynchronizedObjectPool(final ObjectPool pool) throws IllegalArgumentException {
+        SynchronizedObjectPool(final ObjectPool<T> pool) throws IllegalArgumentException {
             if (pool == null) {
                 throw new IllegalArgumentException("pool must not be null.");
             }
@@ -1503,7 +1504,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public Object borrowObject() throws Exception, NoSuchElementException, IllegalStateException {
+        public T borrowObject() throws Exception, NoSuchElementException, IllegalStateException {
             synchronized (lock) {
                 return pool.borrowObject();
             }
@@ -1512,7 +1513,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void returnObject(final Object obj) {
+        public void returnObject(final T obj) {
             synchronized (lock) {
                 try {
                     pool.returnObject(obj);
@@ -1525,7 +1526,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void invalidateObject(final Object obj) {
+        public void invalidateObject(final T obj) {
             synchronized (lock) {
                 try {
                     pool.invalidateObject(obj);
@@ -1590,7 +1591,7 @@ public final class PoolUtils {
          * @param factory new PoolableObjectFactory
          * @deprecated to be removed in pool 2.0
          */
-        public void setFactory(final PoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException {
+        public void setFactory(final PoolableObjectFactory<T> factory) throws IllegalStateException, UnsupportedOperationException {
             synchronized (lock) {
                 pool.setFactory(factory);
             }
@@ -1618,13 +1619,13 @@ public final class PoolUtils {
      * borrowed with another layer of synchronization will cause liveliness issues or a deadlock.
      * </p>
      */
-    private static class SynchronizedKeyedObjectPool implements KeyedObjectPool {
+    private static class SynchronizedKeyedObjectPool<K, V> implements KeyedObjectPool<K, V> {
         
         /** Object whose monitor is used to synchronize methods on the wrapped pool. */
         private final Object lock;
         
         /** Underlying object pool */
-        private final KeyedObjectPool keyedPool;
+        private final KeyedObjectPool<K, V> keyedPool;
 
         /**
          * Create a new SynchronizedKeyedObjectPool wrapping the given pool
@@ -1632,7 +1633,7 @@ public final class PoolUtils {
          * @param keyedPool KeyedObjectPool to wrap
          * @throws IllegalArgumentException if keyedPool is null
          */
-        SynchronizedKeyedObjectPool(final KeyedObjectPool keyedPool) throws IllegalArgumentException {
+        SynchronizedKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool) throws IllegalArgumentException {
             if (keyedPool == null) {
                 throw new IllegalArgumentException("keyedPool must not be null.");
             }
@@ -1643,7 +1644,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public Object borrowObject(final Object key) throws Exception, NoSuchElementException, IllegalStateException {
+        public V borrowObject(final K key) throws Exception, NoSuchElementException, IllegalStateException {
             synchronized (lock) {
                 return keyedPool.borrowObject(key);
             }
@@ -1652,7 +1653,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void returnObject(final Object key, final Object obj) {
+        public void returnObject(final K key, final V obj) {
             synchronized (lock) {
                 try {
                     keyedPool.returnObject(key, obj);
@@ -1665,7 +1666,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void invalidateObject(final Object key, final Object obj) {
+        public void invalidateObject(final K key, final V obj) {
             synchronized (lock) {
                 try {
                     keyedPool.invalidateObject(key, obj);
@@ -1678,7 +1679,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void addObject(final Object key) throws Exception, IllegalStateException, UnsupportedOperationException {
+        public void addObject(final K key) throws Exception, IllegalStateException, UnsupportedOperationException {
             synchronized (lock) {
                 keyedPool.addObject(key);
             }
@@ -1687,7 +1688,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public int getNumIdle(final Object key) throws UnsupportedOperationException {
+        public int getNumIdle(final K key) throws UnsupportedOperationException {
             synchronized (lock) {
                 return keyedPool.getNumIdle(key);
             }
@@ -1696,7 +1697,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public int getNumActive(final Object key) throws UnsupportedOperationException {
+        public int getNumActive(final K key) throws UnsupportedOperationException {
             synchronized (lock) {
                 return keyedPool.getNumActive(key);
             }
@@ -1732,7 +1733,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void clear(final Object key) throws Exception, UnsupportedOperationException {
+        public void clear(final K key) throws Exception, UnsupportedOperationException {
             synchronized (lock) {
                 keyedPool.clear(key);
             }
@@ -1757,7 +1758,7 @@ public final class PoolUtils {
          * @param factory KeyedPoolableObjectFactory used by the pool
          * @deprecated to be removed in pool 2.0
          */
-        public void setFactory(final KeyedPoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException {
+        public void setFactory(final KeyedPoolableObjectFactory<K, V> factory) throws IllegalStateException, UnsupportedOperationException {
             synchronized (lock) {
                 keyedPool.setFactory(factory);
             }
@@ -1783,12 +1784,12 @@ public final class PoolUtils {
      * This should not be used on pool implementations that already provide proper synchronization
      * such as the pools provided in the Commons Pool library. </p>
      */
-    private static class SynchronizedPoolableObjectFactory implements PoolableObjectFactory {
+    private static class SynchronizedPoolableObjectFactory<T> implements PoolableObjectFactory<T> {
         /** Synchronization lock */
         private final Object lock;
         
         /** Wrapped factory */
-        private final PoolableObjectFactory factory;
+        private final PoolableObjectFactory<T> factory;
 
         /** 
          * Create a SynchronizedPoolableObjectFactory wrapping the given factory.
@@ -1796,7 +1797,7 @@ public final class PoolUtils {
          * @param factory underlying factory to wrap
          * @throws IllegalArgumentException if the factory is null
          */
-        SynchronizedPoolableObjectFactory(final PoolableObjectFactory factory) throws IllegalArgumentException {
+        SynchronizedPoolableObjectFactory(final PoolableObjectFactory<T> factory) throws IllegalArgumentException {
             if (factory == null) {
                 throw new IllegalArgumentException("factory must not be null.");
             }
@@ -1807,7 +1808,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public Object makeObject() throws Exception {
+        public T makeObject() throws Exception {
             synchronized (lock) {
                 return factory.makeObject();
             }
@@ -1816,7 +1817,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void destroyObject(final Object obj) throws Exception {
+        public void destroyObject(final T obj) throws Exception {
             synchronized (lock) {
                 factory.destroyObject(obj);
             }
@@ -1825,7 +1826,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public boolean validateObject(final Object obj) {
+        public boolean validateObject(final T obj) {
             synchronized (lock) {
                 return factory.validateObject(obj);
             }
@@ -1834,7 +1835,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void activateObject(final Object obj) throws Exception {
+        public void activateObject(final T obj) throws Exception {
             synchronized (lock) {
                 factory.activateObject(obj);
             }
@@ -1843,7 +1844,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void passivateObject(final Object obj) throws Exception {
+        public void passivateObject(final T obj) throws Exception {
             synchronized (lock) {
                 factory.passivateObject(obj);
             }
@@ -1869,12 +1870,12 @@ public final class PoolUtils {
      * This should not be used on pool implementations that already provide proper synchronization
      * such as the pools provided in the Commons Pool library. </p>
      */
-    private static class SynchronizedKeyedPoolableObjectFactory implements KeyedPoolableObjectFactory {
+    private static class SynchronizedKeyedPoolableObjectFactory<K, V> implements KeyedPoolableObjectFactory<K, V> {
         /** Synchronization lock */
         private final Object lock;
         
         /** Wrapped factory */
-        private final KeyedPoolableObjectFactory keyedFactory;
+        private final KeyedPoolableObjectFactory<K, V> keyedFactory;
 
         /** 
          * Create a SynchronizedKeyedPoolableObjectFactory wrapping the given factory.
@@ -1882,7 +1883,7 @@ public final class PoolUtils {
          * @param keyedFactory underlying factory to wrap
          * @throws IllegalArgumentException if the factory is null
          */
-        SynchronizedKeyedPoolableObjectFactory(final KeyedPoolableObjectFactory keyedFactory) throws IllegalArgumentException {
+        SynchronizedKeyedPoolableObjectFactory(final KeyedPoolableObjectFactory<K, V> keyedFactory) throws IllegalArgumentException {
             if (keyedFactory == null) {
                 throw new IllegalArgumentException("keyedFactory must not be null.");
             }
@@ -1893,7 +1894,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public Object makeObject(final Object key) throws Exception {
+        public V makeObject(final K key) throws Exception {
             synchronized (lock) {
                 return keyedFactory.makeObject(key);
             }
@@ -1902,7 +1903,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void destroyObject(final Object key, final Object obj) throws Exception {
+        public void destroyObject(final K key, final V obj) throws Exception {
             synchronized (lock) {
                 keyedFactory.destroyObject(key, obj);
             }
@@ -1911,7 +1912,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public boolean validateObject(final Object key, final Object obj) {
+        public boolean validateObject(final K key, final V obj) {
             synchronized (lock) {
                 return keyedFactory.validateObject(key, obj);
             }
@@ -1920,7 +1921,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void activateObject(final Object key, final Object obj) throws Exception {
+        public void activateObject(final K key, final V obj) throws Exception {
             synchronized (lock) {
                 keyedFactory.activateObject(key, obj);
             }
@@ -1929,7 +1930,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void passivateObject(final Object key, final Object obj) throws Exception {
+        public void passivateObject(final K key, final V obj) throws Exception {
             synchronized (lock) {
                 keyedFactory.passivateObject(key, obj);
             }
@@ -2026,9 +2027,9 @@ public final class PoolUtils {
      * may be invalidated instead of being added to idle capacity.
      *
      */
-    private static class ErodingObjectPool implements ObjectPool {
+    private static class ErodingObjectPool<T> implements ObjectPool<T> {
         /** Underlying object pool */
-        private final ObjectPool pool;
+        private final ObjectPool<T> pool;
         
         /** Erosion factor */
         private final ErodingFactor factor;
@@ -2040,7 +2041,7 @@ public final class PoolUtils {
          * @param factor erosion factor - determines the frequency of erosion events
          * @see #factor
          */
-        public ErodingObjectPool(final ObjectPool pool, final float factor) {
+        public ErodingObjectPool(final ObjectPool<T> pool, final float factor) {
             this.pool = pool;
             this.factor = new ErodingFactor(factor);
         }
@@ -2048,7 +2049,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public Object borrowObject() throws Exception, NoSuchElementException, IllegalStateException {
+        public T borrowObject() throws Exception, NoSuchElementException, IllegalStateException {
             return pool.borrowObject();
         }
 
@@ -2061,7 +2062,7 @@ public final class PoolUtils {
          * @param obj object to return or invalidate
          * @see #factor
          */
-        public void returnObject(final Object obj) {
+        public void returnObject(final T obj) {
             boolean discard = false;
             final long now = System.currentTimeMillis();
             synchronized (pool) {
@@ -2088,7 +2089,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void invalidateObject(final Object obj) {
+        public void invalidateObject(final T obj) {
             try {
                 pool.invalidateObject(obj);
             } catch (Exception e) {
@@ -2139,7 +2140,7 @@ public final class PoolUtils {
          * {@inheritDoc}
          * @deprecated to be removed in pool 2.0
          */
-        public void setFactory(final PoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException {
+        public void setFactory(final PoolableObjectFactory<T> factory) throws IllegalStateException, UnsupportedOperationException {
             pool.setFactory(factory);
         }
 
@@ -2160,9 +2161,9 @@ public final class PoolUtils {
      * may be invalidated instead of being added to idle capacity.
      *
      */
-    private static class ErodingKeyedObjectPool implements KeyedObjectPool {
+    private static class ErodingKeyedObjectPool<K, V> implements KeyedObjectPool<K, V> {
         /** Underlying pool */
-        private final KeyedObjectPool keyedPool;
+        private final KeyedObjectPool<K, V> keyedPool;
         
         /** Erosion factor */
         private final ErodingFactor erodingFactor;
@@ -2174,7 +2175,7 @@ public final class PoolUtils {
          * @param factor erosion factor - determines the frequency of erosion events
          * @see #erodingFactor
          */
-        public ErodingKeyedObjectPool(final KeyedObjectPool keyedPool, final float factor) {
+        public ErodingKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool, final float factor) {
             this(keyedPool, new ErodingFactor(factor));
         }
 
@@ -2185,7 +2186,7 @@ public final class PoolUtils {
          * @param erodingFactor erosion factor - determines the frequency of erosion events
          * @see #factor
          */
-        protected ErodingKeyedObjectPool(final KeyedObjectPool keyedPool, final ErodingFactor erodingFactor) {
+        protected ErodingKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool, final ErodingFactor erodingFactor) {
             if (keyedPool == null) {
                 throw new IllegalArgumentException("keyedPool must not be null.");
             }
@@ -2196,7 +2197,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public Object borrowObject(final Object key) throws Exception, NoSuchElementException, IllegalStateException {
+        public V borrowObject(final K key) throws Exception, NoSuchElementException, IllegalStateException {
             return keyedPool.borrowObject(key);
         }
 
@@ -2210,7 +2211,7 @@ public final class PoolUtils {
          * @param key key
          * @see #erodingFactor
          */
-        public void returnObject(final Object key, final Object obj) throws Exception {
+        public void returnObject(final K key, final V obj) throws Exception {
             boolean discard = false;
             final long now = System.currentTimeMillis();
             final ErodingFactor factor = getErodingFactor(key);
@@ -2235,7 +2236,7 @@ public final class PoolUtils {
             }
         }
 
-        protected int numIdle(final Object key) {
+        protected int numIdle(final K key) {
             return getKeyedPool().getNumIdle();
         }
 
@@ -2244,14 +2245,14 @@ public final class PoolUtils {
          * @param key key
          * @return eroding factor for the given keyed pool
          */
-        protected ErodingFactor getErodingFactor(final Object key) {
+        protected ErodingFactor getErodingFactor(final K key) {
             return erodingFactor;
         }
 
         /**
          * {@inheritDoc}
          */
-        public void invalidateObject(final Object key, final Object obj) {
+        public void invalidateObject(final K key, final V obj) {
             try {
                 keyedPool.invalidateObject(key, obj);
             } catch (Exception e) {
@@ -2262,7 +2263,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void addObject(final Object key) throws Exception, IllegalStateException, UnsupportedOperationException {
+        public void addObject(final K key) throws Exception, IllegalStateException, UnsupportedOperationException {
             keyedPool.addObject(key);
         }
 
@@ -2276,7 +2277,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public int getNumIdle(final Object key) throws UnsupportedOperationException {
+        public int getNumIdle(final K key) throws UnsupportedOperationException {
             return keyedPool.getNumIdle(key);
         }
 
@@ -2290,7 +2291,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public int getNumActive(final Object key) throws UnsupportedOperationException {
+        public int getNumActive(final K key) throws UnsupportedOperationException {
             return keyedPool.getNumActive(key);
         }
 
@@ -2304,7 +2305,7 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        public void clear(final Object key) throws Exception, UnsupportedOperationException {
+        public void clear(final K key) throws Exception, UnsupportedOperationException {
             keyedPool.clear(key);
         }
 
@@ -2323,7 +2324,7 @@ public final class PoolUtils {
          * {@inheritDoc}
          * @deprecated to be removed in pool 2.0
          */
-        public void setFactory(final KeyedPoolableObjectFactory factory) throws IllegalStateException, UnsupportedOperationException {
+        public void setFactory(final KeyedPoolableObjectFactory<K, V> factory) throws IllegalStateException, UnsupportedOperationException {
             keyedPool.setFactory(factory);
         }
 
@@ -2332,7 +2333,7 @@ public final class PoolUtils {
          * 
          * @return the keyed pool that this ErodingKeyedObjectPool wraps
          */
-        protected KeyedObjectPool getKeyedPool() {
+        protected KeyedObjectPool<K, V> getKeyedPool() {
             return keyedPool;
         }
 
@@ -2351,12 +2352,12 @@ public final class PoolUtils {
      * Extends ErodingKeyedObjectPool to allow erosion to take place on a per-key
      * basis.  Timing of erosion events is tracked separately for separate keyed pools.
      */
-    private static class ErodingPerKeyKeyedObjectPool extends ErodingKeyedObjectPool {
+    private static class ErodingPerKeyKeyedObjectPool<K, V> extends ErodingKeyedObjectPool<K, V> {
         /** Erosion factor - same for all pools */
         private final float factor;
         
         /** Map of ErodingFactor instances keyed on pool keys */
-        private final Map factors = Collections.synchronizedMap(new HashMap());
+        private final Map<K, ErodingFactor> factors = Collections.synchronizedMap(new HashMap<K, ErodingFactor>());
 
         /**
          * Create a new ErordingPerKeyKeyedObjectPool decorating the given keyed pool with
@@ -2364,7 +2365,7 @@ public final class PoolUtils {
          * @param keyedPool underlying keyed pool
          * @param factor erosion factor
          */
-        public ErodingPerKeyKeyedObjectPool(final KeyedObjectPool keyedPool, final float factor) {
+        public ErodingPerKeyKeyedObjectPool(final KeyedObjectPool<K, V> keyedPool, final float factor) {
             super(keyedPool, null);
             this.factor = factor;
         }
@@ -2372,15 +2373,15 @@ public final class PoolUtils {
         /**
          * {@inheritDoc}
          */
-        protected int numIdle(final Object key) {
+        protected int numIdle(final K key) {
             return getKeyedPool().getNumIdle(key);
         }
 
         /**
          * {@inheritDoc}
          */
-        protected ErodingFactor getErodingFactor(final Object key) {
-            ErodingFactor factor = (ErodingFactor)factors.get(key);
+        protected ErodingFactor getErodingFactor(final K key) {
+            ErodingFactor factor = factors.get(key);
             // this may result in two ErodingFactors being created for a key
             // since they are small and cheap this is okay.
             if (factor == null) {

Modified: commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/PoolableObjectFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/PoolableObjectFactory.java?rev=1221705&r1=1221704&r2=1221705&view=diff
==============================================================================
--- commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/PoolableObjectFactory.java (original)
+++ commons/proper/pool/branches/POOL_1_X/src/java/org/apache/commons/pool/PoolableObjectFactory.java Wed Dec 21 13:03:54 2011
@@ -71,7 +71,7 @@ package org.apache.commons.pool;
  * @version $Revision$ $Date$
  * @since Pool 1.0
  */
-public interface PoolableObjectFactory {
+public interface PoolableObjectFactory<T> {
   /**
    * Creates an instance that can be served by the pool.
    * Instances returned from this method should be in the
@@ -83,7 +83,7 @@ public interface PoolableObjectFactory {
    * @throws Exception if there is a problem creating a new instance,
    *    this will be propagated to the code requesting an object.
    */
-  Object makeObject() throws Exception;
+  T makeObject() throws Exception;
 
   /**
    * Destroys an instance no longer needed by the pool.
@@ -104,7 +104,7 @@ public interface PoolableObjectFactory {
    * @see #validateObject
    * @see ObjectPool#invalidateObject
    */
-  void destroyObject(Object obj) throws Exception;
+  void destroyObject(T obj) throws Exception;
 
   /**
    * Ensures that the instance is safe to be returned by the pool.
@@ -114,7 +114,7 @@ public interface PoolableObjectFactory {
    * @return <code>false</code> if <code>obj</code> is not valid and should
    *         be dropped from the pool, <code>true</code> otherwise.
    */
-  boolean validateObject(Object obj);
+  boolean validateObject(T obj);
 
   /**
    * Reinitialize an instance to be returned by the pool.
@@ -124,7 +124,7 @@ public interface PoolableObjectFactory {
    *    this exception may be swallowed by the pool.
    * @see #destroyObject
    */
-  void activateObject(Object obj) throws Exception;
+  void activateObject(T obj) throws Exception;
 
   /**
    * Uninitialize an instance to be returned to the idle object pool.
@@ -134,5 +134,5 @@ public interface PoolableObjectFactory {
    *    this exception may be swallowed by the pool.
    * @see #destroyObject
    */
-  void passivateObject(Object obj) throws Exception;
+  void passivateObject(T obj) throws Exception;
 }



Mime
View raw message