hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r544950 - in /jakarta/httpcomponents/httpcore/trunk: ./ contrib/src/main/java/org/apache/http/contrib/logging/ 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...
Date Wed, 06 Jun 2007 20:58:48 GMT
Author: olegk
Date: Wed Jun  6 13:58:46 2007
New Revision: 544950

URL: http://svn.apache.org/viewvc?view=rev&rev=544950
Log:
HTTPCORE-78: Added ByteBufferAllocator interface that can be used to apply different ByteArray allocation strategies to session and content 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/ByteBufferAllocator.java   (with props)
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java   (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
    jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java
    jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
    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/DefaultNHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.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/NHttpConnectionBase.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/main/java/org/apache/http/nio/util/ExpandableBuffer.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SharedInputBuffer.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SimpleOutputBuffer.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/util/TestBuffers.java
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/examples/org/apache/http/examples/nio/NHttpSSLServer.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=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Wed Jun  6 13:58:46 2007
@@ -1,5 +1,9 @@
 Changes since 4.0 Alpha 4
 
+* [HTTPCORE-78]: Added ByteBufferAllocator interface that can be used to apply 
+  different ByteArray allocation strategies to session and content buffers.
+  Contributed by Steffen Pingel <spingel at limewire.com>
+
 * [HTTPCORE-77]: The result of CharsetDecoder#decode() and CharsetEncoder#encode() 
   was not checked for errors resulting in an infinite loop in 
   SessionInputBuffer#readLine() and SessionOutputBuffer#writeLine() 

Modified: jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java Wed Jun  6 13:58:46 2007
@@ -35,6 +35,8 @@
 import org.apache.http.nio.NHttpClientHandler;
 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.params.HttpParams;
 
 public class LoggingClientIOEventDispatch implements IOEventDispatch {
@@ -42,9 +44,13 @@
     private static final String NHTTP_CONN = "NHTTP_CONN";
     
     private final NHttpClientHandler handler;
+    private final ByteBufferAllocator allocator;
     private final HttpParams params;
     
-    public LoggingClientIOEventDispatch(final NHttpClientHandler handler, final HttpParams params) {
+    public LoggingClientIOEventDispatch(
+            final NHttpClientHandler handler, 
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
         super();
         if (handler == null) {
             throw new IllegalArgumentException("HTTP client handler may not be null");
@@ -52,14 +58,25 @@
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
         this.handler = new LoggingNHttpClientHandler(handler);
+        this.allocator = allocator;
         this.params = params;
     }
     
+    public LoggingClientIOEventDispatch(
+            final NHttpClientHandler handler, 
+            final HttpParams params) {
+        this(handler, new DirectByteBufferAllocator(), params);
+    }
+    
     public void connected(final IOSession session) {
         LoggingNHttpClientConnection conn = new LoggingNHttpClientConnection(
                 new LoggingIOSession(session), 
                 new DefaultHttpResponseFactory(),
+                this.allocator,
                 this.params); 
         session.setAttribute(NHTTP_CONN, conn);
         

Modified: jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java Wed Jun  6 13:58:46 2007
@@ -41,6 +41,7 @@
 import org.apache.http.HttpResponseFactory;
 import org.apache.http.impl.nio.DefaultNHttpClientConnection;
 import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
 public class LoggingNHttpClientConnection extends DefaultNHttpClientConnection {
@@ -51,8 +52,9 @@
     public LoggingNHttpClientConnection(
             final IOSession session,
             final HttpResponseFactory responseFactory,
+            final ByteBufferAllocator allocator,
             final HttpParams params) {
-        super(session, responseFactory, params);
+        super(session, responseFactory, allocator, params);
         this.log = LogFactory.getLog(DefaultNHttpClientConnection.class);
         this.headerlog = LogFactory.getLog("org.apache.http.headers");
     }

Modified: jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java Wed Jun  6 13:58:46 2007
@@ -41,6 +41,7 @@
 import org.apache.http.HttpResponse;
 import org.apache.http.impl.nio.DefaultNHttpServerConnection;
 import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
 public class LoggingNHttpServerConnection extends DefaultNHttpServerConnection {
@@ -51,8 +52,9 @@
     public LoggingNHttpServerConnection(
             final IOSession session,
             final HttpRequestFactory requestFactory,
+            final ByteBufferAllocator allocator,
             final HttpParams params) {
-        super(session, requestFactory, params);
+        super(session, requestFactory, allocator, params);
         this.log = LogFactory.getLog(DefaultNHttpServerConnection.class);
         this.headerlog = LogFactory.getLog("org.apache.http.headers");
     }

Modified: jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java Wed Jun  6 13:58:46 2007
@@ -35,6 +35,8 @@
 import org.apache.http.nio.NHttpServiceHandler;
 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.params.HttpParams;
 
 public class LoggingServerIOEventDispatch implements IOEventDispatch {
@@ -42,24 +44,39 @@
     private static final String NHTTP_CONN = "NHTTP_CONN";
     
     private final NHttpServiceHandler handler;
+    private final ByteBufferAllocator allocator;
     private final HttpParams params;
     
-    public LoggingServerIOEventDispatch(final NHttpServiceHandler handler, final HttpParams params) {
+    public LoggingServerIOEventDispatch(
+            final NHttpServiceHandler handler, 
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
         super();
         if (handler == null) {
             throw new IllegalArgumentException("HTTP service handler may not be null");
         }
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
         this.handler = new LoggingNHttpServiceHandler(handler);
+        this.allocator = allocator;
         this.params = params;
     }
     
+    public LoggingServerIOEventDispatch(
+            final NHttpServiceHandler handler, 
+            final HttpParams params) {
+        this(handler, new DirectByteBufferAllocator(), params);
+    }
+    
     public void connected(final IOSession session) {
         LoggingNHttpServerConnection conn = new LoggingNHttpServerConnection(
                 new LoggingIOSession(session), 
                 new DefaultHttpRequestFactory(),
+                this.allocator,
                 this.params); 
         session.setAttribute(NHTTP_CONN, conn);
         this.handler.connected(conn);

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=544950&r1=544949&r2=544950
==============================================================================
--- 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 Wed Jun  6 13:58:46 2007
@@ -35,6 +35,8 @@
 import org.apache.http.nio.NHttpClientHandler;
 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.params.HttpParams;
 
 public class DefaultClientIOEventDispatch implements IOEventDispatch {
@@ -42,9 +44,13 @@
     private static final String NHTTP_CONN = "NHTTP_CONN";
     
     private final NHttpClientHandler handler;
+    private final ByteBufferAllocator allocator;
     private final HttpParams params;
-    
-    public DefaultClientIOEventDispatch(final NHttpClientHandler handler, final HttpParams params) {
+
+    public DefaultClientIOEventDispatch(
+            final NHttpClientHandler handler, 
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
         super();
         if (handler == null) {
             throw new IllegalArgumentException("HTTP client handler may not be null");
@@ -52,14 +58,25 @@
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
         this.handler = handler;
+        this.allocator = allocator;
         this.params = params;
     }
     
+    public DefaultClientIOEventDispatch(
+            final NHttpClientHandler handler, 
+            final HttpParams params) {
+        this(handler, new DirectByteBufferAllocator(), params);
+    }
+    
     public void connected(final IOSession session) {
         DefaultNHttpClientConnection conn = new DefaultNHttpClientConnection(
                 session, 
                 new DefaultHttpResponseFactory(),
+                this.allocator,
                 this.params); 
         session.setAttribute(NHTTP_CONN, conn);
         

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java Wed Jun  6 13:58:46 2007
@@ -49,6 +49,7 @@
 import org.apache.http.impl.nio.codecs.HttpResponseParser;
 import org.apache.http.nio.reactor.EventMask;
 import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
 public class DefaultNHttpClientConnection 
@@ -59,8 +60,9 @@
     public DefaultNHttpClientConnection(
             final IOSession session,
             final HttpResponseFactory responseFactory,
+            final ByteBufferAllocator allocator,
             final HttpParams params) {
-        super(session, params);
+        super(session, allocator, params);
         if (responseFactory == null) {
             throw new IllegalArgumentException("Response factory may not be null");
         }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java Wed Jun  6 13:58:46 2007
@@ -49,6 +49,7 @@
 import org.apache.http.impl.nio.codecs.HttpRequestParser;
 import org.apache.http.nio.reactor.EventMask;
 import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 
 public class DefaultNHttpServerConnection 
@@ -59,8 +60,9 @@
     public DefaultNHttpServerConnection(
             final IOSession session,
             final HttpRequestFactory requestFactory,
+            final ByteBufferAllocator allocator,
             final HttpParams params) {
-        super(session, params);
+        super(session, allocator, params);
         if (requestFactory == null) {
             throw new IllegalArgumentException("Request factory may not be null");
         }

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=544950&r1=544949&r2=544950
==============================================================================
--- 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 Wed Jun  6 13:58:46 2007
@@ -35,6 +35,8 @@
 import org.apache.http.nio.NHttpServiceHandler;
 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.params.HttpParams;
 
 public class DefaultServerIOEventDispatch implements IOEventDispatch {
@@ -42,24 +44,39 @@
     private static final String NHTTP_CONN = "NHTTP_CONN";
     
     private final NHttpServiceHandler handler;
+    private final ByteBufferAllocator allocator;
     private final HttpParams params;
     
-    public DefaultServerIOEventDispatch(final NHttpServiceHandler handler, final HttpParams params) {
+    public DefaultServerIOEventDispatch(
+            final NHttpServiceHandler handler,
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
         super();
         if (handler == null) {
             throw new IllegalArgumentException("HTTP service handler may not be null");
         }
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
         this.handler = handler;
+        this.allocator = allocator;
         this.params = params;
     }
     
+    public DefaultServerIOEventDispatch(
+            final NHttpServiceHandler handler, 
+            final HttpParams params) {
+        this(handler, new DirectByteBufferAllocator(), params);
+    }
+    
     public void connected(final IOSession session) {
         DefaultNHttpServerConnection conn = new DefaultNHttpServerConnection(
                 session, 
                 new DefaultHttpRequestFactory(),
+                this.allocator,
                 this.params); 
         session.setAttribute(NHTTP_CONN, conn);
         this.handler.connected(conn);

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java Wed Jun  6 13:58:46 2007
@@ -62,6 +62,7 @@
 import org.apache.http.nio.reactor.EventMask;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.SessionBufferStatus;
+import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HTTP;
@@ -91,7 +92,10 @@
     
     protected volatile boolean closed;
     
-    public NHttpConnectionBase(final IOSession session, final HttpParams params) {
+    public NHttpConnectionBase(
+            final IOSession session,
+            final ByteBufferAllocator allocator,
+            final HttpParams params) {
         super();
         if (session == null) {
             throw new IllegalArgumentException("I/O session may not be null");
@@ -108,9 +112,9 @@
             linebuffersize = 512;
         }
         
-        this.inbuf = new SessionInputBuffer(buffersize, linebuffersize); 
+        this.inbuf = new SessionInputBuffer(buffersize, linebuffersize, allocator); 
         this.inbuf.reset(params);
-        this.outbuf = new SessionOutputBuffer(buffersize, linebuffersize); 
+        this.outbuf = new SessionOutputBuffer(buffersize, linebuffersize, allocator); 
         this.outbuf.reset(params);
         this.lineBuffer = new CharArrayBuffer(64); 
         

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=544950&r1=544949&r2=544950
==============================================================================
--- 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 Wed Jun  6 13:58:46 2007
@@ -40,6 +40,8 @@
 import java.nio.charset.CharsetDecoder;
 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.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
@@ -52,13 +54,17 @@
     private Charset charset = null;
     private CharsetDecoder chardecoder = null;
     
-    public SessionInputBuffer(int buffersize, int linebuffersize) {
-        super(buffersize);
+    public SessionInputBuffer(int buffersize, int linebuffersize, final ByteBufferAllocator allocator) {
+        super(buffersize, allocator);
         this.charbuffer = CharBuffer.allocate(linebuffersize);
         this.charset = Charset.forName("US-ASCII");
         this.chardecoder = this.charset.newDecoder();
     }
 
+    public SessionInputBuffer(int buffersize, int linebuffersize) {
+        this(buffersize, linebuffersize, new DirectByteBufferAllocator());
+    }
+    
     public void reset(final HttpParams params) {
         this.charset = Charset.forName(HttpProtocolParams.getHttpElementCharset(params)); 
         this.chardecoder = this.charset.newDecoder();

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=544950&r1=544949&r2=544950
==============================================================================
--- 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 Wed Jun  6 13:58:46 2007
@@ -40,6 +40,8 @@
 import java.nio.charset.CharsetEncoder;
 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.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
@@ -54,11 +56,15 @@
     private Charset charset = null;
     private CharsetEncoder charencoder = null;
     
-    public SessionOutputBuffer(int buffersize, int linebuffersize) {
-        super(buffersize);
+    public SessionOutputBuffer(int buffersize, int linebuffersize, final ByteBufferAllocator allocator) {
+        super(buffersize, allocator);
         this.charbuffer = CharBuffer.allocate(linebuffersize);
         this.charset = Charset.forName("US-ASCII");
         this.charencoder = this.charset.newEncoder();
+    }
+
+    public SessionOutputBuffer(int buffersize, int linebuffersize) {
+        this(buffersize, linebuffersize, new DirectByteBufferAllocator());
     }
 
     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=544950&r1=544949&r2=544950
==============================================================================
--- 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 Wed Jun  6 13:58:46 2007
@@ -51,8 +51,10 @@
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.entity.ContentBufferEntity;
 import org.apache.http.nio.entity.ContentOutputStream;
+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.SimpleInputBuffer;
 import org.apache.http.nio.util.SimpleOutputBuffer;
 import org.apache.http.params.HttpParams;
@@ -81,6 +83,7 @@
     private HttpRequestExecutionHandler execHandler;
     private ConnectionReuseStrategy connStrategy;
     private EventListener eventListener;
+    private ByteBufferAllocator allocator;
     
     public BufferingHttpClientHandler(
             final HttpProcessor httpProcessor, 
@@ -104,6 +107,7 @@
         this.execHandler = execHandler;
         this.connStrategy = connStrategy;
         this.params = params;
+        this.allocator = new DirectByteBufferAllocator();
     }
     
     public void setEventListener(final EventListener eventListener) {
@@ -117,6 +121,13 @@
         }
     }
     
+    public void setByteBufferAllocator(final ByteBufferAllocator allocator) {
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
+        this.allocator = allocator;
+    }
+    
     public void connected(final NHttpClientConnection conn, final Object attachment) {
         HttpContext context = conn.getContext();
 
@@ -133,7 +144,7 @@
         
         initialize(conn, attachment);
         
-        ClientConnState connState = new ClientConnState(); 
+        ClientConnState connState = new ClientConnState(allocator); 
         context.setAttribute(CONN_STATE, connState);
 
         if (this.eventListener != null) {
@@ -462,21 +473,23 @@
         private HttpResponse response;
 
         private int timeout;
+        private final ByteBufferAllocator allocator;
         
-        public ClientConnState() {
+        public ClientConnState(final ByteBufferAllocator allocator) {
             super();
+            this.allocator = allocator;
         }
 
         public ContentInputBuffer getInbuffer() {
             if (this.inbuffer == null) {
-                this.inbuffer = new SimpleInputBuffer(2048);
+                this.inbuffer = new SimpleInputBuffer(2048, allocator);
             }
             return this.inbuffer;
         }
 
         public ContentOutputBuffer getOutbuffer() {
             if (this.outbuffer == null) {
-                this.outbuffer = new SimpleOutputBuffer(2048);
+                this.outbuffer = new SimpleOutputBuffer(2048, allocator);
             }
             return this.outbuffer;
         }

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=544950&r1=544949&r2=544950
==============================================================================
--- 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 Wed Jun  6 13:58:46 2007
@@ -54,8 +54,10 @@
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.entity.ContentBufferEntity;
 import org.apache.http.nio.entity.ContentOutputStream;
+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.SimpleInputBuffer;
 import org.apache.http.nio.util.SimpleOutputBuffer;
 import org.apache.http.params.HttpParams;
@@ -89,6 +91,7 @@
     private HttpRequestHandlerResolver handlerResolver;
     private HttpExpectationVerifier expectationVerifier;
     private EventListener eventListener;
+    private ByteBufferAllocator allocator;
     
     public BufferingHttpServiceHandler(
             final HttpProcessor httpProcessor, 
@@ -112,6 +115,14 @@
         this.connStrategy = connStrategy;
         this.responseFactory = responseFactory;
         this.params = params;
+        this.allocator = new DirectByteBufferAllocator();
+    }
+
+    public void setByteBufferAllocator(final ByteBufferAllocator allocator) {
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
+        this.allocator = allocator;
     }
 
     public void setEventListener(final EventListener eventListener) {
@@ -133,7 +144,7 @@
     public void connected(final NHttpServerConnection conn) {
         HttpContext context = conn.getContext();
 
-        ServerConnState connState = new ServerConnState(); 
+        ServerConnState connState = new ServerConnState(allocator); 
         context.setAttribute(CONN_STATE, connState);
 
         if (this.eventListener != null) {
@@ -473,23 +484,25 @@
         private int outputState;
         
         private HttpRequest request;
+        private final ByteBufferAllocator allocator;
         
-        public ServerConnState() {
+        public ServerConnState(final ByteBufferAllocator allocator) {
             super();
             this.inputState = READY;
             this.outputState = READY;
+            this.allocator = allocator;
         }
 
         public ContentInputBuffer getInbuffer() {
             if (this.inbuffer == null) {
-                this.inbuffer = new SimpleInputBuffer(2048);
+                this.inbuffer = new SimpleInputBuffer(2048, allocator);
             }
             return this.inbuffer;
         }
 
         public ContentOutputBuffer getOutbuffer() {
             if (this.outbuffer == null) {
-                this.outbuffer = new SimpleOutputBuffer(2048);
+                this.outbuffer = new SimpleOutputBuffer(2048, allocator);
             }
             return this.outbuffer;
         }

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=544950&r1=544949&r2=544950
==============================================================================
--- 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 Wed Jun  6 13:58:46 2007
@@ -57,8 +57,10 @@
 import org.apache.http.nio.entity.ContentBufferEntity;
 import org.apache.http.nio.entity.ContentOutputStream;
 import org.apache.http.nio.params.HttpNIOParams;
+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.SharedInputBuffer;
 import org.apache.http.nio.util.SharedOutputBuffer;
 import org.apache.http.params.HttpParams;
@@ -101,6 +103,7 @@
     private HttpExpectationVerifier expectationVerifier;
     private EventListener eventListener;
     private Executor executor;
+    private ByteBufferAllocator allocator;
     
     public ThrottlingHttpServiceHandler(
             final HttpProcessor httpProcessor, 
@@ -129,6 +132,7 @@
         this.responseFactory = responseFactory;
         this.executor = executor;
         this.params = params;
+        this.allocator = new DirectByteBufferAllocator();
     }
 
     public void setEventListener(final EventListener eventListener) {
@@ -143,6 +147,13 @@
         this.expectationVerifier = expectationVerifier;
     }
 
+    public void setByteBufferAllocator(final ByteBufferAllocator allocator) {
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
+        this.allocator = allocator;
+    }
+
     public HttpParams getParams() {
         return this.params;
     }
@@ -152,7 +163,7 @@
 
         int bufsize = this.params.getIntParameter(
                 HttpNIOParams.CONTENT_BUFFER_SIZE, 20480);
-        ServerConnState connState = new ServerConnState(bufsize, conn); 
+        ServerConnState connState = new ServerConnState(bufsize, conn, allocator); 
         context.setAttribute(CONN_STATE, connState);
 
         if (this.eventListener != null) {
@@ -596,10 +607,10 @@
         private volatile HttpRequest request;
         private volatile HttpResponse response;
         
-        public ServerConnState(int bufsize, final IOControl ioControl) {
+        public ServerConnState(int bufsize, final IOControl ioControl, final ByteBufferAllocator allocator) {
             super();
-            this.inbuffer = new SharedInputBuffer(bufsize, ioControl);
-            this.outbuffer = new SharedOutputBuffer(bufsize, ioControl);
+            this.inbuffer = new SharedInputBuffer(bufsize, ioControl, allocator);
+            this.outbuffer = new SharedOutputBuffer(bufsize, ioControl, allocator);
             this.inputState = READY;
             this.outputState = READY;
         }

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ByteBufferAllocator.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ByteBufferAllocator.java?view=auto&rev=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ByteBufferAllocator.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ByteBufferAllocator.java Wed Jun  6 13:58:46 2007
@@ -0,0 +1,40 @@
+/*
+ * $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 interface ByteBufferAllocator {
+    
+    ByteBuffer allocate(int size);
+    
+}

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

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

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

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java?view=auto&rev=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java Wed Jun  6 13:58:46 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 DirectByteBufferAllocator implements ByteBufferAllocator {
+
+    public ByteBuffer allocate(int size) {
+        return ByteBuffer.allocateDirect(size);
+    }
+
+}

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

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

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

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/ExpandableBuffer.java Wed Jun  6 13:58:46 2007
@@ -40,10 +40,15 @@
     
     private int mode;
     protected ByteBuffer buffer = null;
+    private final ByteBufferAllocator allocator;
 
-    public ExpandableBuffer(int buffersize) {
+    public ExpandableBuffer(int buffersize, final ByteBufferAllocator allocator) {
         super();
-        this.buffer = ByteBuffer.allocateDirect(buffersize);
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
+        this.allocator = allocator;
+        this.buffer = allocator.allocate(buffersize);
         this.mode = INPUT_MODE;
     }
 
@@ -71,7 +76,7 @@
     
     private void expandCapacity(int capacity) {
         ByteBuffer oldbuffer = this.buffer;
-        this.buffer = ByteBuffer.allocateDirect(capacity);
+        this.buffer = allocator.allocate(capacity);
         oldbuffer.flip();
         this.buffer.put(oldbuffer);
     }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SharedInputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SharedInputBuffer.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SharedInputBuffer.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SharedInputBuffer.java Wed Jun  6 13:58:46 2007
@@ -44,8 +44,8 @@
     private volatile boolean shutdown = false;
     private volatile boolean endOfStream = false;
     
-    public SharedInputBuffer(int buffersize, final IOControl ioctrl) {
-        super(buffersize);
+    public SharedInputBuffer(int buffersize, final IOControl ioctrl, final ByteBufferAllocator allocator) {
+        super(buffersize, allocator);
         if (ioctrl == null) {
             throw new IllegalArgumentException("I/O content control may not be null");
         }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java Wed Jun  6 13:58:46 2007
@@ -44,8 +44,8 @@
     private volatile boolean shutdown = false;
     private volatile boolean endOfStream;
     
-    public SharedOutputBuffer(int buffersize, final IOControl ioctrl) {
-        super(buffersize);
+    public SharedOutputBuffer(int buffersize, final IOControl ioctrl, final ByteBufferAllocator allocator) {
+        super(buffersize, allocator);
         if (ioctrl == null) {
             throw new IllegalArgumentException("I/O content control may not be null");
         }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SimpleInputBuffer.java Wed Jun  6 13:58:46 2007
@@ -38,8 +38,8 @@
 
     private boolean endOfStream = false;
     
-    public SimpleInputBuffer(int buffersize) {
-        super(buffersize);
+    public SimpleInputBuffer(int buffersize, final ByteBufferAllocator allocator) {
+        super(buffersize, allocator);
     }
     
     public void reset() {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SimpleOutputBuffer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SimpleOutputBuffer.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SimpleOutputBuffer.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/util/SimpleOutputBuffer.java Wed Jun  6 13:58:46 2007
@@ -38,8 +38,8 @@
     
     private boolean endOfStream;
     
-    public SimpleOutputBuffer(int buffersize) {
-        super(buffersize);
+    public SimpleOutputBuffer(int buffersize, final ByteBufferAllocator allocator) {
+        super(buffersize, allocator);
         this.endOfStream = false;
     }
 

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=544950&r1=544949&r2=544950
==============================================================================
--- 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 Wed Jun  6 13:58:46 2007
@@ -32,6 +32,7 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.nio.ByteBuffer;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
@@ -81,7 +82,7 @@
         
         ContentDecoder decoder = new MockupDecoder(channel); 
         
-        SimpleInputBuffer buffer = new SimpleInputBuffer(4);
+        SimpleInputBuffer buffer = new SimpleInputBuffer(4, new DirectByteBufferAllocator());
         int count = buffer.consumeContent(decoder);
         assertEquals(16, count);
         assertTrue(decoder.isCompleted());
@@ -114,7 +115,7 @@
         
         ContentEncoder encoder = new MockupEncoder(channel);
         
-        SimpleOutputBuffer buffer = new SimpleOutputBuffer(4); 
+        SimpleOutputBuffer buffer = new SimpleOutputBuffer(4, new DirectByteBufferAllocator()); 
         
         buffer.write(EncodingUtils.getAsciiBytes("stuff"));
         buffer.write(';');
@@ -129,16 +130,52 @@
     }
 
     public void testInputBufferNullInput() throws IOException {
-        SimpleInputBuffer buffer = new SimpleInputBuffer(4);
+        SimpleInputBuffer buffer = new SimpleInputBuffer(4, new DirectByteBufferAllocator());
         assertEquals(0, buffer.read(null));
         assertEquals(0, buffer.read(null, 0, 0));
     }
     
     public void testOutputBufferNullInput() throws IOException {
-        SimpleOutputBuffer buffer = new SimpleOutputBuffer(4);
+        SimpleOutputBuffer buffer = new SimpleOutputBuffer(4, new DirectByteBufferAllocator());
         buffer.write(null);
         buffer.write(null, 0, 10);
         assertFalse(buffer.hasData());
     }
-
+    
+    public void testDirectByteBufferAllocator() {
+        DirectByteBufferAllocator allocator = new DirectByteBufferAllocator();
+        ByteBuffer buffer = allocator.allocate(1);
+        assertNotNull(buffer);
+        assertTrue(buffer.isDirect());
+        assertEquals(0, buffer.position());
+        assertEquals(1, buffer.limit());
+        assertEquals(1, buffer.capacity());
+        
+        buffer = allocator.allocate(2048);
+        assertTrue(buffer.isDirect());
+        assertEquals(0, buffer.position());
+        assertEquals(2048, buffer.limit());
+        assertEquals(2048, buffer.capacity());
+        
+        buffer = allocator.allocate(0);
+        assertTrue(buffer.isDirect());
+        assertEquals(0, buffer.position());
+        assertEquals(0, buffer.limit());
+        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);
+    }
+    
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/examples/org/apache/http/examples/nio/NHttpSSLServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/examples/org/apache/http/examples/nio/NHttpSSLServer.java?view=diff&rev=544950&r1=544949&r2=544950
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/examples/org/apache/http/examples/nio/NHttpSSLServer.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/examples/org/apache/http/examples/nio/NHttpSSLServer.java Wed Jun  6 13:58:46 2007
@@ -129,7 +129,6 @@
         IOEventDispatch ioEventDispatch = new SSLServerIOEventDispatch(
                 handler, 
                 sslcontext,
-                null,
                 params);
         
         ListeningIOReactor ioReactor = new DefaultListeningIOReactor(2, params);

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=544950&r1=544949&r2=544950
==============================================================================
--- 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 Wed Jun  6 13:58:46 2007
@@ -41,6 +41,8 @@
 import org.apache.http.nio.NHttpClientHandler;
 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.params.HttpParams;
 
 public class SSLClientIOEventDispatch implements IOEventDispatch {
@@ -49,14 +51,16 @@
     private static final String SSL_SESSION = "SSL_SESSION";
     
     private final NHttpClientHandler handler;
-    private final HttpParams params;
     private final SSLContext sslcontext;
     private final SSLIOSessionHandler sslHandler;
+    private final ByteBufferAllocator allocator;
+    private final HttpParams params;
     
     public SSLClientIOEventDispatch(
             final NHttpClientHandler handler,
             final SSLContext sslcontext,
             final SSLIOSessionHandler sslHandler,
+            final ByteBufferAllocator allocator,
             final HttpParams params) {
         super();
         if (handler == null) {
@@ -65,6 +69,9 @@
         if (sslcontext == null) {
             throw new IllegalArgumentException("SSL context may not be null");
         }
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
@@ -72,13 +79,14 @@
         this.params = params;
         this.sslcontext = sslcontext;
         this.sslHandler = sslHandler;
+        this.allocator = allocator;
     }
     
     public SSLClientIOEventDispatch(
             final NHttpClientHandler handler,
             final SSLContext sslcontext,
             final HttpParams params) {
-        this(handler, sslcontext, null, params);
+        this(handler, sslcontext, null, new DirectByteBufferAllocator(), params);
     }
     
     public void connected(final IOSession session) {
@@ -91,6 +99,7 @@
         DefaultNHttpClientConnection conn = new DefaultNHttpClientConnection(
                 sslSession, 
                 new DefaultHttpResponseFactory(),
+                this.allocator,
                 this.params); 
         
         session.setAttribute(NHTTP_CONN, conn);

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=544950&r1=544949&r2=544950
==============================================================================
--- 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 Wed Jun  6 13:58:46 2007
@@ -41,6 +41,8 @@
 import org.apache.http.nio.NHttpServiceHandler;
 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.params.HttpParams;
 
 public class SSLServerIOEventDispatch implements IOEventDispatch {
@@ -51,12 +53,14 @@
     private final NHttpServiceHandler handler;
     private final SSLContext sslcontext;
     private final SSLIOSessionHandler sslHandler;
+    private final ByteBufferAllocator allocator;
     private final HttpParams params;
     
     public SSLServerIOEventDispatch(
             final NHttpServiceHandler handler,
             final SSLContext sslcontext,
             final SSLIOSessionHandler sslHandler,
+            final ByteBufferAllocator allocator,
             final HttpParams params) {
         super();
         if (handler == null) {
@@ -65,6 +69,9 @@
         if (sslcontext == null) {
             throw new IllegalArgumentException("SSL context may not be null");
         }
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
@@ -72,13 +79,14 @@
         this.params = params;
         this.sslcontext = sslcontext;
         this.sslHandler = sslHandler;
+        this.allocator = allocator;
     }
     
     public SSLServerIOEventDispatch(
             final NHttpServiceHandler handler,
             final SSLContext sslcontext,
             final HttpParams params) {
-        this(handler, sslcontext, null, params);
+        this(handler, sslcontext, null, new DirectByteBufferAllocator(), params);
     }
     
     public void connected(final IOSession session) {
@@ -91,6 +99,7 @@
         DefaultNHttpServerConnection conn = new DefaultNHttpServerConnection(
                 sslSession, 
                 new DefaultHttpRequestFactory(),
+                this.allocator,
                 this.params); 
         
         session.setAttribute(NHTTP_CONN, conn);



Mime
View raw message