Author: psteitz
Date: Sun Jan 13 20:11:28 2008
New Revision: 611706
URL: http://svn.apache.org/viewvc?rev=611706&view=rev
Log:
Added support for keyed, stack, softReference pools.
Modified:
commons/sandbox/performance/trunk/config-pool.xml
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/PoolSoakTest.java
Modified: commons/sandbox/performance/trunk/config-pool.xml
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/config-pool.xml?rev=611706&r1=611705&r2=611706&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/config-pool.xml (original)
+++ commons/sandbox/performance/trunk/config-pool.xml Sun Jan 13 20:11:28 2008
@@ -31,7 +31,8 @@
</factory>
<pool>
- <!-- GenericObjectPool or AbandonedObjectPool -->
+ <!-- GenericObjectPool, AbandonedObjectPool, GenericKeyedObjectPool
+ StackObjectPool, StackKeyedObjectPool, SoftReferenceObjectPool -->
<type>GenericObjectPool</type>
<max-active>15</max-active>
<max-idle>15</max-idle>
@@ -45,6 +46,9 @@
<tests-per-eviction>3</tests-per-eviction>
<idle-timeout>-1</idle-timeout>
<test-while-idle>false</test-while-idle>
+ <lifo>false</lifo>
+ <!-- Ignored unless pool type a KeyedObjectPool -->
+ <max-active-per-key>10</max-active-per-key>
</pool>
<!-- Ignored unless pool type is AbandonedObjectPool -->
Modified:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java?rev=611706&r1=611705&r2=611706&view=diff
==============================================================================
---
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
(original)
+++
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
Sun Jan 13 20:11:28 2008
@@ -17,11 +17,15 @@
package org.apache.commons.performance.pool;
+import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.KeyedObjectPool;
import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.math.random.RandomData;
+import org.apache.commons.math.random.RandomDataImpl;
import org.apache.commons.performance.ClientThread;
/**
@@ -33,9 +37,13 @@
public class PoolClientThread extends ClientThread {
private ObjectPool pool;
+ private KeyedObjectPool keyedPool;
+ private boolean keyed;
+ private List<Integer> keys;
+ private RandomData randomData;
/**
- * Create a pool client thread.
+ * Create a pool client thread for an ObjectPool.
*
* @param iterations number of iterations
* @param minDelay minimum mean time between client requests
@@ -48,6 +56,7 @@
* @param rampType type of ramp (linear or random jumps)
* @param logger common logger shared by all clients
* @param statsList List of SummaryStatistics to add results to
+ * @param pool ObjectPool
*/
public PoolClientThread(long iterations, long minDelay, long maxDelay,
double sigma, String delayType, long rampPeriod, long peakPeriod,
@@ -58,13 +67,53 @@
peakPeriod, troughPeriod, cycleType,rampType, logger,
statsList);
this.pool = pool;
+ this.keyed = false;
+ }
+
+ /**
+ * Create a pool client thread for a KeyedObjectPool.
+ *
+ * @param iterations number of iterations
+ * @param minDelay minimum mean time between client requests
+ * @param maxDelay maximum mean time between client requests
+ * @param delayType distribution of time between client requests
+ * @param rampPeriod ramp period of cycle for cyclic load
+ * @param peakPeriod peak period of cycle for cyclic load
+ * @param troughPeriod trough period of cycle for cyclic load
+ * @param cycleType type of cycle for mean delay
+ * @param rampType type of ramp (linear or random jumps)
+ * @param logger common logger shared by all clients
+ * @param statsList List of SummaryStatistics to add results to
+ * @param keyedPool KeyedObjectPool
+ */
+ public PoolClientThread(long iterations, long minDelay, long maxDelay,
+ double sigma, String delayType, long rampPeriod, long peakPeriod,
+ long troughPeriod, String cycleType, String rampType, Logger
logger,
+ List <SummaryStatistics> statsList, KeyedObjectPool keyedPool) {
+
+ super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
+ peakPeriod, troughPeriod, cycleType,rampType, logger,
+ statsList);
+ this.keyedPool = keyedPool;
+ this.keyed = true;
+ keys = new ArrayList<Integer>();
+ for (int i = 0; i < 20; i++) { //TODO: make number of keys configurable
+ keys.add(new Integer(i));
+ }
+ randomData = new RandomDataImpl();
}
/** Borrow and return */
public void execute() throws Exception {
- Waiter waiter = (Waiter) pool.borrowObject();
- waiter.doWait();
- pool.returnObject(waiter);
+ if (keyed) {
+ Integer key = keys.get(randomData.nextInt(0, 19));
+ Waiter waiter = (Waiter) keyedPool.borrowObject(key);
+ waiter.doWait();
+ keyedPool.returnObject(key, waiter);
+ } else {
+ Waiter waiter = (Waiter) pool.borrowObject();
+ waiter.doWait();
+ pool.returnObject(waiter);
+ }
}
-
}
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=611706&r1=611705&r2=611706&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 Jan 13 20:11:28 2008
@@ -22,7 +22,13 @@
import org.apache.commons.dbcp.AbandonedConfig;
import org.apache.commons.dbcp.AbandonedObjectPool;
import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.KeyedObjectPool;
import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.pool.impl.StackObjectPool;
+import org.apache.commons.pool.impl.SoftReferenceObjectPool;
+import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+import org.apache.commons.pool.impl.StackKeyedObjectPool;
import org.apache.commons.performance.ConfigurationException;
import org.apache.commons.performance.ClientThread;
import org.apache.commons.performance.LoadGenerator;
@@ -35,10 +41,17 @@
*/
public class PoolSoak extends LoadGenerator {
+ // Pool instances
+ private GenericObjectPool genericObjectPool;
+ private GenericKeyedObjectPool genericKeyedObjectPool;
+ private StackObjectPool stackObjectPool;
+ private SoftReferenceObjectPool softReferenceObjectPool;
+ private StackKeyedObjectPool stackKeyedObjectPool;
+
// Pool properties
private String poolType;
- private GenericObjectPool pool;
- private int maxActive;
+ private int maxActive; // maxActive for GOP, maxTotal for GKOP
+ private int maxActivePerKey; // maxActive for GKOP
private int maxIdle;
private int minIdle;
private long maxWait;
@@ -50,6 +63,7 @@
private long idleTimeout;
private boolean testWhileIdle;
private AbandonedConfig abandonedConfig = new AbandonedConfig();
+ private boolean lifo;
// WaiterFactory properties
private long activateLatency;
@@ -80,31 +94,35 @@
digester.addCallParam(
"configuration/factory/waiter-latency", 5);
digester.addCallMethod("configuration/pool",
- "configurePool", 12);
+ "configurePool", 14);
digester.addCallParam(
"configuration/pool/max-active", 0);
digester.addCallParam(
- "configuration/pool/max-idle", 1);
+ "configuration/pool/max-active-per-key", 1);
+ digester.addCallParam(
+ "configuration/pool/max-idle", 2);
digester.addCallParam(
- "configuration/pool/min-idle", 2);
+ "configuration/pool/min-idle", 3);
digester.addCallParam(
- "configuration/pool/max-wait", 3);
+ "configuration/pool/max-wait", 4);
digester.addCallParam(
- "configuration/pool/exhausted-action", 4);
+ "configuration/pool/exhausted-action", 5);
digester.addCallParam(
- "configuration/pool/test-on-borrow", 5);
+ "configuration/pool/test-on-borrow", 6);
digester.addCallParam(
- "configuration/pool/test-on-return", 6);
+ "configuration/pool/test-on-return", 7);
digester.addCallParam(
- "configuration/pool/time-between-evictions", 7);
+ "configuration/pool/time-between-evictions", 8);
digester.addCallParam(
- "configuration/pool/tests-per-eviction", 8);
+ "configuration/pool/tests-per-eviction", 9);
digester.addCallParam(
- "configuration/pool/idle-timeout", 9);
+ "configuration/pool/idle-timeout", 10);
digester.addCallParam(
- "configuration/pool/test-while-idle", 10);
+ "configuration/pool/test-while-idle", 11);
digester.addCallParam(
- "configuration/pool/type", 11);
+ "configuration/pool/lifo", 12);
+ digester.addCallParam(
+ "configuration/pool/type", 13);
digester.addCallMethod("configuration/abandoned-config",
"configureAbandonedConfig", 3);
digester.addCallParam(
@@ -122,46 +140,96 @@
* Create object pool and factory
*/
protected void init() throws Exception {
+ // Create factory
+ WaiterFactory factory = new WaiterFactory(activateLatency,
destroyLatency,
+ makeLatency, passivateLatency, validateLatency, waiterLatency,
+ maxActive, maxActivePerKey);
+
// Create object pool
if (poolType.equals("GenericObjectPool")) {
- pool = new GenericObjectPool(
- null, maxActive, exhaustedAction,
- maxWait, maxIdle, minIdle, testOnBorrow, testOnReturn,
- timeBetweenEvictions, testsPerEviction, idleTimeout,
- testWhileIdle);
+ genericObjectPool = new GenericObjectPool();
+ genericObjectPool = new AbandonedObjectPool(null,abandonedConfig);
+ genericObjectPool.setMaxActive(maxActive);
+ genericObjectPool.setWhenExhaustedAction(exhaustedAction);
+ genericObjectPool.setMaxWait(maxWait);
+ genericObjectPool.setMaxIdle(maxIdle);
+ genericObjectPool.setMinIdle(minIdle);
+ genericObjectPool.setTestOnBorrow(testOnBorrow);
+ genericObjectPool.setTestOnReturn(testOnReturn);
+ genericObjectPool.setTimeBetweenEvictionRunsMillis(
+ timeBetweenEvictions);
+ genericObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
+ genericObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
+ genericObjectPool.setTestWhileIdle(testWhileIdle);
+ genericObjectPool.setLifo(lifo);
+ genericObjectPool.setFactory(factory);
} else if (poolType.equals("AbandonedObjectPool")) {
- pool = new AbandonedObjectPool(null,abandonedConfig);
- pool.setMaxActive(maxActive);
- pool.setWhenExhaustedAction(exhaustedAction);
- pool.setMaxWait(maxWait);
- pool.setMaxIdle(maxIdle);
- pool.setMinIdle(minIdle);
- pool.setTestOnBorrow(testOnBorrow);
- pool.setTestOnReturn(testOnReturn);
- pool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictions);
- pool.setNumTestsPerEvictionRun(testsPerEviction);
- pool.setMinEvictableIdleTimeMillis(idleTimeout);
- pool.setTestWhileIdle(testWhileIdle);
+ genericObjectPool = new AbandonedObjectPool(null,abandonedConfig);
+ genericObjectPool.setMaxActive(maxActive);
+ genericObjectPool.setWhenExhaustedAction(exhaustedAction);
+ genericObjectPool.setMaxWait(maxWait);
+ genericObjectPool.setMaxIdle(maxIdle);
+ genericObjectPool.setMinIdle(minIdle);
+ genericObjectPool.setTestOnBorrow(testOnBorrow);
+ genericObjectPool.setTestOnReturn(testOnReturn);
+ genericObjectPool.setTimeBetweenEvictionRunsMillis(
+ timeBetweenEvictions);
+ genericObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
+ genericObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
+ genericObjectPool.setTestWhileIdle(testWhileIdle);
+ genericObjectPool.setLifo(lifo);
+ genericObjectPool.setFactory(factory);
+ } else if (poolType.equals("GenericKeyedObjectPool")) {
+ genericKeyedObjectPool = new GenericKeyedObjectPool();
+ genericKeyedObjectPool.setMaxActive(maxActivePerKey);
+ genericKeyedObjectPool.setMaxTotal(maxActive);
+ genericKeyedObjectPool.setWhenExhaustedAction(exhaustedAction);
+ genericKeyedObjectPool.setMaxWait(maxWait);
+ genericKeyedObjectPool.setMaxIdle(maxIdle);
+ genericKeyedObjectPool.setMinIdle(minIdle);
+ genericKeyedObjectPool.setTestOnBorrow(testOnBorrow);
+ genericKeyedObjectPool.setTestOnReturn(testOnReturn);
+ genericKeyedObjectPool.setTimeBetweenEvictionRunsMillis(
+ timeBetweenEvictions);
+ genericKeyedObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
+ genericKeyedObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
+ genericKeyedObjectPool.setTestWhileIdle(testWhileIdle);
+ genericKeyedObjectPool.setLifo(lifo);
+ genericKeyedObjectPool.setFactory(factory);
+ } else if (poolType.equals("StackObjectPool")) {
+ stackObjectPool = new StackObjectPool();
+ stackObjectPool.setFactory(factory);
+ } else if (poolType.equals("SoftReferenceObjectPool")) {
+ softReferenceObjectPool = new SoftReferenceObjectPool();
+ softReferenceObjectPool.setFactory(factory);
+ } else if (poolType.equals("StackKeyedObjectPool")) {
+ stackKeyedObjectPool = new StackKeyedObjectPool();
+ stackKeyedObjectPool.setFactory(factory);
} else {
throw new ConfigurationException(
"invalid pool type configuration: " + poolType);
}
- // Create factory
- pool.setFactory(new WaiterFactory(activateLatency, destroyLatency,
- makeLatency, passivateLatency, validateLatency, waiterLatency,
- maxActive));
logger.info("Initialized pool with properties: ");
- logger.info(" exhaustedAction: " + pool.getWhenExhaustedAction());
- logger.info(" maxActive: " + pool.getMaxActive());
- logger.info(" maxIdle: " + pool.getMaxIdle());
- logger.info(" minIdle: " + pool.getMinIdle());
- logger.info(" testOnBorrow: " + pool.getTestOnBorrow());
- logger.info(" testWhileIdle: " + pool.getTestWhileIdle());
- logger.info(" timeBetweenEvictions: " +
pool.getTimeBetweenEvictionRunsMillis());
- logger.info(" testsPerEviction: " + pool.getNumTestsPerEvictionRun());
- logger.info(" idleTimeout: " + pool.getMinEvictableIdleTimeMillis());
-
+ logger.info(" poolTypeT: " + poolType);
+ logger.info(" exhaustedAction: " + exhaustedAction);
+ logger.info(" maxActive: " + maxActive);
+ logger.info(" maxActivePerKey: " + maxActivePerKey);
+ logger.info(" maxIdle: " + maxIdle);
+ logger.info(" minIdle: " + minIdle);
+ logger.info(" testOnBorrow: " + testOnBorrow);
+ logger.info(" testWhileIdle: " + testWhileIdle);
+ logger.info(" timeBetweenEvictions: " + timeBetweenEvictions);
+ logger.info(" testsPerEviction: " + testsPerEviction);
+ logger.info(" idleTimeout: " + idleTimeout);
+ logger.info(" lifo: " + lifo);
+ logger.info(" abandonedConfig: ");
+ logger.info(" logAbandoned: " +
+ abandonedConfig.getLogAbandoned());
+ logger.info(" removeAbandoned: " +
+ abandonedConfig.getRemoveAbandoned());
+ logger.info(" abandonedTimeout: " +
+ abandonedConfig.getRemoveAbandonedTimeout());
}
/**
@@ -172,9 +240,36 @@
long peakPeriod, long troughPeriod, String cycleType,
String rampType, Logger logger,
List <SummaryStatistics> statsList) {
- return new PoolClientThread(iterations, minDelay, maxDelay,
- sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
- cycleType, rampType, logger, statsList, pool);
+ if (poolType.equals("GenercObjectPool")) {
+ return new PoolClientThread(iterations, minDelay, maxDelay,
+ sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+ cycleType, rampType, logger, statsList, genericObjectPool);
+ }
+ if (poolType.equals("GenericKeyedObjectPool")) {
+ return new PoolClientThread(iterations, minDelay, maxDelay,
+ sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+ cycleType, rampType, logger, statsList,
+ genericKeyedObjectPool);
+ }
+ if (poolType.equals("StackKeyedObjectPool")) {
+ return new PoolClientThread(iterations, minDelay, maxDelay,
+ sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+ cycleType, rampType, logger, statsList,
+ stackKeyedObjectPool);
+ }
+ if (poolType.equals("StackObjectPool")) {
+ return new PoolClientThread(iterations, minDelay, maxDelay,
+ sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+ cycleType, rampType, logger, statsList,
+ stackObjectPool);
+ }
+ if (poolType.equals("SoftReferenceObjectPool")) {
+ return new PoolClientThread(iterations, minDelay, maxDelay,
+ sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+ cycleType, rampType, logger, statsList,
+ softReferenceObjectPool);
+ }
+ return null;
}
// ------------------------------------------------------------------------
@@ -193,12 +288,15 @@
this.waiterLatency = Long.parseLong(waiterLatency);
}
- public void configurePool(String maxActive, String maxIdle, String minIdle,
- String maxWait, String exhaustedAction, String testOnBorrow,
+ public void configurePool(String maxActive, String maxActivePerKey,
+ String maxIdle, String minIdle, String maxWait,
+ String exhaustedAction, String testOnBorrow,
String testOnReturn, String timeBetweenEvictions,
String testsPerEviction, String idleTimeout,
- String testWhileIdle, String type) throws ConfigurationException {
+ String testWhileIdle, String lifo, String type)
+ throws ConfigurationException {
this.maxActive = Integer.parseInt(maxActive);
+ this.maxActivePerKey = Integer.parseInt(maxActivePerKey);
this.maxIdle = Integer.parseInt(maxIdle);
this.minIdle = Integer.parseInt(minIdle);
this.maxWait = Long.parseLong(maxWait);
@@ -208,6 +306,7 @@
this.testsPerEviction = Integer.parseInt(testsPerEviction);
this.idleTimeout = Long.parseLong(idleTimeout);
this.testWhileIdle = Boolean.parseBoolean(testWhileIdle);
+ this.lifo = Boolean.parseBoolean(lifo);
this.poolType = type;
if (exhaustedAction.equals("block")) {
this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
@@ -231,8 +330,13 @@
Integer.parseInt(abandonedTimeout));
}
- public GenericObjectPool getPool() {
- return pool;
+ // Pool getters for unit tests
+ protected GenericObjectPool getGenericObjectPool() {
+ return genericObjectPool;
+ }
+
+ protected GenericKeyedObjectPool getGenericKeyedObjectPool() {
+ return genericKeyedObjectPool;
}
}
Modified:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java?rev=611706&r1=611705&r2=611706&view=diff
==============================================================================
---
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
(original)
+++
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
Sun Jan 13 20:11:28 2008
@@ -17,16 +17,22 @@
package org.apache.commons.performance.pool;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Iterator;
import java.util.logging.Logger;
import java.util.logging.Level;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.KeyedPoolableObjectFactory;
/**
* Object factory with configurable latencies for object lifecycle methods.
*
*/
-public class WaiterFactory implements PoolableObjectFactory {
+public class WaiterFactory implements PoolableObjectFactory,
+KeyedPoolableObjectFactory {
// TODO: implement protected getters so these can be stochastic
private long activateLatency = 0;
@@ -39,15 +45,22 @@
/** Count of (makes - destroys) since last reset */
private long activeCount = 0;
+ /** Count of (makes - destroys) per key since last reset */
+ private Map<Object, AtomicInteger> activeCounts =
+ new HashMap<Object, AtomicInteger>();
+
/** Maximum of (makes - destroys) - if exceeded IllegalStateException */
private long maxActive = Long.MAX_VALUE;
+ /** Maximum of (makes - destroys) per key */
+ private long maxActivePerKey = Long.MAX_VALUE;
+
protected static final Logger logger =
Logger.getLogger(WaiterFactory.class.getName());
public WaiterFactory(long activateLatency, long destroyLatency,
long makeLatency, long passivateLatency, long validateLatency,
- long waiterLatency,long maxActive) {
+ long waiterLatency,long maxActive, long maxActivePerKey) {
this.activateLatency = activateLatency;
this.destroyLatency = destroyLatency;
this.makeLatency = makeLatency;
@@ -55,13 +68,21 @@
this.validateLatency = validateLatency;
this.waiterLatency = waiterLatency;
this.maxActive = maxActive;
+ this.maxActivePerKey = maxActivePerKey;
}
public WaiterFactory(long activateLatency, long destroyLatency,
long makeLatency, long passivateLatency, long validateLatency,
long waiterLatency) {
this(activateLatency, destroyLatency, makeLatency, passivateLatency,
- validateLatency, waiterLatency, Long.MAX_VALUE);
+ validateLatency, waiterLatency, Long.MAX_VALUE,
Long.MAX_VALUE);
+ }
+
+ public WaiterFactory(long activateLatency, long destroyLatency,
+ long makeLatency, long passivateLatency, long validateLatency,
+ long waiterLatency,long maxActive) {
+ this(activateLatency, destroyLatency, makeLatency, passivateLatency,
+ validateLatency, waiterLatency, maxActive, Long.MAX_VALUE);
}
public void activateObject(Object arg0) throws Exception {
@@ -126,6 +147,13 @@
public synchronized void reset() {
activeCount = 0;
+ if (activeCounts.isEmpty()) {
+ return;
+ }
+ Iterator it = activeCounts.keySet().iterator();
+ while (it.hasNext()) {
+ ((AtomicInteger) activeCounts.get(it.next())).getAndSet(0);
+ }
}
/**
@@ -140,6 +168,45 @@
*/
public synchronized void setMaxActive(long maxActive) {
this.maxActive = maxActive;
+ }
+
+ // KeyedPoolableObjectFactory methods
+
+ public void activateObject(Object key, Object obj) throws Exception {
+ activateObject(obj);
+ }
+
+ public void destroyObject(Object key, Object obj) throws Exception {
+ destroyObject(obj);
+ ((AtomicInteger) activeCounts.get(key)).getAndDecrement();
+ }
+
+ public Object makeObject(Object key) throws Exception {
+ synchronized (this) {
+ AtomicInteger count = (AtomicInteger) activeCounts.get(key);
+ if (count == null) {
+ count = new AtomicInteger(1);
+ activeCounts.put(key, count);
+ } else {
+ if (count.get() >= maxActivePerKey) {
+ throw new IllegalStateException("Too many active " +
+ "instances for key = " + key + ": " + count.get() +
+ " in circulation " + "with maxActivePerKey = " +
+ maxActivePerKey);
+ } else {
+ count.incrementAndGet();
+ }
+ }
+ }
+ return makeObject();
+ }
+
+ public void passivateObject(Object key, Object obj) throws Exception {
+ passivateObject(obj);
+ }
+
+ public boolean validateObject(Object key, Object obj) {
+ return validateObject(obj);
}
}
Modified:
commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/PoolSoakTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/PoolSoakTest.java?rev=611706&r1=611705&r2=611706&view=diff
==============================================================================
---
commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/PoolSoakTest.java
(original)
+++
commons/sandbox/performance/trunk/src/test/org/apache/commons/performance/pool/PoolSoakTest.java
Sun Jan 13 20:11:28 2008
@@ -65,7 +65,7 @@
**/
poolSoak.getDigester().parse(getInputStream("config-pool.xml"));
poolSoak.init();
- GenericObjectPool pool = poolSoak.getPool();
+ GenericObjectPool pool = poolSoak.getGenericObjectPool();
assertEquals(15, pool.getMaxActive());
assertEquals(15, pool.getMaxIdle());
assertEquals(10, pool.getMinIdle());
@@ -108,7 +108,7 @@
*/
poolSoak.getDigester().parse(getInputStream("config-abandoned.xml"));
poolSoak.init();
- AbandonedObjectPool pool = (AbandonedObjectPool) poolSoak.getPool();
+ AbandonedObjectPool pool = (AbandonedObjectPool)
poolSoak.getGenericObjectPool();
assertEquals(15, pool.getMaxActive());
assertEquals(-1, pool.getMaxIdle());
assertEquals(0, pool.getMinIdle());