You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2012/07/15 17:26:10 UTC
svn commit: r1361715 -
/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
Author: psteitz
Date: Sun Jul 15 15:26:10 2012
New Revision: 1361715
URL: http://svn.apache.org/viewvc?rev=1361715&view=rev
Log:
Updated to new pool2 API.
Modified:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java?rev=1361715&r1=1361714&r2=1361715&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java (original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java Sun Jul 15 15:26:10 2012
@@ -27,7 +27,8 @@ import org.apache.commons.performance.Co
import org.apache.commons.performance.ClientThread;
import org.apache.commons.performance.LoadGenerator;
import org.apache.commons.performance.Statistics;
-import org.apache.commons.pool2.impl.WhenExhaustedAction;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
/**
* Configurable load / performance tester for commons pool.
@@ -170,21 +171,23 @@ public class PoolSoak extends LoadGenera
genericObjectPool.setTestWhileIdle(testWhileIdle);
genericObjectPool.setLifo(lifo);
} else if (poolType.equals("GenericObjectPool2")) {
- genericObjectPool2 = new org.apache.commons.pool2.impl.GenericObjectPool<Waiter>();
- genericObjectPool2.setFactory(factory2);
- genericObjectPool2.setMaxTotal(maxActive);
- genericObjectPool2.setWhenExhaustedAction(mapExhaustedAction(exhaustedAction));
- genericObjectPool2.setMaxWait(maxWait);
- genericObjectPool2.setMaxIdle(maxIdle);
- genericObjectPool2.setMinIdle(minIdle);
- genericObjectPool2.setTestOnBorrow(testOnBorrow);
- genericObjectPool2.setTestOnReturn(testOnReturn);
- genericObjectPool2.setTimeBetweenEvictionRunsMillis(
- timeBetweenEvictions);
- genericObjectPool2.setNumTestsPerEvictionRun(testsPerEviction);
- genericObjectPool2.setMinEvictableIdleTimeMillis(idleTimeout);
- genericObjectPool2.setTestWhileIdle(testWhileIdle);
- genericObjectPool2.setLifo(lifo);
+ GenericObjectPoolConfig config = new GenericObjectPoolConfig();
+ config.setBlockWhenExhausted(
+ exhaustedAction == org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_BLOCK ?
+ true : false);
+ config.setMaxIdle(maxIdle);
+ config.setMinIdle(minIdle);
+ config.setMaxWaitMillis(maxWait);
+ config.setTestOnBorrow(testOnBorrow);
+ config.setTestWhileIdle(testWhileIdle);
+ config.setTestOnReturn(testOnReturn);
+ config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictions);
+ config.setNumTestsPerEvictionRun(testsPerEviction);
+ config.setMinEvictableIdleTimeMillis(idleTimeout);
+ config.setLifo(lifo);
+ config.setMaxTotal(maxActive);
+ genericObjectPool2 =
+ new org.apache.commons.pool2.impl.GenericObjectPool<Waiter>(factory2, config);
} else if (poolType.equals("AbandonedObjectPool")) {
genericObjectPool = new AbandonedObjectPool(factory,abandonedConfig);
genericObjectPool.setMaxActive(maxActive);
@@ -217,23 +220,24 @@ public class PoolSoak extends LoadGenera
genericKeyedObjectPool.setTestWhileIdle(testWhileIdle);
genericKeyedObjectPool.setLifo(lifo);
} else if (poolType.equals("GenericKeyedObjectPool2")) {
+ GenericKeyedObjectPoolConfig config = new GenericKeyedObjectPoolConfig();
+ config.setMaxTotal(maxActive);
+ config.setMaxTotalPerKey(maxActivePerKey);
+ config.setBlockWhenExhausted(
+ exhaustedAction == org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_BLOCK ?
+ true : false);
+ config.setMaxWaitMillis(maxWait);
+ config.setMaxIdlePerKey(maxIdle);
+ config.setMinIdlePerKey(minIdle);
+ config.setTestOnBorrow(testOnBorrow);
+ config.setTestOnReturn(testOnReturn);
+ config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictions);
+ config.setNumTestsPerEvictionRun(testsPerEviction);
+ config.setMinEvictableIdleTimeMillis(idleTimeout);
+ config.setTestWhileIdle(testWhileIdle);
+ config.setLifo(lifo);
genericKeyedObjectPool2 =
- new org.apache.commons.pool2.impl.GenericKeyedObjectPool<Integer, Waiter>();
- genericKeyedObjectPool2.setFactory(factory2);
- genericKeyedObjectPool2.setMaxTotalPerKey(maxActivePerKey);
- genericKeyedObjectPool2.setMaxTotal(maxActive);
- genericKeyedObjectPool2.setWhenExhaustedAction(mapExhaustedAction(exhaustedAction));
- genericKeyedObjectPool2.setMaxWait(maxWait);
- genericKeyedObjectPool2.setMaxIdlePerKey(maxIdle);
- genericKeyedObjectPool2.setMinIdlePerKey(minIdle);
- genericKeyedObjectPool2.setTestOnBorrow(testOnBorrow);
- genericKeyedObjectPool2.setTestOnReturn(testOnReturn);
- genericKeyedObjectPool2.setTimeBetweenEvictionRunsMillis(
- timeBetweenEvictions);
- genericKeyedObjectPool2.setNumTestsPerEvictionRun(testsPerEviction);
- genericKeyedObjectPool2.setMinEvictableIdleTimeMillis(idleTimeout);
- genericKeyedObjectPool2.setTestWhileIdle(testWhileIdle);
- genericKeyedObjectPool2.setLifo(lifo);
+ new org.apache.commons.pool2.impl.GenericKeyedObjectPool<Integer, Waiter>(factory2, config);
} else if (poolType.equals("StackObjectPool")) {
stackObjectPool = new StackObjectPool(factory);
} else if (poolType.equals("SoftReferenceObjectPool")) {
@@ -249,22 +253,6 @@ public class PoolSoak extends LoadGenera
}
/**
- * Maps version 1.x byte-coded whenExhaustedAction config to 2.0 enum
- * @param action 1.x-style specification
- * @return 2.0 enum value
- */
- private WhenExhaustedAction mapExhaustedAction(byte action) {
- switch (action) {
- case org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_BLOCK:
- return WhenExhaustedAction.BLOCK;
- case org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_FAIL:
- return WhenExhaustedAction.FAIL;
- default:
- throw new IllegalArgumentException("Invalid whenExhaustedAction");
- }
- }
-
- /**
* Close object pool
*/
protected void cleanUp() throws Exception {