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 19:08:54 UTC
svn commit: r1021844 - in /commons/proper/pool/trunk/src:
java/org/apache/commons/pool/impl/StackObjectPoolFactory.java
test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
Author: simonetripodi
Date: Tue Oct 12 17:08:54 2010
New Revision: 1021844
URL: http://svn.apache.org/viewvc?rev=1021844&view=rev
Log:
fixed generics
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/StackObjectPoolFactory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
Modified: commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPoolFactory.java?rev=1021844&r1=1021843&r2=1021844&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/java/org/apache/commons/pool/impl/StackObjectPoolFactory.java Tue Oct 12 17:08:54 2010
@@ -31,42 +31,7 @@ import org.apache.commons.pool.PoolableO
* @version $Revision$ $Date$
* @since Pool 1.0
*/
-public class StackObjectPoolFactory<T> implements ObjectPoolFactory<T> {
- /**
- * Create a new StackObjectPoolFactory.
- *
- * @see StackObjectPool#StackObjectPool()
- * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory)}
- */
- public StackObjectPoolFactory() {
- this((PoolableObjectFactory<T>)null,StackObjectPool.DEFAULT_MAX_SLEEPING,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
- }
-
- /**
- * Create a new StackObjectPoolFactory.
- *
- * @param maxIdle cap on the number of "sleeping" instances in the pool.
- * @see StackObjectPool#StackObjectPool(int)
- * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory, int)}
- */
- public StackObjectPoolFactory(int maxIdle) {
- this((PoolableObjectFactory<T>)null,maxIdle,StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
- }
-
- /**
- * Create a new StackObjectPoolFactory.
- *
- * @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#StackObjectPool(int, int)
- * @deprecated to be removed in pool 2.0 - use {@link #StackObjectPoolFactory(PoolableObjectFactory, int, int)}
- */
- public StackObjectPoolFactory(int maxIdle, int initIdleCapacity) {
- this((PoolableObjectFactory<T>)null,maxIdle,initIdleCapacity);
- }
-
- /**
+public class StackObjectPoolFactory<T> implements ObjectPoolFactory<T> {/**
* Create a new StackObjectPoolFactory.
*
* @param factory the PoolableObjectFactory used by created pools.
@@ -106,26 +71,23 @@ 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(_factory,_maxSleeping,_initCapacity);
+ return new StackObjectPool<T>(_factory,_maxSleeping,_initCapacity);
}
/**
* The PoolableObjectFactory used by created pools.
- * @deprecated to be made private in pool 2.0
*/
- protected PoolableObjectFactory<T> _factory = null;
+ private final PoolableObjectFactory<T> _factory;
/**
* The maximum number of idle instances in created pools.
- * @deprecated to be made private in pool 2.0
*/
- protected int _maxSleeping = StackObjectPool.DEFAULT_MAX_SLEEPING;
+ private int _maxSleeping = StackObjectPool.DEFAULT_MAX_SLEEPING;
/**
* The initial size of created pools.
- * @deprecated to be made private in pool 2.0
*/
- protected int _initCapacity = StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY;
+ private int _initCapacity = StackObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY;
/**
* Returns the factory used by created pools.
@@ -133,7 +95,7 @@ public class StackObjectPoolFactory<T> i
* @return the PoolableObjectFactory used by created pools
* @since 1.5.5
*/
- public PoolableObjectFactory<T> getFactory() {
+ public synchronized PoolableObjectFactory<T> getFactory() {
return _factory;
}
@@ -143,17 +105,27 @@ public class StackObjectPoolFactory<T> i
* @return the maximum number of idle instances in created pools
* @since 1.5.5
*/
- public int getMaxSleeping() {
+ public synchronized int getMaxSleeping() {
return _maxSleeping;
}
/**
+ * Sets the maxIdle setting for created pools.
+ *
+ * @param maxSleeping
+ * @since 2.0
+ */
+ public synchronized void setMaxSleeping(int maxSleeping) {
+ _maxSleeping = maxSleeping;
+ }
+
+ /**
* Returns the initial capacity of created pools.
*
* @return size of created containers (created pools are not pre-populated)
* @since 1.5.5
*/
- public int getInitCapacity() {
+ public synchronized int getInitCapacity() {
return _initCapacity;
}
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java?rev=1021844&r1=1021843&r2=1021844&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java Tue Oct 12 17:08:54 2010
@@ -18,6 +18,7 @@
package org.apache.commons.pool.impl;
import org.apache.commons.pool.MethodCallPoolableObjectFactory;
+import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.ObjectPoolFactory;
import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool.TestObjectPoolFactory;
@@ -39,22 +40,8 @@ public class TestStackObjectPoolFactory
}
public void testConstructors() throws Exception {
- StackObjectPoolFactory<Object> factory = new StackObjectPoolFactory<Object>();
- factory.createPool().close();
-
-
- factory = new StackObjectPoolFactory<Object>(1);
- StackObjectPool<Object> pool = (StackObjectPool<Object>)factory.createPool();
- pool.close();
-
-
- factory = new StackObjectPoolFactory<Object>(1, 1);
- pool = (StackObjectPool<Object>)factory.createPool();
- pool.close();
-
-
- factory = new StackObjectPoolFactory<Object>(new MethodCallPoolableObjectFactory(), 1);
- pool = (StackObjectPool<Object>)factory.createPool();
+ StackObjectPoolFactory<Object> factory = new StackObjectPoolFactory<Object>(new MethodCallPoolableObjectFactory(), 1);
+ ObjectPool<Object> pool = factory.createPool();
Object a = pool.borrowObject();
Object b = pool.borrowObject();
pool.returnObject(a);