commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1028302 - in /commons/proper/pool/trunk/src: java/org/apache/commons/pool2/impl/ test/org/apache/commons/pool2/impl/
Date Thu, 28 Oct 2010 14:10:04 GMT
Author: simonetripodi
Date: Thu Oct 28 14:10:03 2010
New Revision: 1028302

URL: http://svn.apache.org/viewvc?rev=1028302&view=rev
Log:
made StackObjectPoolConfig objects immutable
removed direct Config objected reference, config information copied inside pool/factory

Modified:
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPoolFactory.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPool.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java
    commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolFactory.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackKeyedObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackKeyedObjectPoolFactory.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackObjectPoolFactory.java

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPool.java?rev=1028302&r1=1028301&r2=1028302&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPool.java
Thu Oct 28 14:10:03 2010
@@ -55,7 +55,7 @@ public class StackKeyedObjectPool<K,V> e
      * @param factory the {@link KeyedPoolableObjectFactory} used to populate the pool
      */
     public StackKeyedObjectPool(KeyedPoolableObjectFactory<K,V> factory) {
-        this(factory,new StackObjectPoolConfig());
+        this(factory,StackObjectPoolConfig.Builder.createDefaultConfig());
     }
 
     /**
@@ -70,17 +70,26 @@ public class StackKeyedObjectPool<K,V> e
         if (factory == null) {
             throw new IllegalArgumentException("factory must not be null");
         }
-        if (config == null) {
-            throw new IllegalArgumentException("config must not be null");
-        }
+        this.reconfigure(config);
         _factory = factory;
-        this.config = config;
-
         _pools = new HashMap<K,Stack<V>>();
         _activeCount = new HashMap<K,Integer>();
     }
 
     /**
+     * Reconfigure the current StackObjectPoolFactory instance.
+     *
+     * @param config the {@link StackObjectPoolConfig} used to configure the pool.
+     */
+    public void reconfigure(StackObjectPoolConfig config) {
+        if (config == null) {
+            throw new IllegalArgumentException("config must not be null");
+        }
+        this.maxSleeping = config.getMaxSleeping();
+        this.initIdleCapacity = config.getInitIdleCapacity();
+    }
+
+    /**
      * Borrows an object with the given key.  If there are no idle instances under the
      * given key, a new one is created.
      * 
@@ -93,7 +102,7 @@ public class StackKeyedObjectPool<K,V> e
         Stack<V> stack = _pools.get(key);
         if(null == stack) {
             stack = new Stack<V>();
-            stack.ensureCapacity(this.config.getInitIdleCapacity() > this.config.getMaxSleeping()
? this.config.getMaxSleeping() : this.config.getInitIdleCapacity());
+            stack.ensureCapacity(this.initIdleCapacity > this.maxSleeping ? this.maxSleeping
: this.initIdleCapacity);
             _pools.put(key,stack);
         }
         V obj = null;
@@ -169,11 +178,11 @@ public class StackKeyedObjectPool<K,V> e
         Stack<V> stack = _pools.get(key);
         if(null == stack) {
             stack = new Stack<V>();
-            stack.ensureCapacity(this.config.getInitIdleCapacity() > this.config.getMaxSleeping()
? this.config.getMaxSleeping() : this.config.getInitIdleCapacity());
+            stack.ensureCapacity(this.initIdleCapacity > this.maxSleeping ? this.maxSleeping
: this.initIdleCapacity);
             _pools.put(key,stack);
         }
         final int stackSize = stack.size();
-        if (stackSize >= this.config.getMaxSleeping()) {
+        if (stackSize >= this.maxSleeping) {
             final V staleObj;
             if (stackSize > 0) {
                 staleObj = stack.remove(0);
@@ -230,12 +239,12 @@ public class StackKeyedObjectPool<K,V> e
         Stack<V> stack = _pools.get(key);
         if(null == stack) {
             stack = new Stack<V>();
-            stack.ensureCapacity(this.config.getInitIdleCapacity() > this.config.getMaxSleeping()
? this.config.getMaxSleeping() : this.config.getInitIdleCapacity());
+            stack.ensureCapacity(this.initIdleCapacity > this.maxSleeping ? this.maxSleeping
: this.initIdleCapacity);
             _pools.put(key,stack);
         }
 
         final int stackSize = stack.size();
-        if (stackSize >= this.config.getMaxSleeping()) {
+        if (stackSize >= this.maxSleeping) {
             final V staleObj;
             if (stackSize > 0) {
                 staleObj = stack.remove(0);
@@ -458,7 +467,7 @@ public class StackKeyedObjectPool<K,V> e
      * @since 1.5.5
      */
     public synchronized int getMaxSleeping() {
-        return this.config.getMaxSleeping();
+        return this.maxSleeping;
     }
 
     /**
@@ -468,15 +477,15 @@ public class StackKeyedObjectPool<K,V> e
      * @since 2.0
      */
     public synchronized void setMaxSleeping(int maxSleeping) {
-        this.config.setMaxSleeping(maxSleeping);
+        this.maxSleeping = maxSleeping;
     }
 
     /**
      * @return the initial capacity of each pool.
      * @since 1.5.5
      */
-    public int getInitSleepingCapacity() {
-        return this.config.getInitIdleCapacity();
+    public synchronized int getInitSleepingCapacity() {
+        return this.initIdleCapacity;
     }
 
     /**
@@ -513,9 +522,15 @@ public class StackKeyedObjectPool<K,V> e
     private final KeyedPoolableObjectFactory<K,V> _factory;
 
     /**
-     * My {@link StackObjectPoolConfig}.
+     * cap on the number of "sleeping" instances in the pool
+     */
+    private int maxSleeping; // @GuardedBy("this")
+
+    /**
+     * initial size of the pool (this specifies the size of the container,
+     * it does not cause the pool to be pre-populated.)
      */
-    private final StackObjectPoolConfig config;
+    private int initIdleCapacity; // @GuardedBy("this")
 
     /**
      * Total number of object borrowed and not yet returned for all pools.

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPoolFactory.java?rev=1028302&r1=1028301&r2=1028302&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPoolFactory.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackKeyedObjectPoolFactory.java
Thu Oct 28 14:10:03 2010
@@ -39,7 +39,7 @@ public class StackKeyedObjectPoolFactory
      * @see StackKeyedObjectPool#StackKeyedObjectPool(KeyedPoolableObjectFactory)
      */
     public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory<K,V> factory) {
-        this(factory,new StackObjectPoolConfig());
+        this(factory,StackObjectPoolConfig.Builder.createDefaultConfig());
     }
 
     /**
@@ -53,11 +53,21 @@ public class StackKeyedObjectPoolFactory
         if (factory == null) {
             throw new IllegalArgumentException("factory must not be null");
         }
+        _factory = factory;
+        this.reconfigure(config);
+    }
+
+    /**
+     * Reconfigure the current StackObjectPoolFactory instance.
+     *
+     * @param config the {@link StackObjectPoolConfig} used to configure the pool.
+     */
+    public void reconfigure(StackObjectPoolConfig config) {
         if (config == null) {
             throw new IllegalArgumentException("config must not be null");
         }
-        _factory = factory;
-        this.config = config;
+        this.maxSleeping = config.getMaxSleeping();
+        this.initIdleCapacity = config.getInitIdleCapacity();
     }
 
     /**
@@ -66,7 +76,7 @@ public class StackKeyedObjectPoolFactory
      * @return a new StackKeyedObjectPool with the configured factory, maxSleeping and initialCapacity
      */
     public KeyedObjectPool<K,V> createPool() {
-        return new StackKeyedObjectPool<K,V>(_factory,this.config);
+        return new StackKeyedObjectPool<K,V>(_factory,new StackObjectPoolConfig(this.maxSleeping,
this.initIdleCapacity));
     }
 
     /** 
@@ -74,10 +84,16 @@ public class StackKeyedObjectPoolFactory
      */
     private final KeyedPoolableObjectFactory<K,V> _factory;
 
-    /** 
-     * The {@link StackObjectPoolConfig} used to configure the pool.
+    /**
+     * cap on the number of "sleeping" instances in the pool
+     */
+    private int maxSleeping; // @GuardedBy("this")
+
+    /**
+     * initial size of the pool (this specifies the size of the container,
+     * it does not cause the pool to be pre-populated.)
      */
-    private StackObjectPoolConfig config;
+    private int initIdleCapacity; // @GuardedBy("this")
 
     /**
      * Returns the KeyedPoolableObjectFactory used by StackKeyedObjectPools created by this
factory
@@ -96,7 +112,7 @@ public class StackKeyedObjectPoolFactory
      * @since 1.5.5
      */
     public synchronized int getMaxSleeping() {
-        return this.config.getMaxSleeping();
+        return this.maxSleeping;
     }
 
     /**
@@ -106,7 +122,7 @@ public class StackKeyedObjectPoolFactory
      * @since 2.0
      */
     public synchronized void setMaxSleeping(int maxSleeping) {
-        this.config.setMaxSleeping(maxSleeping);
+        this.maxSleeping = maxSleeping;
     }
 
     /**
@@ -116,7 +132,7 @@ public class StackKeyedObjectPoolFactory
      * @since 1.5.5
      */
     public synchronized int getInitialCapacity() {
-        return this.config.getInitIdleCapacity();
+        return this.initIdleCapacity;
     }
 
     /**
@@ -126,7 +142,7 @@ public class StackKeyedObjectPoolFactory
      * @since 2.0
      */
     public synchronized void setInitIdleCapacity(int initIdleCapacity) {
-        this.config.setInitIdleCapacity(initIdleCapacity);
+        this.initIdleCapacity = initIdleCapacity;
     }
 
 }

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPool.java?rev=1028302&r1=1028301&r2=1028302&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPool.java
Thu Oct 28 14:10:03 2010
@@ -51,7 +51,7 @@ public class StackObjectPool<T> extends 
      * @param factory the {@link PoolableObjectFactory} used to populate the pool
      */
     public StackObjectPool(PoolableObjectFactory<T> factory) {
-        this(factory,new StackObjectPoolConfig());
+        this(factory,StackObjectPoolConfig.Builder.createDefaultConfig());
     }
 
     /**
@@ -62,14 +62,22 @@ public class StackObjectPool<T> extends 
      * @param config the {@link StackObjectPoolConfig} used to configure the pool.
      */
     public StackObjectPool(PoolableObjectFactory<T> factory, StackObjectPoolConfig
config) {
+        _factory = factory;
+        _pool = new Stack<T>();
+        this.reconfigure(config);
+    }
+
+    /**
+     * Reconfigure the current StackObjectPoolFactory instance.
+     *
+     * @param config the {@link StackObjectPoolConfig} used to configure the pool.
+     */
+    public void reconfigure(StackObjectPoolConfig config) {
         if (config == null) {
             throw new IllegalArgumentException("config must not be null");
         }
-        _factory = factory;
-        this.config = config;
-
-        _pool = new Stack<T>();
-        _pool.ensureCapacity(this.config.getInitIdleCapacity() > this.config.getMaxSleeping()
? this.config.getMaxSleeping() : this.config.getInitIdleCapacity());
+        this.maxSleeping = config.getMaxSleeping();
+        _pool.ensureCapacity(config.getInitIdleCapacity() > config.getMaxSleeping() ?
config.getMaxSleeping() : config.getInitIdleCapacity());
     }
 
     /**
@@ -177,7 +185,7 @@ public class StackObjectPool<T> extends 
         _numActive--;
         if (success) {
             T toBeDestroyed = null;
-            if(_pool.size() >= this.config.getMaxSleeping()) {
+            if(_pool.size() >= this.maxSleeping) {
                 shouldDestroy = true;
                 toBeDestroyed = _pool.remove(0); // remove the stalest object
             }
@@ -299,7 +307,7 @@ public class StackObjectPool<T> extends 
 
         if (success) {
             T toBeDestroyed = null;
-            if(_pool.size() >= this.config.getMaxSleeping()) {
+            if(_pool.size() >= this.maxSleeping) {
                 shouldDestroy = true;
                 toBeDestroyed = _pool.remove(0); // remove the stalest object
             }
@@ -328,9 +336,9 @@ public class StackObjectPool<T> extends 
     private final PoolableObjectFactory<T> _factory;
 
     /**
-     * My {@link StackObjectPoolConfig}.
+     * cap on the number of "sleeping" instances in the pool
      */
-    private final StackObjectPoolConfig config;
+    private int maxSleeping; // @GuardedBy("this")
 
     /**
      * Number of objects borrowed but not yet returned to the pool.
@@ -354,7 +362,7 @@ public class StackObjectPool<T> extends 
      * @since 1.5.5
      */
     public synchronized int getMaxSleeping() {
-        return this.config.getMaxSleeping();
+        return this.maxSleeping;
     }
 
     /**
@@ -364,6 +372,6 @@ public class StackObjectPool<T> extends 
      * @since 2.0
      */
    public synchronized void setMaxSleeping(int maxSleeping) {
-       this.config.setMaxSleeping(maxSleeping);
+       this.maxSleeping = maxSleeping;
    }
 }

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java?rev=1028302&r1=1028301&r2=1028302&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolConfig.java
Thu Oct 28 14:10:03 2010
@@ -38,39 +38,42 @@ public class StackObjectPoolConfig {
     /**
      * cap on the number of "sleeping" instances in the pool
      */
-    private int maxSleeping = DEFAULT_MAX_SLEEPING;
+    private final int maxSleeping;
 
     /**
      * initial size of the pool (this specifies the size of the container,
      * it does not cause the pool to be pre-populated.)
      */
-    private int initIdleCapacity = DEFAULT_INIT_SLEEPING_CAPACITY;
+    private final int initIdleCapacity;
 
-    public int getMaxSleeping() {
-        return maxSleeping;
+    public StackObjectPoolConfig(final int maxSleeping, final int initIdleCapacity) {
+        this.maxSleeping = (maxSleeping < 0 ? DEFAULT_MAX_SLEEPING : maxSleeping);
+        this.initIdleCapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY
: initIdleCapacity);
     }
 
-    public void setMaxSleeping(int maxSleeping) {
-        this.maxSleeping = (maxSleeping < 0 ? DEFAULT_MAX_SLEEPING : maxSleeping);
+    public int getMaxSleeping() {
+        return maxSleeping;
     }
 
     public int getInitIdleCapacity() {
         return initIdleCapacity;
     }
 
-    public void setInitIdleCapacity(int initIdleCapacity) {
-        this.initIdleCapacity = (initIdleCapacity < 1 ? DEFAULT_INIT_SLEEPING_CAPACITY
: initIdleCapacity);
-    }
-
     /**
      * Helper class to easily build {@link StackObjectPoolConfig} instances.
      */
     public static final class Builder {
 
         /**
-         * The {@link StackObjectPoolConfig} instance, initialized with default values.
+         * cap on the number of "sleeping" instances in the pool
          */
-        private final StackObjectPoolConfig config = new StackObjectPoolConfig();
+        private int maxSleeping = DEFAULT_MAX_SLEEPING;
+
+        /**
+         * initial size of the pool (this specifies the size of the container,
+         * it does not cause the pool to be pre-populated.)
+         */
+        private int initIdleCapacity = DEFAULT_INIT_SLEEPING_CAPACITY;
 
         /**
          * Set the number of "sleeping" instances in the pool.
@@ -79,7 +82,7 @@ public class StackObjectPoolConfig {
          * @return this builder instance.
          */
         public Builder setMaxSleeping(int maxSleeping) {
-            this.config.setMaxSleeping(maxSleeping);
+            this.maxSleeping = maxSleeping;
             return this;
         }
 
@@ -90,17 +93,26 @@ public class StackObjectPoolConfig {
          * @return this builder instance.
          */
         public Builder setInitIdleCapacity(int initIdleCapacity) {
-            this.config.setInitIdleCapacity(initIdleCapacity);
+            this.initIdleCapacity = initIdleCapacity;
             return this;
         }
 
         /**
-         * Return the created {@link StackObjectPoolConfig} instance.
+         * Creates a {@link StackObjectPoolConfig} instance.
          *
          * @return the created {@link StackObjectPoolConfig} instance.
          */
-        public StackObjectPoolConfig getConfig() {
-            return this.config;
+        public StackObjectPoolConfig createConfig() {
+            return new StackObjectPoolConfig(this.maxSleeping, this.initIdleCapacity);
+        }
+
+        /**
+         * Creates a {@link StackObjectPoolConfig} instance with default values.
+         *
+         * @return a {@link StackObjectPoolConfig} instance with default values.
+         */
+        public static StackObjectPoolConfig createDefaultConfig() {
+            return new Builder().createConfig();
         }
 
     }

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolFactory.java?rev=1028302&r1=1028301&r2=1028302&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolFactory.java
(original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool2/impl/StackObjectPoolFactory.java
Thu Oct 28 14:10:03 2010
@@ -39,7 +39,7 @@ public class StackObjectPoolFactory<T> i
      * @see StackObjectPool#StackObjectPool(PoolableObjectFactory)
      */
     public StackObjectPoolFactory(PoolableObjectFactory<T> factory) {
-        this(factory,new StackObjectPoolConfig());
+        this(factory,StackObjectPoolConfig.Builder.createDefaultConfig());
     }
 
     /**
@@ -52,11 +52,21 @@ public class StackObjectPoolFactory<T> i
         if (factory == null) {
             throw new IllegalArgumentException("factory must not be null");
         }
+        this.reconfigure(config);
+        _factory = factory;
+    }
+
+    /**
+     * Reconfigure the current StackObjectPoolFactory instance.
+     *
+     * @param config the {@link StackObjectPoolConfig} used to configure the pool.
+     */
+    public void reconfigure(StackObjectPoolConfig config) {
         if (config == null) {
             throw new IllegalArgumentException("config must not be null");
         }
-        _factory = factory;
-        this.config = config;
+        this.maxSleeping = config.getMaxSleeping();
+        this.initIdleCapacity = config.getInitIdleCapacity();
     }
 
     /**
@@ -65,7 +75,7 @@ public class StackObjectPoolFactory<T> i
      * @return a new StackObjectPool with the configured factory, maxIdle and initial capacity
settings
      */
     public ObjectPool<T> createPool() {
-        return new StackObjectPool<T>(_factory,this.config);
+        return new StackObjectPool<T>(_factory,new StackObjectPoolConfig(this.maxSleeping,
this.initIdleCapacity));
     }
 
     /**
@@ -74,9 +84,15 @@ public class StackObjectPoolFactory<T> i
     private final PoolableObjectFactory<T> _factory;
 
     /**
-     * The {@link StackObjectPoolConfig} used to configure the pool.
+     * cap on the number of "sleeping" instances in the pool
      */
-    private final StackObjectPoolConfig config;
+    private int maxSleeping; // @GuardedBy("this")
+
+    /**
+     * initial size of the pool (this specifies the size of the container,
+     * it does not cause the pool to be pre-populated.)
+     */
+    private int initIdleCapacity; // @GuardedBy("this")
 
     /**
      * Returns the factory used by created pools.
@@ -95,7 +111,7 @@ public class StackObjectPoolFactory<T> i
      * @since 1.5.5
      */
     public synchronized int getMaxSleeping() {
-        return this.config.getMaxSleeping();
+        return this.maxSleeping;
     }
 
     /**
@@ -105,7 +121,7 @@ public class StackObjectPoolFactory<T> i
      * @since 2.0
      */
     public synchronized void setMaxSleeping(int maxSleeping) {
-        this.config.setMaxSleeping(maxSleeping);
+        this.maxSleeping = maxSleeping;
     }
 
     /**
@@ -115,7 +131,16 @@ public class StackObjectPoolFactory<T> i
      * @since 1.5.5
      */
     public synchronized int getInitCapacity() {
-        return this.config.getInitIdleCapacity();
+        return this.initIdleCapacity;
+    }
+
+    /**
+     * Set the size of created containers (created pools are not pre-populated).
+     *
+     * @param initIdleCapacity size of created containers (created pools are not pre-populated)
+     */
+    public synchronized void setInitCapacity(int initIdleCapacity) {
+        this.initIdleCapacity = initIdleCapacity;
     }
 
 }

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackKeyedObjectPool.java?rev=1028302&r1=1028301&r2=1028302&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackKeyedObjectPool.java
Thu Oct 28 14:10:03 2010
@@ -38,8 +38,9 @@ import org.junit.Test;
 public class TestStackKeyedObjectPool extends TestBaseKeyedObjectPool {
     @Override
     protected KeyedObjectPool<Object,Object> makeEmptyPool(int mincapacity) {
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setInitIdleCapacity(mincapacity);
+        StackObjectPoolConfig config = new StackObjectPoolConfig.Builder()
+            .setInitIdleCapacity(mincapacity)
+            .createConfig();
         StackKeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>(new
SimpleFactory(),config);
         return pool;
     }
@@ -148,16 +149,12 @@ public class TestStackKeyedObjectPool ex
             assertNotNull(pool);
         }
         {
-            StackObjectPoolConfig config = new StackObjectPoolConfig();
-            config.setMaxSleeping(10);
-            config.setInitIdleCapacity(5);
+            StackObjectPoolConfig config = new StackObjectPoolConfig(10, 5);
             StackKeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>(new
SimpleFactory(),config);
             assertNotNull(pool);
         }
         {
-            StackObjectPoolConfig config = new StackObjectPoolConfig();
-            config.setMaxSleeping(10);
-            config.setInitIdleCapacity(5);
+            StackObjectPoolConfig config = new StackObjectPoolConfig(10, 5);
             StackKeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>(new
SimpleFactory(),config);
             assertNotNull(pool);
         }

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackKeyedObjectPoolFactory.java?rev=1028302&r1=1028301&r2=1028302&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackKeyedObjectPoolFactory.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackKeyedObjectPoolFactory.java
Thu Oct 28 14:10:03 2010
@@ -44,14 +44,15 @@ public class TestStackKeyedObjectPoolFac
         StackKeyedObjectPool<Object,Object> pool = (StackKeyedObjectPool<Object,Object>)factory.createPool();
         pool.close();
 
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setMaxSleeping(1);
+        StackObjectPoolConfig config = new StackObjectPoolConfig.Builder()
+            .setMaxSleeping(1)
+            .createConfig();
         factory = new StackKeyedObjectPoolFactory<Object,Object>(createObjectFactory(),
config);
         pool = (StackKeyedObjectPool<Object,Object>)factory.createPool();
         assertEquals(1,pool.getMaxSleeping());
         pool.close();
 
-        config.setInitIdleCapacity(2);
+        config = new StackObjectPoolConfig(1, 2);
         factory = new StackKeyedObjectPoolFactory<Object,Object>(createObjectFactory(),
config);
         pool = (StackKeyedObjectPool<Object,Object>)factory.createPool();
         assertEquals(1,pool.getMaxSleeping());

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackObjectPool.java?rev=1028302&r1=1028301&r2=1028302&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackObjectPool.java
Thu Oct 28 14:10:03 2010
@@ -29,7 +29,6 @@ import java.util.NoSuchElementException;
 import org.apache.commons.pool2.ObjectPool;
 import org.apache.commons.pool2.PoolableObjectFactory;
 import org.apache.commons.pool2.TestBaseObjectPool;
-import org.apache.commons.pool2.impl.StackObjectPool;
 import org.junit.Test;
 
 /**
@@ -81,8 +80,9 @@ public class TestStackObjectPool extends
         factory.setValidateSelectively(true);  // Even numbers fail validation
         factory.setPassivateSelectively(true); // Multiples of 3 fail passivation
 
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setMaxSleeping(20);
+        StackObjectPoolConfig config = new StackObjectPoolConfig.Builder()
+            .setMaxSleeping(20)
+            .createConfig();
 
         ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, config);
         Integer[] obj = new Integer[10];
@@ -127,8 +127,9 @@ public class TestStackObjectPool extends
     @Test
     public void testBorrowReturnWithSometimesInvalidObjects() throws Exception {
         SelectiveFactory factory = new SelectiveFactory();
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setMaxSleeping(20);
+        StackObjectPoolConfig config = new StackObjectPoolConfig.Builder()
+            .setMaxSleeping(20)
+            .createConfig();
         ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, config);
 
         Integer[] obj = new Integer[10];
@@ -156,15 +157,14 @@ public class TestStackObjectPool extends
             assertNotNull(pool);
         }
         {
-            StackObjectPoolConfig config = new StackObjectPoolConfig();
-            config.setMaxSleeping(10);
+            StackObjectPoolConfig config = new StackObjectPoolConfig.Builder()
+                .setMaxSleeping(10)
+                .createConfig();
             StackObjectPool<Integer> pool = new StackObjectPool<Integer>(null,config);
             assertNotNull(pool);
         }
         {
-            StackObjectPoolConfig config = new StackObjectPoolConfig();
-            config.setMaxSleeping(20);
-            config.setInitIdleCapacity(5);
+            StackObjectPoolConfig config = new StackObjectPoolConfig(20, 5);
             StackObjectPool<Integer> pool = new StackObjectPool<Integer>(null,config);
             assertNotNull(pool);
         }
@@ -176,9 +176,7 @@ public class TestStackObjectPool extends
     @Test
     public void testMaxIdleInitCapacityOutOfRange() throws Exception {
         SimpleFactory factory = new SimpleFactory();
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setMaxSleeping(-1);
-        config.setInitIdleCapacity(0);
+        StackObjectPoolConfig config = new StackObjectPoolConfig(-1, 0);
         StackObjectPool<Object> pool = new StackObjectPool<Object>(factory, config);
         assertEquals(pool.getMaxSleeping(), StackObjectPoolConfig.DEFAULT_MAX_SLEEPING);
         pool.addObject();
@@ -192,8 +190,9 @@ public class TestStackObjectPool extends
     @Test
     public void testReturnObjectDiscardOrder() throws Exception {
         SelectiveFactory factory = new SelectiveFactory();
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setMaxSleeping(3);
+        StackObjectPoolConfig config = new StackObjectPoolConfig.Builder()
+            .setMaxSleeping(3)
+            .createConfig();
         ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, config);
 
         // borrow more objects than the pool can hold
@@ -249,8 +248,9 @@ public class TestStackObjectPool extends
     @Test
     public void testExceptionOnDestroy() throws Exception {
         SelectiveFactory factory = new SelectiveFactory();
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setMaxSleeping(2);
+        StackObjectPoolConfig config = new StackObjectPoolConfig.Builder()
+            .setMaxSleeping(2)
+            .createConfig();
         ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, config);
         factory.setThrowOnDestroy(true);
         for (int i = 0; i < 3; i++) {
@@ -275,8 +275,9 @@ public class TestStackObjectPool extends
     @Test
     public void testExceptionOnPassivate() throws Exception {
         SelectiveFactory factory = new SelectiveFactory();
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setMaxSleeping(2);
+        StackObjectPoolConfig config = new StackObjectPoolConfig.Builder()
+            .setMaxSleeping(2)
+            .createConfig();
         ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, config);
         factory.setThrowOnPassivate(true);
         
@@ -302,8 +303,9 @@ public class TestStackObjectPool extends
     @Test
     public void testExceptionOnValidate() throws Exception {
         SelectiveFactory factory = new SelectiveFactory();
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setMaxSleeping(2);
+        StackObjectPoolConfig config = new StackObjectPoolConfig.Builder()
+            .setMaxSleeping(2)
+            .createConfig();
         ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, config);
         factory.setThrowOnValidate(true);
         
@@ -381,16 +383,13 @@ public class TestStackObjectPool extends
     @Test
     public void testInitIdleCapacityExceeded() throws Exception {
         PoolableObjectFactory<Object> factory = new SimpleFactory();
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setMaxSleeping(2);
-        config.setInitIdleCapacity(1);
+        StackObjectPoolConfig config = new StackObjectPoolConfig(2, 1);
         ObjectPool<Object> pool = new StackObjectPool<Object>(factory, config);
         pool.addObject();
         pool.addObject();
         assertEquals(2, pool.getNumIdle());
         pool.close();
-        config.setMaxSleeping(1);
-        config.setInitIdleCapacity(2);
+        config = new StackObjectPoolConfig(1, 2);
         pool = new StackObjectPool<Object>(factory, config);
         pool.addObject();
         pool.addObject();

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackObjectPoolFactory.java?rev=1028302&r1=1028301&r2=1028302&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackObjectPoolFactory.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestStackObjectPoolFactory.java
Thu Oct 28 14:10:03 2010
@@ -41,8 +41,9 @@ public class TestStackObjectPoolFactory 
 
     @Test
     public void testConstructors() throws Exception {
-        StackObjectPoolConfig config = new StackObjectPoolConfig();
-        config.setMaxSleeping(1);
+        StackObjectPoolConfig config = new StackObjectPoolConfig.Builder()
+            .setMaxSleeping(1)
+            .createConfig();
         StackObjectPoolFactory<Object> factory = new StackObjectPoolFactory<Object>(new
MethodCallPoolableObjectFactory(), config);
         ObjectPool<Object> pool = factory.createPool();
         Object a = pool.borrowObject();



Mime
View raw message