commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1052754 - in /commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool: PoolSoak.java WaiterFactory.java
Date Sat, 25 Dec 2010 05:34:53 GMT
Author: psteitz
Date: Sat Dec 25 05:34:52 2010
New Revision: 1052754

URL: http://svn.apache.org/viewvc?rev=1052754&view=rev
Log:
Added passivateInvalidationProbability config property (instances will 'go bad' with this
probability on passivation).  Made WaiterFactory config fields final.

Modified:
    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

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=1052754&r1=1052753&r2=1052754&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
Sat Dec 25 05:34:52 2010
@@ -70,6 +70,7 @@ public class PoolSoak extends LoadGenera
     private long passivateLatency;
     private long validateLatency;
     private long waiterLatency;
+    private double passivateInvalidationProbability;
     
     /**
      * Add pool configuration to parameters loaded by super.
@@ -78,7 +79,7 @@ public class PoolSoak extends LoadGenera
     protected void configure() throws Exception {
         super.configure();
         digester.addCallMethod("configuration/factory", 
-                "configureFactory", 6);
+                "configureFactory", 7);
         digester.addCallParam(
                 "configuration/factory/activate-latency", 0);
         digester.addCallParam(
@@ -90,7 +91,9 @@ public class PoolSoak extends LoadGenera
         digester.addCallParam(
                 "configuration/factory/validate-latency", 4);
         digester.addCallParam(
-                "configuration/factory/waiter-latency", 5);   
+                "configuration/factory/waiter-latency", 5); 
+        digester.addCallParam(
+                "configuration/factory/passivate-invalidation-probability", 6);    
         digester.addCallMethod("configuration/pool", 
                 "configurePool", 15);
         digester.addCallParam(
@@ -143,7 +146,7 @@ public class PoolSoak extends LoadGenera
         // Create factory
         WaiterFactory factory = new WaiterFactory(activateLatency, destroyLatency,
                 makeLatency, passivateLatency, validateLatency, waiterLatency,
-                maxActive, maxActivePerKey); 
+                maxActive, maxActivePerKey, passivateInvalidationProbability); 
         
         // Create object pool
         if (poolType.equals("GenericObjectPool")) {
@@ -278,7 +281,7 @@ public class PoolSoak extends LoadGenera
     // ------------------------------------------------------------------------       
     public void configureFactory(String activateLatency, String destroyLatency,
             String makeLatency, String passivateLatency, String validateLatency,
-            String waiterLatency) {
+            String waiterLatency, String passivateInvalidationProbability) {
        
         this.activateLatency = Long.parseLong(activateLatency);
         this.destroyLatency = Long.parseLong(destroyLatency);
@@ -286,6 +289,8 @@ public class PoolSoak extends LoadGenera
         this.passivateLatency = Long.parseLong(passivateLatency);
         this.validateLatency = Long.parseLong(validateLatency);
         this.waiterLatency = Long.parseLong(waiterLatency);
+        this.passivateInvalidationProbability = 
+            Double.parseDouble(passivateInvalidationProbability);
     }
     
     public void configurePool(String maxActive, String maxActivePerKey,

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=1052754&r1=1052753&r2=1052754&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
Sat Dec 25 05:34:52 2010
@@ -35,12 +35,13 @@ public class WaiterFactory implements Po
 KeyedPoolableObjectFactory {
     
     // TODO: implement protected getters so these can be stochastic
-    private long activateLatency = 0;
-    private long destroyLatency = 0;
-    private long makeLatency = 0;
-    private long passivateLatency = 0;
-    private long validateLatency = 0;
-    private long waiterLatency = 0;
+    private final long activateLatency;
+    private final long destroyLatency;
+    private final long makeLatency;
+    private final long passivateLatency;
+    private final long validateLatency;
+    private final long waiterLatency;
+    private final double passivateInvalidationProbability;
     
     /** Count of (makes - destroys) since last reset */
     private long activeCount = 0;
@@ -50,17 +51,18 @@ KeyedPoolableObjectFactory {
         new HashMap<Object, AtomicInteger>();
     
     /** Maximum of (makes - destroys) - if exceeded IllegalStateException */
-    private long maxActive = Long.MAX_VALUE;
+    private final long maxActive;
     
     /** Maximum of (makes - destroys) per key */
-    private long maxActivePerKey = Long.MAX_VALUE;
+    private final long maxActivePerKey;
     
     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 maxActivePerKey) {
+            long waiterLatency,long maxActive, long maxActivePerKey,
+            double passivateInvalidationProbability) {
         this.activateLatency = activateLatency;
         this.destroyLatency = destroyLatency;
         this.makeLatency = makeLatency;
@@ -69,20 +71,21 @@ KeyedPoolableObjectFactory {
         this.waiterLatency = waiterLatency;
         this.maxActive = maxActive;
         this.maxActivePerKey = maxActivePerKey;
+        this.passivateInvalidationProbability = passivateInvalidationProbability;
     }
     
     public WaiterFactory(long activateLatency, long destroyLatency,
             long makeLatency, long passivateLatency, long validateLatency,
             long waiterLatency) {
         this(activateLatency, destroyLatency, makeLatency, passivateLatency,
-                validateLatency, waiterLatency, Long.MAX_VALUE, Long.MAX_VALUE);
+                validateLatency, waiterLatency, Long.MAX_VALUE, Long.MAX_VALUE, 0);
     }
     
     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);
+                validateLatency, waiterLatency, maxActive, Long.MAX_VALUE, 0);
     }
 
     public void activateObject(Object obj) throws Exception {
@@ -129,6 +132,9 @@ KeyedPoolableObjectFactory {
         }
         ((Waiter) arg0).setActive(false);
         doWait(passivateLatency);
+        if (Math.random() < passivateInvalidationProbability) {
+            ((Waiter) arg0).setValid(false);
+        }
     }
 
     public boolean validateObject(Object arg0) {
@@ -165,13 +171,6 @@ KeyedPoolableObjectFactory {
         return maxActive;
     }
 
-    /**
-     * @param maxActive the maxActive to set
-     */
-    public synchronized void setMaxActive(long maxActive) {
-        this.maxActive = maxActive;
-    }
-
     // KeyedPoolableObjectFactory methods
     
     public void activateObject(Object key, Object obj) throws Exception {
@@ -180,7 +179,9 @@ KeyedPoolableObjectFactory {
 
     public void destroyObject(Object key, Object obj) throws Exception {
         destroyObject(obj);
-        ((AtomicInteger) activeCounts.get(key)).getAndDecrement(); 
+        synchronized (this) {
+            ((AtomicInteger) activeCounts.get(key)).getAndDecrement(); 
+        }
     }
 
     public Object makeObject(Object key) throws Exception {



Mime
View raw message