hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r536656 - in /jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http: ./ impl/ impl/io/ io/
Date Wed, 09 May 2007 21:15:15 GMT
Author: olegk
Date: Wed May  9 14:15:14 2007
New Revision: 536656

URL: http://svn.apache.org/viewvc?view=rev&rev=536656
Log:
HTTPCORE-21: 
* Added HttpTransportMetrics interface
* Changed abstract HTTP data receiver / transmitter to implement HttpTransportMetrics interface
* Added HttpConnectionMetrics interface and its default impl

Contributed by Andrea Selva <selva.andre at gmail.com>
Reviewed and committed with minor modifications by Oleg Kalnichevski

Added:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java
  (with props)
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java
  (with props)
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java
  (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java

Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java?view=auto&rev=536656
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java
Wed May  9 14:15:14 2007
@@ -0,0 +1,74 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http;
+
+/**
+ * This interface is the point to access the information about the status 
+ * of {@link HttpConnection}.
+ */
+public interface HttpConnectionMetrics {
+
+    /**
+     * Returns the number of requests transferred over the connection, 
+     * 0 if not available.
+     */ 
+    long getRequestCount();
+    
+    /**
+     * Returns the number of responses transferred over the connection, 
+     * 0 if not available.
+     */ 
+    long getResponseCount();
+    
+    /**
+     * Returns the number of bytes transferred over the connection, 
+     * 0 if not available.
+     */ 
+    long getSentBytesCount();
+    
+    /**
+     * Returns the number of bytes transferred over the connection, 
+     * 0 if not available.
+     */ 
+    long getReceivedBytesCount(); 
+    
+    /**
+     * Return the value for the specified metric.
+     *
+     *@param metricName the name of the metric to query.
+     *
+     *@return the object representing the metric requested,
+     *        <code>null</code> if the metric cannot not found.
+     */
+    Object getMetric(String metricName);
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java?view=auto&rev=536656
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java
Wed May  9 14:15:14 2007
@@ -0,0 +1,137 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl;
+
+import java.util.HashMap;
+import org.apache.http.HttpConnectionMetrics;
+
+/**
+ * Implementation of the metrics interface.
+ */
+public class HttpConnectionMetricsImpl implements HttpConnectionMetrics {
+    
+    public static final String REQUEST_COUNT = "http.request-count";
+    public static final String RESPONSE_COUNT = "http.response-count";
+    public static final String SENT_BYTES_COUNT = "http.sent-bytes-count";
+    public static final String RECEIVED_BYTES_COUNT = "http.received-bytes-count";
+    
+    private long requestCount = 0;
+    private long responseCount = 0;
+    private long sentBytesCount = 0;
+    private long receivedBytesCount = 0;
+    
+    /**
+     * The cache map for all metrics values.
+     */
+    private HashMap metricsCache;
+    
+    public HttpConnectionMetricsImpl() {
+        super();
+    }
+    
+    /* ------------------  Public interface method -------------------------- */
+
+    public long getRequestCount() {
+        return requestCount;
+    }
+    
+    public void setRequestCount(long count) {
+        requestCount = count;
+    }
+    
+    public void incrementRequestCount(long count) {
+        requestCount += count;
+    }
+    
+    public long getResponseCount() {
+        return responseCount;
+    }
+    
+    public void setResponseCount(long count) {
+        responseCount = count;
+    }
+    
+    public void incrementResponseCount(long count) {
+        responseCount += count;
+    }
+    
+    public long getSentBytesCount() {
+        return sentBytesCount;
+    }
+    
+    public void setSentBytesCount(long count) {
+        sentBytesCount = count;
+    }
+    
+    public void incrementSentBytesCount(long count) {
+        sentBytesCount += count;
+    }
+    
+    public long getReceivedBytesCount() {
+        return receivedBytesCount;
+    }
+    
+    public void setReceivedBytesCount(long count) {
+        receivedBytesCount = count;
+    }
+    
+    public void incrementReceivedBytesCount(long count) {
+        receivedBytesCount += count;
+    }
+    
+    public Object getMetric(final String metricName) {
+        Object value = null;
+        if (this.metricsCache != null) {
+            value = this.metricsCache.get(metricName);
+        }
+        if (value == null) {
+            if (REQUEST_COUNT.equals(metricName)) {
+                value = new Long(requestCount);
+            } else if (RESPONSE_COUNT.equals(metricName)) {
+                value = new Long(responseCount);
+            } else if (RECEIVED_BYTES_COUNT.equals(metricName)) {
+                value = new Long(receivedBytesCount);
+            } else if (SENT_BYTES_COUNT.equals(metricName)) {
+                value = new Long(sentBytesCount);
+            }
+        }
+        return value;
+    }
+    
+    public void setMetric(final String metricName, Object obj) {
+        if (this.metricsCache == null) {
+            this.metricsCache = new HashMap();
+        }
+        this.metricsCache.put(metricName, obj);
+    }
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java?view=diff&rev=536656&r1=536655&r2=536656
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
Wed May  9 14:15:14 2007
@@ -35,6 +35,7 @@
 import java.io.InputStream;
 
 import org.apache.http.io.HttpDataReceiver;
+import org.apache.http.io.HttpTransportMetrics;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
@@ -48,7 +49,8 @@
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
  */
-public abstract class AbstractHttpDataReceiver implements HttpDataReceiver {
+public abstract class AbstractHttpDataReceiver 
+    implements HttpDataReceiver, HttpTransportMetrics {
 
     private InputStream instream;
     private byte[] buffer;
@@ -61,6 +63,8 @@
     private boolean ascii = true;
     private int maxLineLen = -1;
     
+    private long bytesTransferred = 0;
+    
     protected void init(final InputStream instream, int buffersize) {
         if (instream == null) {
             throw new IllegalArgumentException("Input stream may not be null");
@@ -93,6 +97,7 @@
             return -1;
         } else {
             this.bufferlen = off + l;
+            this.bytesTransferred += l;
             return l;
         }
     }
@@ -256,6 +261,14 @@
         this.ascii = this.charset.equalsIgnoreCase(HTTP.US_ASCII)
                      || this.charset.equalsIgnoreCase(HTTP.ASCII);
         this.maxLineLen = params.getIntParameter(HttpConnectionParams.MAX_LINE_LENGTH, -1);
+    }
+    
+    public long getBytesTransferred() {
+        return this.bytesTransferred;
+    }
+    
+    public void resetCounts() {
+        this.bytesTransferred = 0;
     }
     
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java?view=diff&rev=536656&r1=536655&r2=536656
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
Wed May  9 14:15:14 2007
@@ -35,6 +35,7 @@
 import java.io.OutputStream;
 
 import org.apache.http.io.HttpDataTransmitter;
+import org.apache.http.io.HttpTransportMetrics;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.HTTP;
@@ -47,7 +48,8 @@
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
  */
-public abstract class AbstractHttpDataTransmitter implements HttpDataTransmitter {
+public abstract class AbstractHttpDataTransmitter 
+    implements HttpDataTransmitter, HttpTransportMetrics {
 
     private static final byte[] CRLF = new byte[] {HTTP.CR, HTTP.LF};
     
@@ -59,6 +61,8 @@
     private String charset = HTTP.US_ASCII;
     private boolean ascii = true;
     
+    private long bytesTransferred = 0;
+    
     protected void init(final OutputStream outstream, int buffersize) {
         if (outstream == null) {
             throw new IllegalArgumentException("Input stream may not be null");
@@ -73,6 +77,7 @@
     protected void flushBuffer() throws IOException {
         if (this.buffer.length() > 0) {
             this.outstream.write(this.buffer.buffer(), 0, this.buffer.length());
+            this.bytesTransferred += this.buffer.length();
             this.buffer.clear();
         }
     }
@@ -94,6 +99,7 @@
             flushBuffer();
             // write directly to the out stream
             this.outstream.write(b, off, len);
+            this.bytesTransferred += len;
         } else {
             // Do not let the buffer grow unnecessarily
             int freecapacity = this.buffer.capacity() - this.buffer.length();
@@ -162,6 +168,14 @@
         this.charset = HttpProtocolParams.getHttpElementCharset(params); 
         this.ascii = this.charset.equalsIgnoreCase(HTTP.US_ASCII)
                      || this.charset.equalsIgnoreCase(HTTP.ASCII);
+    }
+    
+    public long getBytesTransferred() {
+        return this.bytesTransferred;
+    }
+    
+    public void resetCounts() {
+        this.bytesTransferred = 0;
     }
     
 }

Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java?view=auto&rev=536656
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java
Wed May  9 14:15:14 2007
@@ -0,0 +1,46 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.io;
+
+public interface HttpTransportMetrics {
+    
+    /**
+     * Returns the number of bytes trasferred.
+     */
+    long getBytesTransferred(); 
+    
+    /**
+     * Resets the counts
+     */
+    void resetCounts();
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message