commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r608292 - in /commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool: PoolSoak.java WaiterFactory.java
Date Thu, 03 Jan 2008 00:30:05 GMT
Author: psteitz
Date: Wed Jan  2 16:30:03 2008
New Revision: 608292

URL: http://svn.apache.org/viewvc?rev=608292&view=rev
Log:
Modified WaiterFactory to keep track of makes - destroys and enforce limit.

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=608292&r1=608291&r2=608292&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
Wed Jan  2 16:30:03 2008
@@ -149,7 +149,8 @@
         
         // Create factory
         pool.setFactory(new WaiterFactory(activateLatency, destroyLatency,
-                makeLatency, passivateLatency, validateLatency, waiterLatency)); 
+                makeLatency, passivateLatency, validateLatency, waiterLatency,
+                maxActive)); 
         logger.info("Initialized pool with properties: ");
         logger.info(" exhaustedAction: " + pool.getWhenExhaustedAction());
         logger.info(" maxActive: " + pool.getMaxActive());

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=608292&r1=608291&r2=608292&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
Wed Jan  2 16:30:03 2008
@@ -36,18 +36,32 @@
     private long validateLatency = 0;
     private long waiterLatency = 0;
     
+    /** Count of (makes - destroys) since last reset */
+    private long activeCount = 0;
+    
+    /** Maximum of (makes - destroys) - if exceeded IllegalStateException */
+    private long maxActive = 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 waiterLatency,long maxActive) {
         this.activateLatency = activateLatency;
         this.destroyLatency = destroyLatency;
         this.makeLatency = makeLatency;
         this.passivateLatency = passivateLatency;
         this.validateLatency = validateLatency;
         this.waiterLatency = waiterLatency;
+        this.maxActive = maxActive;
+    }
+    
+    public WaiterFactory(long activateLatency, long destroyLatency,
+            long makeLatency, long passivateLatency, long validateLatency,
+            long waiterLatency) {
+        this(activateLatency, destroyLatency, makeLatency, passivateLatency,
+                validateLatency, waiterLatency, Long.MAX_VALUE);
     }
 
     public void activateObject(Object arg0) throws Exception {
@@ -63,9 +77,22 @@
         }
         doWait(destroyLatency);
         ((Waiter) arg0).setValid(false);
+        // Decrement *after* destroy 
+        synchronized (this) {
+            activeCount--;
+        }
     }
 
     public Object makeObject() throws Exception {
+        // Increment and test *before* make
+        synchronized (this) {
+            if (activeCount >= maxActive) {
+                throw new IllegalStateException("Too many active instances: " +
+                activeCount + " in circulation with maxActive = " + maxActive);
+            } else {
+                activeCount++;
+            }
+        }
         if (logger.isLoggable(Level.FINE)) {
             logger.fine("makeObject");
         }
@@ -95,6 +122,24 @@
         } catch (InterruptedException ex) {
             // ignore
         }
+    }
+    
+    public synchronized void reset() {
+        activeCount = 0;
+    }
+
+    /**
+     * @return the maxActive
+     */
+    public synchronized long getMaxActive() {
+        return maxActive;
+    }
+
+    /**
+     * @param maxActive the maxActive to set
+     */
+    public synchronized void setMaxActive(long maxActive) {
+        this.maxActive = maxActive;
     }
 
 }



Mime
View raw message