Author: markt Date: Mon Apr 30 14:30:35 2012 New Revision: 1332219 URL: http://svn.apache.org/viewvc?rev=1332219&view=rev Log: Pull up lifo and evictionPolicy
Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java?rev=1332219&r1=1332218&r2=1332219&view=diff ============================================================================== --- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java (original) +++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java Mon Apr 30 14:30:35 2012 @@ -61,6 +61,7 @@ public abstract class BaseGenericObjectP GenericObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED; private volatile long maxWaitMillis = GenericKeyedObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS; + private volatile boolean lifo = GenericObjectPoolConfig.DEFAULT_LIFO; private volatile boolean testOnBorrow = GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW; private volatile boolean testOnReturn = @@ -75,6 +76,7 @@ public abstract class BaseGenericObjectP GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS; private volatile long softMinEvictableIdleTimeMillis = GenericObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS; + private volatile EvictionPolicy<T> evictionPolicy; // Internal (primarily state) attributes @@ -212,6 +214,38 @@ public abstract class BaseGenericObjectP } /** + * Returns whether the pool has LIFO (last in, first out) behaviour with + * respect to idle objects - always returning the most recently used object + * from the pool, or as a FIFO (first in, first out) queue, where the pool + * always returns the oldest object in the idle object pool. + * + * @return <code>true</true> if the pool is configured with LIFO behaviour + * or <code>false</code> if the pool is configured with FIFO + * behaviour + * + * @see #setLifo + */ + public boolean getLifo() { + return lifo; + } + + /** + * Sets whether the pool has LIFO (last in, first out) behaviour with + * respect to idle objects - always returning the most recently used object + * from the pool, or as a FIFO (first in, first out) queue, where the pool + * always returns the oldest object in the idle object pool. + * + * @param lifo <code>true</true> if the pool is to be configured with LIFO + * behaviour or <code>false</code> if the pool is to be + * configured with FIFO behaviour + * + * @see #getLifo() + */ + public void setLifo(boolean lifo) { + this.lifo = lifo; + } + + /** * Returns whether objects borrowed from the pool will be validated before * being returned from the <code>borrowObject()</code> method. Validation is * performed by the factory associated with the pool. If the object fails to @@ -450,6 +484,50 @@ public abstract class BaseGenericObjectP this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis; } + /** + * Returns the name of the {@link EvictionPolicy} implementation that is + * used by this pool. + * + * @return The fully qualified class name of the {@link EvictionPolicy} + * + * @see #setEvictionPolicyClassName(String) + */ + public String getEvictionPolicyClassName() { + return evictionPolicy.getClass().getName(); + } + + /** + * Sets the name of the {@link EvictionPolicy} implementation that is + * used by this pool. + * + * @param evictionPolicyClassName the fully qualified class name of the + * new eviction policy + * + * @see #getEvictionPolicyClassName() + */ + @SuppressWarnings("unchecked") + public void setEvictionPolicyClassName(String evictionPolicyClassName) { + try { + Class<?> clazz = Class.forName(evictionPolicyClassName); + Object policy = clazz.newInstance(); + if (policy instanceof EvictionPolicy<?>) { + this.evictionPolicy = (EvictionPolicy<T>) policy; + } + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException( + "Unable to create EvictionPolicy instance of type " + + evictionPolicyClassName, e); + } catch (InstantiationException e) { + throw new IllegalArgumentException( + "Unable to create EvictionPolicy instance of type " + + evictionPolicyClassName, e); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException( + "Unable to create EvictionPolicy instance of type " + + evictionPolicyClassName, e); + } + } + /** * Closes the pool, destroys the remaining idle objects and, if registered @@ -477,6 +555,13 @@ public abstract class BaseGenericObjectP */ public abstract void evict() throws Exception; + /* + * Make the eviction policy instance available to the sub-classes + */ + EvictionPolicy<T> getEvictionPolicy() { + return evictionPolicy; + } + /** * Throws an <code>IllegalStateException</code> if called when the pool has * been closed. Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java?rev=1332219&r1=1332218&r2=1332219&view=diff ============================================================================== --- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java (original) +++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericKeyedObjectPool.java Mon Apr 30 14:30:35 2012 @@ -364,61 +364,6 @@ public class GenericKeyedObjectPool<K,T> } } - public String getEvictionPolicyClassName() { - return evictionPolicy.getClass().getName(); - } - - @SuppressWarnings("unchecked") - public void setEvictionPolicyClassName(String evictionPolicyClassName) { - try { - Class<?> clazz = Class.forName(evictionPolicyClassName); - Object policy = clazz.newInstance(); - if (policy instanceof EvictionPolicy<?>) { - this.evictionPolicy = (EvictionPolicy<T>) policy; - } - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException( - "Unable to create EvictionPolicy instance of type " + - evictionPolicyClassName, e); - } catch (InstantiationException e) { - throw new IllegalArgumentException( - "Unable to create EvictionPolicy instance of type " + - evictionPolicyClassName, e); - } catch (IllegalAccessException e) { - throw new IllegalArgumentException( - "Unable to create EvictionPolicy instance of type " + - evictionPolicyClassName, e); - } - } - - /** - * The pools can be configured to behave as LIFO (last in, first out) queues - * with respect to idle objects - always returning the most recently used - * object from the pool, or as FIFO (first in, first out) queues, where - * {@link #borrowObject(Object)} and {@link #borrowObject(Object, long)} - * always return the oldest object in the idle object pool. - * - * @return <code>true</code> if the pools are configured to act as LIFO - * queues or <code>false</code> if the pools are configured to act - * as FIFO queues - * @since 1.4 - */ - @Override - public boolean getLifo() { - return lifo; - } - - /** - * Sets the LIFO property of the pools. - * - * @param lifo the new value for the lifo property - * @since 1.4 - * @see #getLifo() - */ - public void setLifo(boolean lifo) { - this.lifo = lifo; - } - /** * Sets the configuration. * @param conf the new configuration to use. @@ -1062,6 +1007,7 @@ public class GenericKeyedObjectPool<K,T> } PooledObject<T> underTest = null; + EvictionPolicy<T> evictionPolicy = getEvictionPolicy(); synchronized (evictionLock) { EvictionConfig evictionConfig = new EvictionConfig( @@ -1769,7 +1715,6 @@ public class GenericKeyedObjectPool<K,T> private int maxTotalPerKey = GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY; - private boolean lifo = GenericKeyedObjectPoolConfig.DEFAULT_LIFO; private final KeyedPoolableObjectFactory<K,T> factory; @@ -1813,11 +1758,6 @@ public class GenericKeyedObjectPool<K,T> */ private K evictionKey = null; // @GuardedBy("evictionLock") - /** - * Policy that determines if an object is eligible for eviction or not. - */ - private EvictionPolicy<T> evictionPolicy; - /** Object used to ensure closed() is only called once. */ private final Object closeLock = new Object(); Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java?rev=1332219&r1=1332218&r2=1332219&view=diff ============================================================================== --- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java (original) +++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java Mon Apr 30 14:30:35 2012 @@ -302,61 +302,6 @@ public class GenericObjectPool<T> extend } - public String getEvictionPolicyClassName() { - return evictionPolicy.getClass().getName(); - } - - @SuppressWarnings("unchecked") - public void setEvictionPolicyClassName(String evictionPolicyClassName) { - try { - Class<?> clazz = Class.forName(evictionPolicyClassName); - Object policy = clazz.newInstance(); - if (policy instanceof EvictionPolicy<?>) { - this.evictionPolicy = (EvictionPolicy<T>) policy; - } - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException( - "Unable to create EvictionPolicy instance of type " + - evictionPolicyClassName, e); - } catch (InstantiationException e) { - throw new IllegalArgumentException( - "Unable to create EvictionPolicy instance of type " + - evictionPolicyClassName, e); - } catch (IllegalAccessException e) { - throw new IllegalArgumentException( - "Unable to create EvictionPolicy instance of type " + - evictionPolicyClassName, e); - } - } - - /** - * The pool can be configured to behave as a LIFO (last in, first out) queue - * with respect to idle objects - always returning the most recently used - * object from the pool, or as a FIFO (first in, first out) queue, where - * {@link #borrowObject} always returns the oldest object in the idle object - * pool. - * - * @return <code>true</true> if the pool is configured to act as a LIFO - * queue or <code>false</code> if the pool is configured to act as a - * FIFO queue - * @since 1.4 - */ - @Override - public boolean getLifo() { - return lifo; - } - - /** - * Sets the LIFO property of the pool. - * - * @param lifo the new value for the LIFO property - * @since 1.4 - * @see #getLifo() - */ - public void setLifo(boolean lifo) { - this.lifo = lifo; - } - /** * Sets my configuration. * @@ -785,6 +730,7 @@ public class GenericObjectPool<T> extend } PooledObject<T> underTest = null; + EvictionPolicy<T> evictionPolicy = getEvictionPolicy(); synchronized (evictionLock) { EvictionConfig evictionConfig = new EvictionConfig( @@ -1106,7 +1052,6 @@ public class GenericObjectPool<T> extend */ private volatile int minIdle = GenericObjectPoolConfig.DEFAULT_MIN_IDLE; - private volatile boolean lifo = GenericObjectPoolConfig.DEFAULT_LIFO; private final PoolableObjectFactory<T> factory; @@ -1134,11 +1079,6 @@ public class GenericObjectPool<T> extend private final LinkedBlockingDeque<PooledObject<T>> idleObjects = new LinkedBlockingDeque<PooledObject<T>>(); - /** - * Policy that determines if an object is eligible for eviction or not. - */ - private EvictionPolicy<T> evictionPolicy; - /** Object used to ensure closed() is only called once. */ private final Object closeLock = new Object();