You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2010/10/12 20:02:46 UTC

svn commit: r1021865 - in /commons/proper/pool/trunk/src: java/org/apache/commons/pool/impl/StackKeyedObjectPool.java test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java

Author: simonetripodi
Date: Tue Oct 12 18:02:46 2010
New Revision: 1021865

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

Modified:
    commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
    commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java

Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java?rev=1021865&r1=1021864&r2=1021865&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackKeyedObjectPool.java Tue Oct 12 18:02:46 2010
@@ -17,17 +17,16 @@
 
 package org.apache.commons.pool.impl;
 
-import org.apache.commons.pool.BaseKeyedObjectPool;
-import org.apache.commons.pool.KeyedObjectPool;
-import org.apache.commons.pool.KeyedPoolableObjectFactory;
-import org.apache.commons.pool.PoolUtils;
-
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Stack;
 
+import org.apache.commons.pool.BaseKeyedObjectPool;
+import org.apache.commons.pool.KeyedObjectPool;
+import org.apache.commons.pool.KeyedPoolableObjectFactory;
+import org.apache.commons.pool.PoolUtils;
+
 /**
  * A simple, <code>Stack</code>-based <code>KeyedObjectPool</code> implementation.
  * <p>
@@ -520,7 +519,7 @@ public class StackKeyedObjectPool<K,V> e
      * @return map of keyed pools
      * @since 1.5.5
      */
-    public Map<K,Stack<V>> getPools() {
+    public synchronized Map<K,Stack<V>> getPools() {
         return _pools;
     }
 
@@ -528,29 +527,39 @@ public class StackKeyedObjectPool<K,V> e
      * @return the cap on the number of "sleeping" instances in <code>each</code> pool.
      * @since 1.5.5
      */
-    public int getMaxSleeping() {
+    public synchronized int getMaxSleeping() {
         return _maxSleeping;
     }
 
     /**
+     * Sets the cap on the number of "sleeping" instances in <code>each</code> pool.
+     *
+     * @param maxSleeping
+     * @since 2.0
+     */
+    public synchronized void setMaxSleeping(int maxSleeping) {
+        _maxSleeping = maxSleeping;
+    }
+
+    /**
      * @return the initial capacity of each pool.
      * @since 1.5.5
      */
-    public int getInitSleepingCapacity() {
+    public synchronized int getInitSleepingCapacity() {
         return _initSleepingCapacity;
     }
 
     /**
      * @return the _totActive
      */
-    public int getTotActive() {
+    public synchronized int getTotActive() {
         return _totActive;
     }
 
     /**
      * @return the _totIdle
      */
-    public int getTotIdle() {
+    public synchronized int getTotIdle() {
         return _totIdle;
     }
 
@@ -558,7 +567,7 @@ public class StackKeyedObjectPool<K,V> e
      * @return the _activeCount
      * @since 1.5.5
      */
-    public Map<K,Integer> getActiveCount() {
+    public synchronized Map<K,Integer> getActiveCount() {
         return _activeCount;
     }
 
@@ -575,44 +584,37 @@ public class StackKeyedObjectPool<K,V> e
 
     /**
      *  My named-set of pools.
-     *  @deprecated to be removed in pool 2.0.  Use {@link #getPools()}
      */
-    protected HashMap<K,Stack<V>> _pools = null;
+    private HashMap<K,Stack<V>> _pools = null;
 
     /**
      * My {@link KeyedPoolableObjectFactory}.
-     * @deprecated to be removed in pool 2.0.  Use {@link #getFactory()}
      */
-    protected KeyedPoolableObjectFactory<K,V> _factory = null;
+    private final KeyedPoolableObjectFactory<K,V> _factory;
 
     /**
      *  The cap on the number of "sleeping" instances in <code>each</code> pool.
-     *  @deprecated to be removed in pool 2.0.  Use {@link #getMaxSleeping()}
      */
-    protected int _maxSleeping = DEFAULT_MAX_SLEEPING;
+    private int _maxSleeping = DEFAULT_MAX_SLEEPING;
 
     /**
      * The initial capacity of each pool.
-     * @deprecated to be removed in pool 2.0.  Use {@link #getInitSleepingCapacity()}.
      */
-    protected int _initSleepingCapacity = DEFAULT_INIT_SLEEPING_CAPACITY;
+    private int _initSleepingCapacity = DEFAULT_INIT_SLEEPING_CAPACITY;
 
     /**
      * Total number of object borrowed and not yet returned for all pools.
-     * @deprecated to be removed in pool 2.0.  Use {@link #getTotActive()}.
      */
-    protected int _totActive = 0;
+    private int _totActive = 0;
 
     /**
-     * Total number of objects "sleeping" for all pools
-     * @deprecated to be removed in pool 2.0.  Use {@link #getTotIdle()}.
+     * Total number of objects "sleeping" for all pools.
      */
-    protected int _totIdle = 0;
+    private int _totIdle = 0;
 
     /**
-     * Number of active objects borrowed and not yet returned by pool
-     * @deprecated to be removed in pool 2.0.  Use {@link #getActiveCount()}.
+     * Number of active objects borrowed and not yet returned by pool.
      */
-    protected HashMap<K,Integer> _activeCount = null;
+    private HashMap<K,Integer> _activeCount = null;
 
 }

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java?rev=1021865&r1=1021864&r2=1021865&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java Tue Oct 12 18:02:46 2010
@@ -123,7 +123,7 @@ public class TestStackKeyedObjectPool ex
      * returning instance, which is pushed onto the idle object stack.
      */
     public void testRemoveOldest() throws Exception {
-        pool._maxSleeping = 2;
+        pool.setMaxSleeping(2);
         String obj0 = pool.borrowObject("");
         String obj1 = pool.borrowObject("");
         String obj2 = pool.borrowObject("");
@@ -161,18 +161,6 @@ public class TestStackKeyedObjectPool ex
 
     public void testVariousConstructors() throws Exception {
         {
-            StackKeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>();
-            assertNotNull(pool);
-        }
-        {
-            StackKeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>(10);
-            assertNotNull(pool);
-        }
-        {
-            StackKeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>(10,5);
-            assertNotNull(pool);
-        }
-        {
             StackKeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>(null);
             assertNotNull(pool);
         }