commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1021840 - in /commons/proper/pool/trunk/src: java/org/apache/commons/pool/impl/StackObjectPool.java test/org/apache/commons/pool/impl/TestStackObjectPool.java
Date Tue, 12 Oct 2010 17:03:06 GMT
Author: simonetripodi
Date: Tue Oct 12 17:03:06 2010
New Revision: 1021840

URL: http://svn.apache.org/viewvc?rev=1021840&view=rev
Log:
removed deprecated constructors
removed deprecated Factory setter
properties made private
added missing syncronized setter(s)
updated related testcase

Modified:
    commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java?rev=1021840&r1=1021839&r2=1021840&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPool.java Tue
Oct 12 17:03:06 2010
@@ -46,52 +46,6 @@ import org.apache.commons.pool.PoolableO
  */
 public class StackObjectPool<T> extends BaseObjectPool<T> implements ObjectPool<T>
{
     /**
-     * Create a new pool using no factory. Clients must first 
-     * {@link #setFactory(PoolableObjectFactory) set the factory} or
-     * else this pool will not behave correctly. Clients may first populate the pool
-     * using {@link #returnObject(java.lang.Object)} before they can be {@link #borrowObject
borrowed}
-     * but this usage is <strong>discouraged</strong>.
-     *
-     * @see #StackObjectPool(PoolableObjectFactory)
-     * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPool(PoolableObjectFactory)}
-     */
-    public StackObjectPool() {
-        this((PoolableObjectFactory<T>)null,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY);
-    }
-
-    /**
-     * Create a new pool using no factory.
-     * Clients must first {@link #setFactory(PoolableObjectFactory) set the factory} or
-     * else this pool will not behave correctly. Clients may first populate the pool
-     * using {@link #returnObject(java.lang.Object)} before they can be {@link #borrowObject
borrowed}
-     * but this usage is <strong>discouraged</strong>.
-     *
-     * @param maxIdle cap on the number of "sleeping" instances in the pool
-     * @see #StackObjectPool(PoolableObjectFactory, int)
-     * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPool(PoolableObjectFactory,
int)}
-     */
-    public StackObjectPool(int maxIdle) {
-        this((PoolableObjectFactory<T>)null,maxIdle,DEFAULT_INIT_SLEEPING_CAPACITY);
-    }
-
-    /**
-     * Create a new pool using no factory.
-     * Clients must first {@link #setFactory(PoolableObjectFactory) set the factory} or
-     * else this pool will not behave correctly. Clients may first populate the pool
-     * using {@link #returnObject(java.lang.Object)} before they can be {@link #borrowObject
borrowed}
-     * but this usage is <strong>discouraged</strong>.
-     *
-     * @param maxIdle cap on the number of "sleeping" instances in the pool
-     * @param initIdleCapacity initial size of the pool (this specifies the size of the container,
-     *             it does not cause the pool to be pre-populated.)
-     * @see #StackObjectPool(PoolableObjectFactory, int, int)
-     * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPool(PoolableObjectFactory,
int, int)}
-     */
-    public StackObjectPool(int maxIdle, int initIdleCapacity) {
-        this((PoolableObjectFactory<T>)null,maxIdle,initIdleCapacity);
-    }
-
-    /**
      * Create a new <tt>StackObjectPool</tt> using the specified <i>factory</i>
to create new instances.
      *
      * @param factory the {@link PoolableObjectFactory} used to populate the pool
@@ -381,27 +335,6 @@ public class StackObjectPool<T> extends 
     }
 
     /**
-     * Sets the {@link PoolableObjectFactory factory} this pool uses
-     * to create new instances. Trying to change
-     * the <code>factory</code> while there are borrowed objects will
-     * throw an {@link IllegalStateException}.
-     *
-     * @param factory the {@link PoolableObjectFactory} used to create new instances.
-     * @throws IllegalStateException when the factory cannot be set at this time
-     * @deprecated to be removed in pool 2.0
-     */
-    @Override
-    public synchronized void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException
{
-        assertOpen();
-        if(0 < getNumActive()) {
-            throw new IllegalStateException("Objects are already active");
-        } else {
-            clear();
-            _factory = factory;
-        }
-    }
-
-    /**
      * The cap on the number of "sleeping" instances in the pool.
      */
     protected static final int DEFAULT_MAX_SLEEPING  = 8;
@@ -414,28 +347,24 @@ public class StackObjectPool<T> extends 
     protected static final int DEFAULT_INIT_SLEEPING_CAPACITY = 4;
 
     /** 
-     * My pool.
-     * @deprecated to be made private in pool 2.0 
+     * My pool. 
      */
-    protected Stack<T> _pool = null;
+    private Stack<T> _pool = null;
 
     /** 
      * My {@link PoolableObjectFactory}.
-     * @deprecated to be made private in pool 2.0 - use {@link #getFactory()}
      */
-    protected PoolableObjectFactory<T> _factory = null;
+    private final PoolableObjectFactory<T> _factory;
 
     /** 
-     * The cap on the number of "sleeping" instances in the pool. 
-     * @deprecated to be made private in pool 2.0 - use {@link #getMaxSleeping()}
+     * The cap on the number of "sleeping" instances in the pool.
      */
-    protected int _maxSleeping = DEFAULT_MAX_SLEEPING;
+    private int _maxSleeping = DEFAULT_MAX_SLEEPING;
     
     /**
      * Number of objects borrowed but not yet returned to the pool.
-     * @deprecated to be made private in pool 2.0 - use {@link #getNumActive()}
      */
-    protected int _numActive = 0;
+    private int _numActive = 0;
 
     /**
      * Returns the {@link PoolableObjectFactory} used by this pool to create and manage object
instances.
@@ -453,9 +382,17 @@ public class StackObjectPool<T> extends 
      * @return maxSleeping
      * @since 1.5.5
      */
-    public int getMaxSleeping() {
+    public synchronized int getMaxSleeping() {
         return _maxSleeping;
     }
 
-   
+    /**
+     * Sets the maximum number of idle instances in the pool.
+     *
+     * @param maxSleeping
+     * @since 2.0
+     */
+   public synchronized void setMaxSleeping(int maxSleeping) {
+       _maxSleeping = maxSleeping;
+   }
 }

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java?rev=1021840&r1=1021839&r2=1021840&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
Tue Oct 12 17:03:06 2010
@@ -18,7 +18,6 @@
 package org.apache.commons.pool.impl;
 
 import java.util.ArrayList;
-import java.util.BitSet;
 import java.util.List;
 import java.util.NoSuchElementException;
 
@@ -68,99 +67,6 @@ public class TestStackObjectPool extends
     }
 
     /**
-     * @deprecated - to be removed in pool 2.0
-     */
-    public void testPoolWithNullFactory() throws Exception {
-        ObjectPool<Object> pool = new StackObjectPool<Object>(10);
-        for(int i=0;i<10;i++) {
-            pool.returnObject(new Integer(i));
-        }
-        for(int j=0;j<3;j++) {
-            Integer[] borrowed = new Integer[10];
-            BitSet found = new BitSet();
-            for(int i=0;i<10;i++) {
-                borrowed[i] = (Integer)(pool.borrowObject());
-                assertNotNull(borrowed);
-                assertTrue(!found.get(borrowed[i].intValue()));
-                found.set(borrowed[i].intValue());
-            }
-            for(int i=0;i<10;i++) {
-                pool.returnObject(borrowed[i]);
-            }
-        }
-        pool.invalidateObject(pool.borrowObject());
-        pool.invalidateObject(pool.borrowObject());
-        pool.clear();        
-    }
-    
-    /**
-     * @deprecated - to be removed in pool 2.0
-     */
-    public void testBorrowFromEmptyPoolWithNullFactory() throws Exception {
-        ObjectPool<Object> pool = new StackObjectPool<Object>();
-        try {
-            pool.borrowObject();
-            fail("Expected NoSuchElementException");
-        } catch(NoSuchElementException e) {
-            // expected
-        }
-    }
-    
-    /**
-     * @deprecated - to be removed in pool 2.0
-     */
-    @Override
-    public void testSetFactory() throws Exception {
-        ObjectPool<Object> pool = new StackObjectPool<Object>();
-        try {
-            pool.borrowObject();
-            fail("Expected NoSuchElementException");
-        } catch(NoSuchElementException e) {
-            // expected
-        }
-        pool.setFactory(new SimpleFactory());
-        Object obj = pool.borrowObject();
-        assertNotNull(obj);
-        pool.returnObject(obj);
-    }
-
-    /**
-     * @deprecated - to be removed in pool 2.0
-     */
-    public void testCantResetFactoryWithActiveObjects() throws Exception {
-        ObjectPool<Object> pool = new StackObjectPool<Object>();
-        pool.setFactory(new SimpleFactory());
-        Object obj = pool.borrowObject();
-        assertNotNull(obj);
-
-        try {
-            pool.setFactory(new SimpleFactory());
-            fail("Expected IllegalStateException");
-        } catch(IllegalStateException e) {
-            // expected
-        }        
-    }
-    
-    /**
-     * @deprecated - to be removed in pool 2.0
-     */
-    public void testCanResetFactoryWithoutActiveObjects() throws Exception {
-        ObjectPool<Object> pool = new StackObjectPool<Object>();
-        {
-            pool.setFactory(new SimpleFactory());
-            Object obj = pool.borrowObject();        
-            assertNotNull(obj);
-            pool.returnObject(obj);
-        }
-        {
-            pool.setFactory(new SimpleFactory());
-            Object obj = pool.borrowObject();        
-            assertNotNull(obj);
-            pool.returnObject(obj);
-        }
-    }
-
-    /**
      * Verifies that validation failures when borrowing newly created instances
      * from the pool result in NoSuchElementExceptions and passivation failures
      * result in instances not being returned to the pool.
@@ -233,18 +139,6 @@ public class TestStackObjectPool extends
      
     public void testVariousConstructors() throws Exception {
         {
-            StackObjectPool<Integer> pool = new StackObjectPool<Integer>();
-            assertNotNull(pool);
-        }
-        {
-            StackObjectPool<Integer> pool = new StackObjectPool<Integer>(10);
-            assertNotNull(pool);
-        }
-        {
-            StackObjectPool<Integer> pool = new StackObjectPool<Integer>(10,5);
-            assertNotNull(pool);
-        }
-        {
             StackObjectPool<Integer> pool = new StackObjectPool<Integer>(null);
             assertNotNull(pool);
         }



Mime
View raw message