geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r615192 - in /geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc: codec/HttpIoHandler.java util/TimeMonitor.java
Date Fri, 25 Jan 2008 11:58:46 GMT
Author: rickmcguire
Date: Fri Jan 25 03:58:44 2008
New Revision: 615192

URL: http://svn.apache.org/viewvc?rev=615192&view=rev
Log:
GERONIMO-3761 Committed revision 614952.

Patch provided by Sangjin Lee. 


Modified:
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/TimeMonitor.java

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java?rev=615192&r1=615191&r2=615192&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
Fri Jan 25 03:58:44 2008
@@ -241,8 +241,6 @@
         ResponseFuture result = request.getResponseFuture();
         result.setException(throwable);
 
-        // notify any interesting parties that this is starting 
-        client.notifyMonitoringListeners(MonitoringEvent.CONNECTION_CLOSED_BY_SERVER, request);

         //Exception is bad, so just close it up
         ioSession.close();
     }

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/TimeMonitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/TimeMonitor.java?rev=615192&r1=615191&r2=615192&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/TimeMonitor.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/TimeMonitor.java Fri
Jan 25 03:58:44 2008
@@ -23,14 +23,18 @@
 import java.util.concurrent.atomic.AtomicLong;
 
 /**
- * Simple monitoring listener for tracking average 
- * request times. 
+ * Simple monitoring listener for tracking average request times and average
+ * connect times.  This is provided mainly to illustrate how one can collect 
+ * timing data. 
  */
 public final class TimeMonitor extends CountingMonitor {
-	private final AtomicInteger requestCount = new AtomicInteger();
-	private final AtomicLong requestTimes = new AtomicLong();
+    private final AtomicInteger requestCount = new AtomicInteger();
+    private final AtomicLong requestTimes = new AtomicLong();
+    
+    private final AtomicInteger connectCount = new AtomicInteger();
+    private final AtomicLong connectTimes = new AtomicLong();
 
-	@Override
+    @Override
     /**
      * Process a notification event.  If this is a 
      * REQUEST_COMPLETED event, the request timeing 
@@ -39,17 +43,22 @@
      * 
      * @param event  The notification event.
      */
-	public void notification(MonitoringEvent event) {
-		super.notification(event);
-		// get the response time
-		int type = event.getType();
-		if (type == MonitoringEvent.REQUEST_COMPLETED) {
-			requestCount.incrementAndGet();
-			long elapsed = event.getTimeStamp() - event.getRequest().getRequestStartTime();
-			requestTimes.addAndGet(elapsed);
-		}
-	}
-	
+    public void notification(MonitoringEvent event) {
+        super.notification(event);
+        
+        // get the response time
+        int type = event.getType();
+        if (type == MonitoringEvent.REQUEST_COMPLETED) {
+            requestCount.incrementAndGet();
+            long elapsed = event.getTimeStamp() - event.getRequest().getRequestStartTime();
+            requestTimes.addAndGet(elapsed);
+        } else if (type == MonitoringEvent.CONNECTION_SUCCESSFUL) {
+            connectCount.incrementAndGet();
+            long elapsed = event.getTimeStamp() - event.getRequest().getConnectStartTime();
+            connectTimes.addAndGet(elapsed);
+        }
+    }
+    
     /**
      * Return the average calculated response time for 
      * the processed requests. 
@@ -57,10 +66,25 @@
      * @return The average response time, in milliseconds, for 
      *         all recorded completed requests.
      */
-	public long getAverageResponseTime() {
-		if (requestCount.get() == 0) {
-			return 0L;
-		}
-		return requestTimes.get()/requestCount.get();
-	}
+    public long getAverageResponseTime() {
+        if (requestCount.get() == 0) {
+            return 0L;
+        }
+        return requestTimes.get()/requestCount.get();
+    }
+    
+    
+    /**
+     * Return the average calculated connect time for 
+     * the processed requests. 
+     * 
+     * @return The average connect time, in milliseconds, for 
+     *         all recorded completed requests.
+     */
+    public long getAverageConnectTime() {
+        if (connectCount.get() == 0) {
+            return 0L;
+        }
+        return connectTimes.get()/connectCount.get();
+    }
 }



Mime
View raw message