hc-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?view=rev&rev=536667
Log:
HTTPCORE-21: 
* Some minor API enhancements based on the original patch contributed by Andrea Selva

Added:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpTransportMetricsImpl.java
  (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java
    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
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataReceiver.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataTransmitter.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java

Modified: 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=diff&rev=536667&r1=536666&r2=536667
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpConnectionMetrics.java
Wed May  9 14:48:41 2007
@@ -71,4 +71,10 @@
      */
     Object getMetric(String metricName);
     
+    /**
+     * Resets the counts
+     *
+     */
+    void reset();
+    
 }

Modified: 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=diff&rev=536667&r1=536666&r2=536667
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/HttpConnectionMetricsImpl.java
Wed May  9 14:48:41 2007
@@ -134,4 +134,12 @@
         this.metricsCache.put(metricName, obj);
     }
     
+    public void reset() {
+        requestCount = 0;
+        responseCount = 0;
+        sentBytesCount = 0;
+        receivedBytesCount = 0;
+        this.metricsCache = null;
+    }
+    
 }

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=536667&r1=536666&r2=536667
==============================================================================
--- 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:48:41 2007
@@ -49,8 +49,7 @@
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
  */
-public abstract class AbstractHttpDataReceiver 
-    implements HttpDataReceiver, HttpTransportMetrics {
+public abstract class AbstractHttpDataReceiver implements HttpDataReceiver {
 
     private InputStream instream;
     private byte[] buffer;
@@ -63,7 +62,7 @@
     private boolean ascii = true;
     private int maxLineLen = -1;
     
-    private long bytesTransferred = 0;
+    private HttpTransportMetricsImpl metrics;
     
     protected void init(final InputStream instream, int buffersize) {
         if (instream == null) {
@@ -77,6 +76,7 @@
         this.bufferpos = 0;
         this.bufferlen = 0;
         this.linebuffer = new ByteArrayBuffer(buffersize);
+        this.metrics = new HttpTransportMetricsImpl();
     }
     
     protected int fillBuffer() throws IOException {
@@ -97,7 +97,7 @@
             return -1;
         } else {
             this.bufferlen = off + l;
-            this.bytesTransferred += l;
+            this.metrics.incrementBytesTransferred(l);
             return l;
         }
     }
@@ -262,13 +262,9 @@
                      || 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;
+
+    public HttpTransportMetrics getMetrics() {
+        return this.metrics;
     }
     
 }

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=536667&r1=536666&r2=536667
==============================================================================
--- 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:48:41 2007
@@ -48,8 +48,7 @@
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
  */
-public abstract class AbstractHttpDataTransmitter 
-    implements HttpDataTransmitter, HttpTransportMetrics {
+public abstract class AbstractHttpDataTransmitter implements HttpDataTransmitter {
 
     private static final byte[] CRLF = new byte[] {HTTP.CR, HTTP.LF};
     
@@ -61,7 +60,7 @@
     private String charset = HTTP.US_ASCII;
     private boolean ascii = true;
     
-    private long bytesTransferred = 0;
+    private HttpTransportMetricsImpl metrics;
     
     protected void init(final OutputStream outstream, int buffersize) {
         if (outstream == null) {
@@ -72,13 +71,15 @@
         }
         this.outstream = outstream;
         this.buffer = new ByteArrayBuffer(buffersize);
+        this.metrics = new HttpTransportMetricsImpl();
     }
     
     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();
+        int len = this.buffer.length();
+        if (len > 0) {
+            this.outstream.write(this.buffer.buffer(), 0, len);
             this.buffer.clear();
+            this.metrics.incrementBytesTransferred(len);
         }
     }
     
@@ -99,7 +100,7 @@
             flushBuffer();
             // write directly to the out stream
             this.outstream.write(b, off, len);
-            this.bytesTransferred += len;
+            this.metrics.incrementBytesTransferred(len);
         } else {
             // Do not let the buffer grow unnecessarily
             int freecapacity = this.buffer.capacity() - this.buffer.length();
@@ -169,13 +170,9 @@
         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;
+
+    public HttpTransportMetrics getMetrics() {
+        return this.metrics;
     }
     
 }

Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpTransportMetricsImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpTransportMetricsImpl.java?view=auto&rev=536667
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpTransportMetricsImpl.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpTransportMetricsImpl.java
Wed May  9 14:48:41 2007
@@ -0,0 +1,64 @@
+/*
+ * $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.io;
+
+import org.apache.http.io.HttpTransportMetrics;
+
+/**
+ * This interface is the point to access the information about the status 
+ * of {@link HttpDataReceiver} or {@link HttpDataTransmitter}.
+ */
+public class HttpTransportMetricsImpl implements HttpTransportMetrics {
+
+    private long bytesTransferred = 0;
+    
+    public HttpTransportMetricsImpl() {
+        super();
+    }
+    
+    public long getBytesTransferred() {
+        return this.bytesTransferred;
+    }
+
+    public void setBytesTransferred(long count) {
+        this.bytesTransferred = count;
+    }
+
+    public void incrementBytesTransferred(long count) {
+        this.bytesTransferred += count;
+    }
+
+    public void reset() {
+        this.bytesTransferred = 0;
+    }
+    
+}

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

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

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

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataReceiver.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataReceiver.java?view=diff&rev=536667&r1=536666&r2=536667
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataReceiver.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataReceiver.java
Wed May  9 14:48:41 2007
@@ -63,4 +63,6 @@
     
     boolean isDataAvailable(int timeout) throws IOException; 
 
+    HttpTransportMetrics getMetrics();
+    
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataTransmitter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataTransmitter.java?view=diff&rev=536667&r1=536666&r2=536667
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataTransmitter.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataTransmitter.java
Wed May  9 14:48:41 2007
@@ -63,4 +63,6 @@
     
     void flush() throws IOException;
     
+    HttpTransportMetrics getMetrics();
+    
 }

Modified: 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=diff&rev=536667&r1=536666&r2=536667
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpTransportMetrics.java
Wed May  9 14:48:41 2007
@@ -41,6 +41,6 @@
     /**
      * Resets the counts
      */
-    void resetCounts();
+    void reset();
     
 }



Mime
View raw message