hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r545600 - in /jakarta/httpcomponents/httpcore/trunk: ./ module-nio/src/main/java/org/apache/http/impl/nio/ module-nio/src/main/java/org/apache/http/impl/nio/reactor/ module-nio/src/main/java/org/apache/http/nio/protocol/ module-nio/src/main...
Date Fri, 08 Jun 2007 19:23:23 GMT
Author: olegk
Date: Fri Jun  8 12:23:20 2007
New Revision: 545600

URL: http://svn.apache.org/viewvc?view=rev&rev=545600
Log:
HTTPCORE-78: Use heap bound ByteBufferAllocator for short-lived or variable in length (requiring
frequent content re-allocation) buffers

Contributed by Steffen Pingel <spingel at limewire.com>
Reviewed by Oleg Kalnichevski

Added:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java
  (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBuffer.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBuffer.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLClientIOEventDispatch.java
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLServerIOEventDispatch.java

Modified: jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Fri Jun  8 12:23:20 2007
@@ -2,6 +2,8 @@
 
 * [HTTPCORE-78]: Added ByteBufferAllocator interface that can be used to apply 
   different ByteArray allocation strategies to session and content buffers.
+  Use heap bound implementation for short-lived or variable in length (requiring 
+  frequent content re-allocation) buffers.
   Contributed by Steffen Pingel <spingel at limewire.com>
 
 * [HTTPCORE-77]: The result of CharsetDecoder#decode() and CharsetEncoder#encode() 

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIOEventDispatch.java
Fri Jun  8 12:23:20 2007
@@ -36,7 +36,7 @@
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.util.ByteBufferAllocator;
-import org.apache.http.nio.util.DirectByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
 public class DefaultClientIOEventDispatch implements IOEventDispatch {
@@ -69,7 +69,7 @@
     public DefaultClientIOEventDispatch(
             final NHttpClientHandler handler, 
             final HttpParams params) {
-        this(handler, new DirectByteBufferAllocator(), params);
+        this(handler, new HeapByteBufferAllocator(), params);
     }
     
     public void connected(final IOSession session) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIOEventDispatch.java
Fri Jun  8 12:23:20 2007
@@ -36,7 +36,7 @@
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.util.ByteBufferAllocator;
-import org.apache.http.nio.util.DirectByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
 public class DefaultServerIOEventDispatch implements IOEventDispatch {
@@ -69,7 +69,7 @@
     public DefaultServerIOEventDispatch(
             final NHttpServiceHandler handler, 
             final HttpParams params) {
-        this(handler, new DirectByteBufferAllocator(), params);
+        this(handler, new HeapByteBufferAllocator(), params);
     }
     
     public void connected(final IOSession session) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBuffer.java?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBuffer.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionInputBuffer.java
Fri Jun  8 12:23:20 2007
@@ -41,8 +41,8 @@
 import java.nio.charset.CoderResult;
 
 import org.apache.http.nio.util.ByteBufferAllocator;
-import org.apache.http.nio.util.DirectByteBufferAllocator;
 import org.apache.http.nio.util.ExpandableBuffer;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.HTTP;
@@ -62,7 +62,7 @@
     }
 
     public SessionInputBuffer(int buffersize, int linebuffersize) {
-        this(buffersize, linebuffersize, new DirectByteBufferAllocator());
+        this(buffersize, linebuffersize, new HeapByteBufferAllocator());
     }
     
     public void reset(final HttpParams params) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBuffer.java?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBuffer.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionOutputBuffer.java
Fri Jun  8 12:23:20 2007
@@ -41,8 +41,8 @@
 import java.nio.charset.CoderResult;
 
 import org.apache.http.nio.util.ByteBufferAllocator;
-import org.apache.http.nio.util.DirectByteBufferAllocator;
 import org.apache.http.nio.util.ExpandableBuffer;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.HTTP;
@@ -64,7 +64,7 @@
     }
 
     public SessionOutputBuffer(int buffersize, int linebuffersize) {
-        this(buffersize, linebuffersize, new DirectByteBufferAllocator());
+        this(buffersize, linebuffersize, new HeapByteBufferAllocator());
     }
 
     public void reset(final HttpParams params) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java
Fri Jun  8 12:23:20 2007
@@ -54,7 +54,7 @@
 import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.nio.util.ContentInputBuffer;
 import org.apache.http.nio.util.ContentOutputBuffer;
-import org.apache.http.nio.util.DirectByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.nio.util.SimpleInputBuffer;
 import org.apache.http.nio.util.SimpleOutputBuffer;
 import org.apache.http.params.HttpParams;
@@ -121,7 +121,7 @@
             final ConnectionReuseStrategy connStrategy,
             final HttpParams params) {
         this(httpProcessor, execHandler, connStrategy, 
-                new DirectByteBufferAllocator(), params);
+                new HeapByteBufferAllocator(), params);
     }
     
     public void setEventListener(final EventListener eventListener) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
Fri Jun  8 12:23:20 2007
@@ -57,7 +57,7 @@
 import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.nio.util.ContentInputBuffer;
 import org.apache.http.nio.util.ContentOutputBuffer;
-import org.apache.http.nio.util.DirectByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.nio.util.SimpleInputBuffer;
 import org.apache.http.nio.util.SimpleOutputBuffer;
 import org.apache.http.params.HttpParams;
@@ -129,7 +129,7 @@
             final ConnectionReuseStrategy connStrategy,
             final HttpParams params) {
         this(httpProcessor, responseFactory, connStrategy, 
-                new DirectByteBufferAllocator(), params);
+                new HeapByteBufferAllocator(), params);
     }
     
     public void setEventListener(final EventListener eventListener) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
Fri Jun  8 12:23:20 2007
@@ -98,8 +98,8 @@
     private final HttpProcessor httpProcessor;
     private final HttpResponseFactory responseFactory;
     private final ConnectionReuseStrategy connStrategy;
-    private final Executor executor;
     private final ByteBufferAllocator allocator;
+    private final Executor executor;
     private final HttpParams params;
 
     private HttpRequestHandlerResolver handlerResolver;
@@ -615,7 +615,10 @@
         private volatile HttpRequest request;
         private volatile HttpResponse response;
         
-        public ServerConnState(int bufsize, final IOControl ioControl, final ByteBufferAllocator
allocator) {
+        public ServerConnState(
+                int bufsize, 
+                final IOControl ioControl, 
+                final ByteBufferAllocator allocator) {
             super();
             this.inbuffer = new SharedInputBuffer(bufsize, ioControl, allocator);
             this.outbuffer = new SharedOutputBuffer(bufsize, ioControl, allocator);

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java?view=auto&rev=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java
Fri Jun  8 12:23:20 2007
@@ -0,0 +1,42 @@
+/*
+ * $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.nio.util;
+
+import java.nio.ByteBuffer;
+
+public class HeapByteBufferAllocator implements ByteBufferAllocator {
+
+    public ByteBuffer allocate(int size) {
+        return ByteBuffer.allocate(size);
+    }
+
+}

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

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

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

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
Fri Jun  8 12:23:20 2007
@@ -37,19 +37,17 @@
 import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
 
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.mockup.MockupDecoder;
 import org.apache.http.nio.mockup.MockupEncoder;
 import org.apache.http.nio.mockup.ReadableByteChannelMockup;
-import org.apache.http.nio.util.SimpleInputBuffer;
-import org.apache.http.nio.util.SimpleOutputBuffer;
 import org.apache.http.util.EncodingUtils;
 
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
 /**
  * Buffer tests.
  *
@@ -164,18 +162,26 @@
         assertEquals(0, buffer.capacity());
     }
 
-    public void testCustomByteBufferAllocator() {
-        ExpandableBuffer buffer = new ExpandableBuffer(1024, new ByteBufferAllocator() {
-            public ByteBuffer allocate(int size) {
-                return ByteBuffer.allocate(size);
-            }            
-        });
-        assertEquals(1024, buffer.capacity());
-        assertFalse(buffer.buffer.isDirect());
-        buffer.ensureCapacity(4000);
-        assertFalse(buffer.buffer.isDirect());
-        assertEquals(4000, buffer.capacity());
-        buffer.ensureCapacity(5000);
+    public void testHeapByteBufferAllocator() {
+        HeapByteBufferAllocator allocator = new HeapByteBufferAllocator();
+        ByteBuffer buffer = allocator.allocate(1);
+        assertNotNull(buffer);
+        assertFalse(buffer.isDirect());
+        assertEquals(0, buffer.position());
+        assertEquals(1, buffer.limit());
+        assertEquals(1, buffer.capacity());
+        
+        buffer = allocator.allocate(2048);
+        assertFalse(buffer.isDirect());
+        assertEquals(0, buffer.position());
+        assertEquals(2048, buffer.limit());
+        assertEquals(2048, buffer.capacity());
+        
+        buffer = allocator.allocate(0);
+        assertFalse(buffer.isDirect());
+        assertEquals(0, buffer.position());
+        assertEquals(0, buffer.limit());
+        assertEquals(0, buffer.capacity());
     }
     
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLClientIOEventDispatch.java?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLClientIOEventDispatch.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLClientIOEventDispatch.java
Fri Jun  8 12:23:20 2007
@@ -42,7 +42,7 @@
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.util.ByteBufferAllocator;
-import org.apache.http.nio.util.DirectByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
 public class SSLClientIOEventDispatch implements IOEventDispatch {
@@ -86,7 +86,7 @@
             final NHttpClientHandler handler,
             final SSLContext sslcontext,
             final HttpParams params) {
-        this(handler, sslcontext, null, new DirectByteBufferAllocator(), params);
+        this(handler, sslcontext, null, new HeapByteBufferAllocator(), params);
     }
     
     public void connected(final IOSession session) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLServerIOEventDispatch.java?view=diff&rev=545600&r1=545599&r2=545600
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLServerIOEventDispatch.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/main/java/org/apache/http/impl/nio/reactor/SSLServerIOEventDispatch.java
Fri Jun  8 12:23:20 2007
@@ -42,7 +42,7 @@
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.util.ByteBufferAllocator;
-import org.apache.http.nio.util.DirectByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
 public class SSLServerIOEventDispatch implements IOEventDispatch {
@@ -86,7 +86,7 @@
             final NHttpServiceHandler handler,
             final SSLContext sslcontext,
             final HttpParams params) {
-        this(handler, sslcontext, null, new DirectByteBufferAllocator(), params);
+        this(handler, sslcontext, null, new HeapByteBufferAllocator(), params);
     }
     
     public void connected(final IOSession session) {



Mime
View raw message