You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2007/11/02 11:01:48 UTC

svn commit: r591287 - in /jakarta/httpcomponents/httpcore/trunk: ./ contrib/ 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/nio/ module-niossl/src/main/...

Author: olegk
Date: Fri Nov  2 03:01:45 2007
New Revision: 591287

URL: http://svn.apache.org/viewvc?rev=591287&view=rev
Log:
HTTPCORE-128: Simplified injection of custom NIO connection implementations

Added:
    jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java
      - copied, changed from r589333, 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/LoggingNHttpServerIOTarget.java
      - copied, changed from r589333, jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java   (with props)
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java   (with props)
Removed:
    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
Modified:
    jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    jakarta/httpcomponents/httpcore/trunk/contrib/   (props changed)
    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-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?rev=591287&r1=591286&r2=591287&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Fri Nov  2 03:01:45 2007
@@ -1,5 +1,8 @@
 Changes since 4.0 Alpha 6
 
+* [HTTPCORE-128] Simplified injection of custom NIO connection implementations. 
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCORE-126] Improved HTTP message parsing API and optimized parser
   implementations. 
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Propchange: jakarta/httpcomponents/httpcore/trunk/contrib/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Nov  2 03:01:45 2007
@@ -2,3 +2,4 @@
 .project
 bin
 .settings
+lib

Copied: jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java (from r589333, 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/LoggingNHttpClientIOTarget.java?p2=jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java&p1=jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java&r1=589333&r2=591287&rev=591287&view=diff
==============================================================================
--- 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/LoggingNHttpClientIOTarget.java Fri Nov  2 03:01:45 2007
@@ -36,34 +36,106 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
+import org.apache.http.HttpConnectionMetrics;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
-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;
+import org.apache.http.HttpResponse;
+import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientIOTarget;
+import org.apache.http.protocol.HttpContext;
 
-public class LoggingNHttpClientConnection extends DefaultNHttpClientConnection {
+public class LoggingNHttpClientIOTarget implements NHttpClientIOTarget  {
 
+    private final NHttpClientIOTarget target;
     private final Log log;
     private final Log headerlog;
     
-    public LoggingNHttpClientConnection(
-            final IOSession session,
-            final HttpResponseFactory responseFactory,
-            final ByteBufferAllocator allocator,
-            final HttpParams params) {
-        super(session, responseFactory, allocator, params);
-        this.log = LogFactory.getLog(DefaultNHttpClientConnection.class);
+    public LoggingNHttpClientIOTarget(final NHttpClientIOTarget target) {
+        super();
+        this.target = target;
+        this.log = LogFactory.getLog(target.getClass());
         this.headerlog = LogFactory.getLog("org.apache.http.headers");
     }
 
+    public void requestInput() {
+        this.target.requestInput();
+    }
+
+    public void requestOutput() {
+        this.target.requestOutput();
+    }
+
+    public void suspendInput() {
+        this.target.suspendInput();
+    }
+
+    public void suspendOutput() {
+        this.target.suspendOutput();
+    }
+
+    public void close() throws IOException {
+        this.log.debug("Close connection");        
+        this.target.close();
+    }
+
+    public HttpConnectionMetrics getMetrics() {
+        return this.target.getMetrics();
+    }
+
+    public int getSocketTimeout() {
+        return this.target.getSocketTimeout();
+    }
+
+    public boolean isOpen() {
+        return this.target.isOpen();
+    }
+
+    public boolean isStale() {
+        return this.target.isStale();
+    }
+
+    public void setSocketTimeout(int timeout) {
+        this.target.setSocketTimeout(timeout);
+    }
+
+    public void shutdown() throws IOException {
+        this.log.debug("Shutdown connection");        
+        this.target.shutdown();
+    }
+
+    public HttpContext getContext() {
+        return this.target.getContext();
+    }
+
+    public HttpRequest getHttpRequest() {
+        return this.target.getHttpRequest();
+    }
+
+    public HttpResponse getHttpResponse() {
+        return this.target.getHttpResponse();
+    }
+
+    public int getStatus() {
+        return this.target.getStatus();
+    }
+
+    public boolean isRequestSubmitted() {
+        return this.target.isRequestSubmitted();
+    }
+
+    public void resetInput() {
+        this.target.resetInput();
+    }
+
+    public void resetOutput() {
+        this.target.resetOutput();
+    }
+
     public void submitRequest(final HttpRequest request) throws IOException, HttpException {
         if (this.log.isDebugEnabled()) {
             this.log.debug("HTTP connection " + this + ": "  + request.getRequestLine().toString());
         }
-        super.submitRequest(request);
+        this.target.submitRequest(request);
         if (this.headerlog.isDebugEnabled()) {
             this.headerlog.debug(">> " + request.getRequestLine().toString());
             Header[] headers = request.getAllHeaders();
@@ -71,6 +143,16 @@
                 this.headerlog.debug(">> " + headers[i].toString());
             }
         }
+    }
+
+    public void consumeInput(final NHttpClientHandler handler) {
+        this.log.debug("Consume input");        
+        this.target.consumeInput(handler);
+    }
+
+    public void produceOutput(final NHttpClientHandler handler) {
+        this.log.debug("Produce output");        
+        this.target.produceOutput(handler);
     }
     
 }

Copied: jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java (from r589333, 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/LoggingNHttpServerIOTarget.java?p2=jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java&p1=jakarta/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java&r1=589333&r2=591287&rev=591287&view=diff
==============================================================================
--- 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/LoggingNHttpServerIOTarget.java Fri Nov  2 03:01:45 2007
@@ -36,34 +36,105 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
+import org.apache.http.HttpConnectionMetrics;
 import org.apache.http.HttpException;
-import org.apache.http.HttpRequestFactory;
+import org.apache.http.HttpRequest;
 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;
+import org.apache.http.nio.NHttpServerIOTarget;
+import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.protocol.HttpContext;
 
-public class LoggingNHttpServerConnection extends DefaultNHttpServerConnection {
+public class LoggingNHttpServerIOTarget implements NHttpServerIOTarget {
 
+    private final NHttpServerIOTarget target;
     private final Log log;
     private final Log headerlog;
     
-    public LoggingNHttpServerConnection(
-            final IOSession session,
-            final HttpRequestFactory requestFactory,
-            final ByteBufferAllocator allocator,
-            final HttpParams params) {
-        super(session, requestFactory, allocator, params);
-        this.log = LogFactory.getLog(DefaultNHttpServerConnection.class);
+    public LoggingNHttpServerIOTarget(final NHttpServerIOTarget target) {
+        this.target = target;
+        this.log = LogFactory.getLog(target.getClass());
         this.headerlog = LogFactory.getLog("org.apache.http.headers");
     }
 
+    public void requestInput() {
+        this.target.requestInput();
+    }
+
+    public void requestOutput() {
+        this.target.requestOutput();
+    }
+
+    public void suspendInput() {
+        this.target.suspendInput();
+    }
+
+    public void suspendOutput() {
+        this.target.suspendOutput();
+    }
+
+    public void close() throws IOException {
+        this.log.debug("Close connection");        
+        this.target.close();
+    }
+
+    public HttpConnectionMetrics getMetrics() {
+        return this.target.getMetrics();
+    }
+
+    public int getSocketTimeout() {
+        return this.target.getSocketTimeout();
+    }
+
+    public boolean isOpen() {
+        return this.target.isOpen();
+    }
+
+    public boolean isStale() {
+        return this.target.isStale();
+    }
+
+    public void setSocketTimeout(int timeout) {
+        this.target.setSocketTimeout(timeout);
+    }
+
+    public void shutdown() throws IOException {
+        this.log.debug("Shutdown connection");        
+        this.target.shutdown();
+    }
+    
+    public HttpContext getContext() {
+        return this.target.getContext();
+    }
+
+    public HttpRequest getHttpRequest() {
+        return this.target.getHttpRequest();
+    }
+
+    public HttpResponse getHttpResponse() {
+        return this.target.getHttpResponse();
+    }
+
+    public int getStatus() {
+        return this.target.getStatus();
+    }
+
+    public boolean isResponseSubmitted() {
+        return this.target.isResponseSubmitted();
+    }
+
+    public void resetInput() {
+        this.target.requestInput();
+    }
+
+    public void resetOutput() {
+        this.target.requestOutput();
+    }
+
     public void submitResponse(final HttpResponse response) throws IOException, HttpException {
         if (this.log.isDebugEnabled()) {
             this.log.debug("HTTP connection " + this + ": "  + response.getStatusLine().toString());
         }
-        super.submitResponse(response);
+        this.target.submitResponse(response);
         if (this.headerlog.isDebugEnabled()) {
             this.headerlog.debug("<< " + response.getStatusLine().toString());
             Header[] headers = response.getAllHeaders();
@@ -71,6 +142,16 @@
                 this.headerlog.debug("<< " + headers[i].toString());
             }
         }
+    }
+
+    public void consumeInput(final NHttpServiceHandler handler) {
+        this.log.debug("Consume input");        
+        this.target.consumeInput(handler);
+    }
+
+    public void produceOutput(final NHttpServiceHandler handler) {
+        this.log.debug("Produce output");        
+        this.target.produceOutput(handler);
     }
     
 }

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?rev=591287&r1=591286&r2=591287&view=diff
==============================================================================
--- 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 Nov  2 03:01:45 2007
@@ -32,6 +32,7 @@
 package org.apache.http.impl.nio;
 
 import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
@@ -43,13 +44,12 @@
 
     private static final String NHTTP_CONN = "NHTTP_CONN";
     
-    private final NHttpClientHandler handler;
     private final ByteBufferAllocator allocator;
+    private final NHttpClientHandler handler;
     private final HttpParams params;
 
     public DefaultClientIOEventDispatch(
             final NHttpClientHandler handler, 
-            final ByteBufferAllocator allocator,
             final HttpParams params) {
         super();
         if (handler == null) {
@@ -58,53 +58,51 @@
         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.allocator = createByteBufferAllocator();
         this.handler = handler;
-        this.allocator = allocator;
         this.params = params;
     }
     
-    public DefaultClientIOEventDispatch(
-            final NHttpClientHandler handler, 
-            final HttpParams params) {
-        this(handler, new HeapByteBufferAllocator(), params);
+    protected ByteBufferAllocator createByteBufferAllocator() {
+        return new HeapByteBufferAllocator(); 
     }
-    
-    public void connected(final IOSession session) {
-        DefaultNHttpClientConnection conn = new DefaultNHttpClientConnection(
+        
+    protected NHttpClientIOTarget createConnection(final IOSession session) {
+        return new DefaultNHttpClientConnection(
                 session, 
                 new DefaultHttpResponseFactory(),
                 this.allocator,
                 this.params); 
-        session.setAttribute(NHTTP_CONN, conn);
+    }
         
+    public void connected(final IOSession session) {
+        NHttpClientIOTarget conn = createConnection(session);
         Object attachment = session.getAttribute(IOSession.ATTACHMENT_KEY);
+//        session.setAttribute(NHTTP_CONN, conn);
         this.handler.connected(conn, attachment);
     }
 
     public void disconnected(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
+        NHttpClientIOTarget conn = 
+            (NHttpClientIOTarget) session.getAttribute(NHTTP_CONN);
         this.handler.closed(conn);
     }
 
     public void inputReady(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
+        NHttpClientIOTarget conn = 
+            (NHttpClientIOTarget) session.getAttribute(NHTTP_CONN);
         conn.consumeInput(this.handler);
     }
 
     public void outputReady(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
+        NHttpClientIOTarget conn = 
+            (NHttpClientIOTarget) session.getAttribute(NHTTP_CONN);
         conn.produceOutput(this.handler);
     }
 
     public void timeout(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
+        NHttpClientIOTarget conn = 
+            (NHttpClientIOTarget) session.getAttribute(NHTTP_CONN);
         this.handler.timeout(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?rev=591287&r1=591286&r2=591287&view=diff
==============================================================================
--- 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 Fri Nov  2 03:01:45 2007
@@ -41,7 +41,7 @@
 import org.apache.http.HttpResponseFactory;
 import org.apache.http.impl.nio.codecs.HttpRequestWriter;
 import org.apache.http.impl.nio.codecs.HttpResponseParser;
-import org.apache.http.nio.NHttpClientConnection;
+import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.NHttpMessageParser;
 import org.apache.http.nio.NHttpMessageWriter;
@@ -53,7 +53,7 @@
 import org.apache.http.params.HttpParams;
 
 public class DefaultNHttpClientConnection 
-    extends NHttpConnectionBase implements NHttpClientConnection {
+    extends NHttpConnectionBase implements NHttpClientIOTarget {
 
     private final NHttpMessageParser responseParser;
     private final NHttpMessageWriter requestWriter;

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?rev=591287&r1=591286&r2=591287&view=diff
==============================================================================
--- 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 Fri Nov  2 03:01:45 2007
@@ -43,7 +43,7 @@
 import org.apache.http.impl.nio.codecs.HttpResponseWriter;
 import org.apache.http.nio.NHttpMessageParser;
 import org.apache.http.nio.NHttpMessageWriter;
-import org.apache.http.nio.NHttpServerConnection;
+import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.reactor.EventMask;
 import org.apache.http.nio.reactor.IOSession;
@@ -53,7 +53,7 @@
 import org.apache.http.params.HttpParams;
 
 public class DefaultNHttpServerConnection 
-    extends NHttpConnectionBase implements NHttpServerConnection {
+    extends NHttpConnectionBase implements NHttpServerIOTarget {
 
     private final NHttpMessageParser requestParser;
     private final NHttpMessageWriter responseWriter;

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?rev=591287&r1=591286&r2=591287&view=diff
==============================================================================
--- 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 Nov  2 03:01:45 2007
@@ -32,6 +32,7 @@
 package org.apache.http.impl.nio;
 
 import org.apache.http.impl.DefaultHttpRequestFactory;
+import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
@@ -43,66 +44,64 @@
 
     private static final String NHTTP_CONN = "NHTTP_CONN";
     
-    private final NHttpServiceHandler handler;
     private final ByteBufferAllocator allocator;
+    private final NHttpServiceHandler handler;
     private 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.allocator = createByteBufferAllocator();
         this.handler = handler;
-        this.allocator = allocator;
         this.params = params;
     }
     
-    public DefaultServerIOEventDispatch(
-            final NHttpServiceHandler handler, 
-            final HttpParams params) {
-        this(handler, new HeapByteBufferAllocator(), params);
+    protected ByteBufferAllocator createByteBufferAllocator() {
+        return new HeapByteBufferAllocator(); 
     }
-    
-    public void connected(final IOSession session) {
-        DefaultNHttpServerConnection conn = new DefaultNHttpServerConnection(
+        
+    protected NHttpServerIOTarget createConnection(final IOSession session) {
+        return new DefaultNHttpServerConnection(
                 session, 
                 new DefaultHttpRequestFactory(),
                 this.allocator,
                 this.params); 
+    }
+        
+    public void connected(final IOSession session) {
+        NHttpServerIOTarget conn = createConnection(session);
         session.setAttribute(NHTTP_CONN, conn);
         this.handler.connected(conn);
     }
 
     public void disconnected(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
+        NHttpServerIOTarget conn = 
+            (NHttpServerIOTarget) session.getAttribute(NHTTP_CONN);
         this.handler.closed(conn);
     }
 
     public void inputReady(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
+        NHttpServerIOTarget conn = 
+            (NHttpServerIOTarget) session.getAttribute(NHTTP_CONN);
         conn.consumeInput(this.handler);
     }
 
     public void outputReady(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
+        NHttpServerIOTarget conn = 
+            (NHttpServerIOTarget) session.getAttribute(NHTTP_CONN);
         conn.produceOutput(this.handler);
     }
 
     public void timeout(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
+        NHttpServerIOTarget conn = 
+            (NHttpServerIOTarget) session.getAttribute(NHTTP_CONN);
         this.handler.timeout(conn);
     }
 

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java?rev=591287&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java Fri Nov  2 03:01:45 2007
@@ -0,0 +1,48 @@
+/*
+ * $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;
+
+import org.apache.http.nio.reactor.IOEventDispatch;
+
+/**
+ * Extended version of the {@link NHttpClientConnection} used by {@link IOEventDispatch}
+ * implementations to inform client-side connection objects of I/O events.
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public interface NHttpClientIOTarget extends NHttpClientConnection {
+    
+    void consumeInput(NHttpClientHandler handler);
+    
+    void produceOutput(NHttpClientHandler handler);    
+
+}

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

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

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

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java?rev=591287&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java Fri Nov  2 03:01:45 2007
@@ -0,0 +1,48 @@
+/*
+ * $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;
+
+import org.apache.http.nio.reactor.IOEventDispatch;
+
+/**
+ * Extended version of the {@link NHttpServerConnection} used by {@link IOEventDispatch}
+ * implementations to inform server-side connection objects of I/O events.
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public interface NHttpServerIOTarget extends NHttpServerConnection {
+    
+    void consumeInput(NHttpServiceHandler handler);
+    
+    void produceOutput(NHttpServiceHandler handler);    
+
+}

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

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

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

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?rev=591287&r1=591286&r2=591287&view=diff
==============================================================================
--- 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 Nov  2 03:01:45 2007
@@ -39,6 +39,7 @@
 import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.impl.nio.DefaultNHttpClientConnection;
 import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.util.ByteBufferAllocator;
@@ -50,17 +51,16 @@
     private static final String NHTTP_CONN = "NHTTP_CONN";
     private static final String SSL_SESSION = "SSL_SESSION";
     
+    private final ByteBufferAllocator allocator;
     private final NHttpClientHandler handler;
     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) {
@@ -69,26 +69,35 @@
         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");
         }
+        this.allocator = createByteBufferAllocator();
         this.handler = handler;
         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, new HeapByteBufferAllocator(), params);
+        this(handler, sslcontext, null, params);
     }
     
+    protected ByteBufferAllocator createByteBufferAllocator() {
+        return new HeapByteBufferAllocator(); 
+    }
+        
+    protected NHttpClientIOTarget createConnection(final IOSession session) {
+        return new DefaultNHttpClientConnection(
+                session, 
+                new DefaultHttpResponseFactory(),
+                this.allocator,
+                this.params); 
+    }
+        
     public void connected(final IOSession session) {
 
         SSLIOSession sslSession = new SSLIOSession(
@@ -96,11 +105,8 @@
                 this.sslcontext,
                 this.sslHandler); 
         
-        DefaultNHttpClientConnection conn = new DefaultNHttpClientConnection(
-                sslSession, 
-                new DefaultHttpResponseFactory(),
-                this.allocator,
-                this.params); 
+        NHttpClientIOTarget conn = createConnection(
+                sslSession);
         
         session.setAttribute(NHTTP_CONN, conn);
         session.setAttribute(SSL_SESSION, sslSession);
@@ -117,17 +123,18 @@
     }
 
     public void disconnected(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
+        NHttpClientIOTarget conn = 
+            (NHttpClientIOTarget) session.getAttribute(NHTTP_CONN);
         
         this.handler.closed(conn);
     }
 
     public void inputReady(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
+        NHttpClientIOTarget conn = 
+            (NHttpClientIOTarget) session.getAttribute(NHTTP_CONN);
+        SSLIOSession sslSession = 
+            (SSLIOSession) session.getAttribute(SSL_SESSION);
+
         try {
             synchronized (sslSession) {
                 if (sslSession.isAppInputReady()) {
@@ -142,10 +149,11 @@
     }
 
     public void outputReady(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
+        NHttpClientIOTarget conn = 
+            (NHttpClientIOTarget) session.getAttribute(NHTTP_CONN);
+        SSLIOSession sslSession = 
+            (SSLIOSession) session.getAttribute(SSL_SESSION);
+
         try {
             synchronized (sslSession) {
                 if (sslSession.isAppOutputReady()) {
@@ -160,10 +168,11 @@
     }
 
     public void timeout(final IOSession session) {
-        DefaultNHttpClientConnection conn = (DefaultNHttpClientConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
+        NHttpClientIOTarget conn = 
+            (NHttpClientIOTarget) session.getAttribute(NHTTP_CONN);
+        SSLIOSession sslSession = 
+            (SSLIOSession) session.getAttribute(SSL_SESSION);
+
         this.handler.timeout(conn);
         synchronized (sslSession) {
             if (sslSession.isOutboundDone() && !sslSession.isInboundDone()) {

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?rev=591287&r1=591286&r2=591287&view=diff
==============================================================================
--- 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 Nov  2 03:01:45 2007
@@ -38,6 +38,7 @@
 
 import org.apache.http.impl.DefaultHttpRequestFactory;
 import org.apache.http.impl.nio.DefaultNHttpServerConnection;
+import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
@@ -50,17 +51,16 @@
     private static final String NHTTP_CONN = "NHTTP_CONN";
     private static final String SSL_SESSION = "SSL_SESSION";
    
+    private final ByteBufferAllocator allocator;
     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) {
@@ -69,26 +69,35 @@
         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");
         }
+        this.allocator = createByteBufferAllocator();
         this.handler = handler;
         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, new HeapByteBufferAllocator(), params);
+        this(handler, sslcontext, null, params);
     }
     
+    protected ByteBufferAllocator createByteBufferAllocator() {
+        return new HeapByteBufferAllocator(); 
+    }
+        
+    protected NHttpServerIOTarget createConnection(final IOSession session) {
+        return new DefaultNHttpServerConnection(
+                session, 
+                new DefaultHttpRequestFactory(),
+                this.allocator,
+                this.params); 
+    }
+        
     public void connected(final IOSession session) {
 
         SSLIOSession sslSession = new SSLIOSession(
@@ -96,11 +105,8 @@
                 this.sslcontext,
                 this.sslHandler); 
         
-        DefaultNHttpServerConnection conn = new DefaultNHttpServerConnection(
-                sslSession, 
-                new DefaultHttpRequestFactory(),
-                this.allocator,
-                this.params); 
+        NHttpServerIOTarget conn = createConnection(
+                sslSession); 
         
         session.setAttribute(NHTTP_CONN, conn);
         session.setAttribute(SSL_SESSION, sslSession);
@@ -116,16 +122,18 @@
     }
 
     public void disconnected(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
+        NHttpServerIOTarget conn = 
+            (NHttpServerIOTarget) session.getAttribute(NHTTP_CONN);
+
         this.handler.closed(conn);
     }
 
     public void inputReady(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
+        NHttpServerIOTarget conn = 
+            (NHttpServerIOTarget) session.getAttribute(NHTTP_CONN);
+        SSLIOSession sslSession = 
+            (SSLIOSession) session.getAttribute(SSL_SESSION);
+
         try {
             synchronized (sslSession) {
                 if (sslSession.isAppInputReady()) {
@@ -140,10 +148,11 @@
     }
 
     public void outputReady(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
+        NHttpServerIOTarget conn = 
+            (NHttpServerIOTarget) session.getAttribute(NHTTP_CONN);
+        SSLIOSession sslSession = 
+            (SSLIOSession) session.getAttribute(SSL_SESSION);
+
         try {
             synchronized (sslSession) {
                 if (sslSession.isAppOutputReady()) {
@@ -158,10 +167,11 @@
     }
 
     public void timeout(final IOSession session) {
-        DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session.getAttribute(
-                NHTTP_CONN);
-        SSLIOSession sslSession = (SSLIOSession) session.getAttribute(
-                SSL_SESSION);
+        NHttpServerIOTarget conn = 
+            (NHttpServerIOTarget) session.getAttribute(NHTTP_CONN);
+        SSLIOSession sslSession = 
+            (SSLIOSession) session.getAttribute(SSL_SESSION);
+
         this.handler.timeout(conn);
         synchronized (sslSession) {
             if (sslSession.isOutboundDone() && !sslSession.isInboundDone()) {