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 2011/04/24 22:05:44 UTC
svn commit: r1096366 -
/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/WaiterFactory.java
Author: simonetripodi
Date: Sun Apr 24 20:05:44 2011
New Revision: 1096366
URL: http://svn.apache.org/viewvc?rev=1096366&view=rev
Log:
added generics to WaiterFactory class
Modified:
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/WaiterFactory.java
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/WaiterFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/WaiterFactory.java?rev=1096366&r1=1096365&r2=1096366&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/WaiterFactory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/WaiterFactory.java Sun Apr 24 20:05:44 2011
@@ -32,8 +32,8 @@ import org.apache.commons.pool2.Poolable
* (per key) exceeds the configured max.
*
*/
-public class WaiterFactory implements PoolableObjectFactory,
-KeyedPoolableObjectFactory {
+public class WaiterFactory<K> implements PoolableObjectFactory<Waiter>,
+KeyedPoolableObjectFactory<K,Waiter> {
/** Latency of activateObject */
private final long activateLatency;
@@ -60,7 +60,7 @@ KeyedPoolableObjectFactory {
private long activeCount = 0;
/** Count of (makes - destroys) per key since last reset */
- private Map activeCounts = new HashMap();
+ private Map<K,Integer> activeCounts = new HashMap<K,Integer>();
/** Maximum of (makes - destroys) - if exceeded IllegalStateException */
private final long maxActive; // GKOP 1.x calls this maxTotal
@@ -97,22 +97,22 @@ KeyedPoolableObjectFactory {
validateLatency, waiterLatency, maxActive, Long.MAX_VALUE, 0);
}
- public void activateObject(Object obj) throws Exception {
+ public void activateObject(Waiter obj) throws Exception {
doWait(activateLatency);
- ((Waiter) obj).setActive(true);
+ obj.setActive(true);
}
- public void destroyObject(Object obj) throws Exception {
+ public void destroyObject(Waiter obj) throws Exception {
doWait(destroyLatency);
- ((Waiter) obj).setValid(false);
- ((Waiter) obj).setActive(false);
+ obj.setValid(false);
+ obj.setActive(false);
// Decrement *after* destroy
synchronized (this) {
activeCount--;
}
}
- public Object makeObject() throws Exception {
+ public Waiter makeObject() throws Exception {
// Increment and test *before* make
synchronized (this) {
if (activeCount >= maxActive) {
@@ -126,17 +126,17 @@ KeyedPoolableObjectFactory {
return new Waiter(false, true, waiterLatency);
}
- public void passivateObject(Object arg0) throws Exception {
- ((Waiter) arg0).setActive(false);
+ public void passivateObject(Waiter arg0) throws Exception {
+ arg0.setActive(false);
doWait(passivateLatency);
if (Math.random() < passivateInvalidationProbability) {
- ((Waiter) arg0).setValid(false);
+ arg0.setValid(false);
}
}
- public boolean validateObject(Object arg0) {
+ public boolean validateObject(Waiter arg0) {
doWait(validateLatency);
- return ((Waiter) arg0).isValid();
+ return arg0.isValid();
}
protected void doWait(long latency) {
@@ -152,9 +152,9 @@ KeyedPoolableObjectFactory {
if (activeCounts.isEmpty()) {
return;
}
- Iterator it = activeCounts.keySet().iterator();
+ Iterator<K> it = activeCounts.keySet().iterator();
while (it.hasNext()) {
- Object key = it.next();
+ K key = it.next();
activeCounts.put(key, new Integer (0));
}
}
@@ -168,21 +168,21 @@ KeyedPoolableObjectFactory {
// KeyedPoolableObjectFactory methods
- public void activateObject(Object key, Object obj) throws Exception {
+ public void activateObject(K key, Waiter obj) throws Exception {
activateObject(obj);
}
- public void destroyObject(Object key, Object obj) throws Exception {
+ public void destroyObject(K key, Waiter obj) throws Exception {
destroyObject(obj);
synchronized (this) {
- Integer count = (Integer) activeCounts.get(key);
+ Integer count = activeCounts.get(key);
activeCounts.put(key, new Integer(count.intValue() - 1));
}
}
- public Object makeObject(Object key) throws Exception {
+ public Waiter makeObject(K key) throws Exception {
synchronized (this) {
- Integer count = (Integer) activeCounts.get(key);
+ Integer count = activeCounts.get(key);
if (count == null) {
count = new Integer(1);
activeCounts.put(key, count);
@@ -200,11 +200,11 @@ KeyedPoolableObjectFactory {
return makeObject();
}
- public void passivateObject(Object key, Object obj) throws Exception {
+ public void passivateObject(K key, Waiter obj) throws Exception {
passivateObject(obj);
}
- public boolean validateObject(Object key, Object obj) {
+ public boolean validateObject(K key, Waiter obj) {
return validateObject(obj);
}