commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1102755 - /commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java
Date Fri, 13 May 2011 14:24:50 GMT
Author: psteitz
Date: Fri May 13 14:24:50 2011
New Revision: 1102755

URL: http://svn.apache.org/viewvc?rev=1102755&view=rev
Log:
Implemented equals, hashCode and toString.

Modified:
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java?rev=1102755&r1=1102754&r2=1102755&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java
(original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java
Fri May 13 14:24:50 2011
@@ -17,6 +17,8 @@
 
 package org.apache.commons.performance.pool;
 
+import java.util.concurrent.atomic.AtomicLong;
+
 /**
  * <p>Object created by {@link WaiterFactory}. Maintains active / valid state,
  * last passivated and idle times.  Waits with configurable latency when 
@@ -31,11 +33,18 @@ public class Waiter {
     private long lastPassivated = 0;
     private long lastIdleTimeMs = 0;
     
+    /** Next available ID */
+    private static AtomicLong nextId = new AtomicLong(0);
+    
+    /** Unique ID */
+    private final long id;
+    
     public Waiter(boolean active, boolean valid, long latency) {
         this.active = active;
         this.valid = valid;
         this.latency = latency;
         this.lastPassivated = System.currentTimeMillis();
+        this.id = nextId.getAndIncrement();
     }
 
     /**
@@ -129,4 +138,36 @@ public class Waiter {
         return lastIdleTimeMs;
     }
     
+    public boolean equals(Object obj) {
+        if (null == obj || !(obj instanceof Waiter)) {
+            return false;
+        }
+        if (obj == this) {
+            return true;
+        }
+        return ((Waiter) obj).id == this.id;
+    }
+    
+    public int hashCode() {
+        return Long.valueOf(id).hashCode();
+    }
+    
+    public String toString() {
+        StringBuffer buff = new StringBuffer("Waiter\n");
+        buff.append("ID: ");
+        buff.append(id);
+        buff.append("  Active: ");
+        buff.append(active);
+        buff.append("  Valid: ");
+        buff.append(valid);
+        buff.append(" Latency: ");
+        buff.append(latency);
+        buff.append("  Last Passivated: ");
+        buff.append(lastPassivated);
+        buff.append("  Last Idle Time: ");
+        buff.append(lastIdleTimeMs);
+        buff.append("\n");
+        return buff.toString();
+    }
+    
 }



Mime
View raw message