hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1767339 [12/14] - in /httpcomponents/httpcore/trunk: ./ httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/ httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/ httpcore5-h2/src/main/java/org/apache/hc/core5/http2/boot...
Date Mon, 31 Oct 2016 17:33:33 GMT
Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/RequestChannel.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/RequestChannel.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/RequestChannel.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/RequestChannel.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/RequestChannel.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/RequestChannel.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/RequestChannel.java Mon Oct 31 17:33:27 2016
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.nio;
 
 import java.io.IOException;
 

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResourceHolder.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResourceHolder.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResourceHolder.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResourceHolder.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResourceHolder.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResourceHolder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResourceHolder.java Mon Oct 31 17:33:27 2016
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.nio;
 
 /**
  * Abstract resource holder.

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResourceHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResourceHolder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResourceHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResponseChannel.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResponseChannel.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResponseChannel.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResponseChannel.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResponseChannel.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/ResponseChannel.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResponseChannel.java Mon Oct 31 17:33:27 2016
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.nio;
 
 import java.io.IOException;
 

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResponseChannel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResponseChannel.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ResponseChannel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/SessionOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/SessionOutputBuffer.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/SessionOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/SessionOutputBuffer.java Mon Oct 31 17:33:27 2016
@@ -58,7 +58,7 @@ public interface SessionOutputBuffer {
      *
      * @return available space.
      */
-    int available();
+    int capacity();
 
     /**
      * Returns the length of this buffer.

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/StreamChannel.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/StreamChannel.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/StreamChannel.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/StreamChannel.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/StreamChannel.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/StreamChannel.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/StreamChannel.java Mon Oct 31 17:33:27 2016
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.nio;
 
 import java.io.IOException;
 import java.nio.Buffer;

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/StreamChannel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/StreamChannel.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/StreamChannel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/Supplier.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/Supplier.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/Supplier.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/Supplier.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/Supplier.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/Supplier.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/Supplier.java Mon Oct 31 17:33:27 2016
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.nio;
 
 /**
  * Abstract object supplier.

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/Supplier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/Supplier.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/Supplier.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ExecutionCommand.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ExecutionCommand.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ExecutionCommand.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ExecutionCommand.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ExecutionCommand.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ExecutionCommand.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ExecutionCommand.java Mon Oct 31 17:33:27 2016
@@ -25,10 +25,10 @@
  *
  */
 
-package org.apache.hc.core5.http2.nio.command;
+package org.apache.hc.core5.http.nio.command;
 
+import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
 import org.apache.hc.core5.http.protocol.HttpContext;
-import org.apache.hc.core5.http2.nio.AsyncClientExchangeHandler;
 import org.apache.hc.core5.reactor.Command;
 import org.apache.hc.core5.util.Args;
 

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ExecutionCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ExecutionCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ExecutionCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownCommand.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownCommand.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownCommand.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java Mon Oct 31 17:33:27 2016
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http2.nio.command;
+package org.apache.hc.core5.http.nio.command;
 
 import org.apache.hc.core5.reactor.Command;
 

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownType.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownType.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownType.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownType.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownType.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/command/ShutdownType.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownType.java Mon Oct 31 17:33:27 2016
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http2.nio.command;
+package org.apache.hc.core5.http.nio.command;
 
 /**
  * Shutdown type.

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownType.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/command/ShutdownType.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityConsumer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityConsumer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java Mon Oct 31 17:33:27 2016
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio.entity;
+package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
@@ -36,15 +36,15 @@ import org.apache.hc.core5.concurrent.Fu
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http2.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
 import org.apache.hc.core5.util.Args;
 
 public abstract class AbstractBinAsyncEntityConsumer<T> implements AsyncEntityConsumer<T> {
 
     protected abstract void dataStart(ContentType contentType, FutureCallback<T> resultCallback) throws HttpException, IOException;
 
-    protected abstract void consumeData(ByteBuffer src) throws IOException;
+    protected abstract int consumeData(ByteBuffer src) throws IOException;
 
     protected abstract void dataEnd() throws IOException;
 
@@ -62,8 +62,8 @@ public abstract class AbstractBinAsyncEn
     }
 
     @Override
-    public final void consume(final ByteBuffer src) throws IOException {
-        consumeData(src);
+    public final int consume(final ByteBuffer src) throws IOException {
+        return consumeData(src);
     }
 
     @Override

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityConsumer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityProducer.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityProducer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityProducer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityProducer.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityProducer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractBinAsyncEntityProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityProducer.java Mon Oct 31 17:33:27 2016
@@ -24,16 +24,16 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio.entity;
+package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.Set;
 
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http2.nio.AsyncEntityProducer;
-import org.apache.hc.core5.http2.nio.DataStreamChannel;
-import org.apache.hc.core5.http2.nio.StreamChannel;
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.http.nio.StreamChannel;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -41,19 +41,22 @@ import org.apache.hc.core5.util.Args;
  */
 public abstract class AbstractBinAsyncEntityProducer implements AsyncEntityProducer {
 
-    private final ContentType contentType;
     private final ByteBuffer bytebuf;
+    private final int fragmentSizeHint;
+    private final ContentType contentType;
 
     private volatile boolean endStream;
 
-    public AbstractBinAsyncEntityProducer(final int bufferSize, final ContentType contentType) {
+    public AbstractBinAsyncEntityProducer(
+            final int bufferSize,
+            final int fragmentSizeHint,
+            final ContentType contentType) {
         Args.positive(bufferSize, "Buffer size");
         this.bytebuf = ByteBuffer.allocate(bufferSize);
+        this.fragmentSizeHint = fragmentSizeHint >= 0 ? fragmentSizeHint : bufferSize / 2;
         this.contentType = contentType;
     }
 
-    protected abstract void dataStart() throws IOException;
-
     protected abstract void produceData(StreamChannel<ByteBuffer> channel) throws IOException;
 
     @Override
@@ -77,17 +80,12 @@ public abstract class AbstractBinAsyncEn
     }
 
     @Override
-    public final void streamStart(final DataStreamChannel channel)  throws IOException {
-        dataStart();
-    }
-
-    @Override
     public final void produce(final DataStreamChannel channel) throws IOException {
         produceData(new StreamChannel<ByteBuffer>() {
 
             @Override
             public int write(final ByteBuffer src) throws IOException {
-                Args.notNull(src, "ByteBuffer");
+                Args.notNull(src, "Buffer");
                 final int chunk = src.remaining();
                 if (chunk == 0) {
                     return 0;
@@ -96,16 +94,18 @@ public abstract class AbstractBinAsyncEn
                     bytebuf.put(src);
                     return chunk;
                 }
-                if (bytebuf.position() > 0) {
+                int totalBytesWritten = 0;
+                if (!bytebuf.hasRemaining() || bytebuf.position() >= fragmentSizeHint) {
                     bytebuf.flip();
                     final int bytesWritten = channel.write(bytebuf);
                     bytebuf.compact();
-                    return bytesWritten;
+                    totalBytesWritten += bytesWritten;
                 }
                 if (bytebuf.position() == 0) {
-                    return channel.write(src);
+                    final int bytesWritten = channel.write(src);
+                    totalBytesWritten += bytesWritten;
                 }
-                return 0;
+                return totalBytesWritten;
             }
 
             @Override
@@ -115,7 +115,7 @@ public abstract class AbstractBinAsyncEn
 
         });
 
-        if (bytebuf.remaining() > 1024 || endStream) {
+        if (endStream || !bytebuf.hasRemaining() || bytebuf.position() >= fragmentSizeHint) {
             bytebuf.flip();
             channel.write(bytebuf);
             bytebuf.compact();

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractBinAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityConsumer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityConsumer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java Mon Oct 31 17:33:27 2016
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio.entity;
+package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
@@ -41,8 +41,8 @@ import org.apache.hc.core5.concurrent.Fu
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http2.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -90,7 +90,7 @@ public abstract class AbstractCharAsyncE
         charbuf.compact();
     }
 
-    public final void consume(final ByteBuffer src) throws IOException {
+    public final int consume(final ByteBuffer src) throws IOException {
         Args.notNull(src, "ByteBuffer");
         if (charsetDecoder == null) {
             Charset charset = contentType != null ? contentType.getCharset() : null;
@@ -106,6 +106,7 @@ public abstract class AbstractCharAsyncE
             checkResult(charsetDecoder.decode(src, charbuf, false));
             doDecode();
         }
+        return charbuf.remaining();
     }
 
     @Override

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityConsumer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityProducer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityProducer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/AbstractCharAsyncEntityProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java Mon Oct 31 17:33:27 2016
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio.entity;
+package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -35,10 +35,10 @@ import java.nio.charset.CoderResult;
 import java.nio.charset.StandardCharsets;
 import java.util.Set;
 
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http2.nio.AsyncEntityProducer;
-import org.apache.hc.core5.http2.nio.DataStreamChannel;
-import org.apache.hc.core5.http2.nio.StreamChannel;
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.http.nio.StreamChannel;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -46,46 +46,53 @@ import org.apache.hc.core5.util.Args;
  */
 public abstract class AbstractCharAsyncEntityProducer implements AsyncEntityProducer {
 
+    private enum State { ACTIVE, FLUSHING, END_STREAM }
+
     private static final CharBuffer EMPTY = CharBuffer.wrap(new char[0]);
 
+    private final ByteBuffer bytebuf;
+    private final int fragmentSizeHint;
     private final ContentType contentType;
     private final CharsetEncoder charsetEncoder;
-    private final ByteBuffer bytebuf;
     private final StreamChannel<CharBuffer> charDataStream;
 
-    private volatile boolean endStream;
+    private volatile State state;
 
-    public AbstractCharAsyncEntityProducer(final int bufferSize, final ContentType contentType) {
+    public AbstractCharAsyncEntityProducer(
+            final int bufferSize,
+            final int fragmentSizeHint,
+            final ContentType contentType) {
         Args.positive(bufferSize, "Buffer size");
+        this.fragmentSizeHint = fragmentSizeHint >= 0 ? fragmentSizeHint : bufferSize / 2;
+        this.bytebuf = ByteBuffer.allocate(bufferSize);
         this.contentType = contentType;
         Charset charset = contentType != null ? contentType.getCharset() : null;
         if (charset == null) {
             charset = StandardCharsets.US_ASCII;
         }
         this.charsetEncoder = charset.newEncoder();
-        this.bytebuf = ByteBuffer.allocate(bufferSize);
         this.charDataStream = new StreamChannel<CharBuffer>() {
 
             @Override
             public int write(final CharBuffer src) throws IOException {
-                Args.notNull(src, "CharBuffer");
+                Args.notNull(src, "Buffer");
                 final int p = src.position();
-                checkResult(charsetEncoder.encode(src, bytebuf, false));
+                final CoderResult result = charsetEncoder.encode(src, bytebuf, false);
+                if (result.isError()) {
+                    result.throwException();
+                }
                 return src.position() - p;
             }
 
             @Override
             public void endStream() throws IOException {
-                endStream = true;
-                checkResult(charsetEncoder.encode(EMPTY, bytebuf, true));
-                checkResult(charsetEncoder.flush(bytebuf));
+                state = State.FLUSHING;
             }
 
         };
+        this.state = State.ACTIVE;
     }
 
-    protected abstract void dataStart(StreamChannel<CharBuffer> channel) throws IOException;
-
     protected abstract void produceData(StreamChannel<CharBuffer> channel) throws IOException;
 
     @Override
@@ -108,38 +115,32 @@ public abstract class AbstractCharAsyncE
         return null;
     }
 
-    private void checkResult(final CoderResult result) throws IOException {
-        if (result.isError()) {
-            result.throwException();
-        }
-    }
-
-    private void flushData(final DataStreamChannel channel) throws IOException {
-        if (!endStream) {
+    @Override
+    public final void produce(final DataStreamChannel channel) throws IOException {
+        if (state.compareTo(State.ACTIVE) == 0) {
             produceData(charDataStream);
         }
-        if (bytebuf.position() > 0) {
+        if (state.compareTo(State.ACTIVE) > 0 || !bytebuf.hasRemaining() || bytebuf.position() >= fragmentSizeHint) {
             bytebuf.flip();
             channel.write(bytebuf);
             bytebuf.compact();
         }
-        if (bytebuf.position() == 0 && endStream) {
-            channel.endStream();
+        if (state.compareTo(State.FLUSHING) == 0) {
+            final CoderResult result = charsetEncoder.encode(EMPTY, bytebuf, true);
+            if (result.isError()) {
+                result.throwException();
+            } else if (result.isUnderflow()) {
+                final CoderResult result2 = charsetEncoder.flush(bytebuf);
+                if (result2.isError()) {
+                    result.throwException();
+                } else if (result2.isUnderflow()) {
+                    state = State.END_STREAM;
+                }
+            }
         }
-    }
-
-    @Override
-    public void streamStart(final DataStreamChannel channel) throws IOException {
-        dataStart(charDataStream);
-        flushData(channel);
-    }
-
-    @Override
-    public final void produce(final DataStreamChannel channel) throws IOException {
-        if (!endStream) {
-            produceData(charDataStream);
+        if (bytebuf.position() == 0 && state.compareTo(State.END_STREAM) == 0) {
+            channel.endStream();
         }
-        flushData(channel);
     }
 
 }

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/AbstractCharAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java?rev=1767339&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java Mon Oct 31 17:33:27 2016
@@ -0,0 +1,133 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http.nio.entity;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public class BasicAsyncEntityProducer implements AsyncEntityProducer {
+
+    private final ByteBuffer bytebuf;
+    private final int length;
+    private final ContentType contentType;
+    private final AtomicReference<Exception> exception;
+
+    public BasicAsyncEntityProducer(final byte[] content, final ContentType contentType) {
+        Args.notNull(content, "Content");
+        this.bytebuf = ByteBuffer.wrap(content);
+        this.length = this.bytebuf.remaining();
+        this.contentType = contentType;
+        this.exception = new AtomicReference<>(null);
+    }
+
+    public BasicAsyncEntityProducer(final byte[] content) {
+        this(content, ContentType.APPLICATION_OCTET_STREAM);
+    }
+
+    public BasicAsyncEntityProducer(final CharSequence content, final ContentType contentType) {
+        Args.notNull(content, "Content");
+        this.contentType = contentType;
+        Charset charset = contentType != null ? contentType.getCharset() : null;
+        if (charset == null) {
+            charset = StandardCharsets.US_ASCII;
+        }
+        this.bytebuf = charset.encode(CharBuffer.wrap(content));
+        this.length = this.bytebuf.remaining();
+        this.exception = new AtomicReference<>(null);
+    }
+
+    public BasicAsyncEntityProducer(final CharSequence content) {
+        this(content, ContentType.TEXT_PLAIN);
+    }
+
+    @Override
+    public final String getContentType() {
+        return contentType != null ? contentType.toString() : null;
+    }
+
+    @Override
+    public long getContentLength() {
+        return length;
+    }
+
+    @Override
+    public int available() {
+        return Integer.MAX_VALUE;
+    }
+
+    @Override
+    public String getContentEncoding() {
+        return null;
+    }
+
+    @Override
+    public boolean isChunked() {
+        return false;
+    }
+
+    @Override
+    public Set<String> getTrailerNames() {
+        return null;
+    }
+
+    @Override
+    public final void produce(final DataStreamChannel channel) throws IOException {
+        channel.write(bytebuf);
+        if (!bytebuf.hasRemaining()) {
+            channel.endStream();
+        }
+    }
+
+    @Override
+    public final void failed(final Exception cause) {
+        if (exception.compareAndSet(null, cause)) {
+            releaseResources();
+        }
+    }
+
+    public final Exception getException() {
+        return exception.get();
+    }
+
+    @Override
+    public void releaseResources() {
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ContentInputBuffer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ContentInputBuffer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ContentInputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java Mon Oct 31 17:33:27 2016
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http.nio;
+package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
 

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputStream.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputStream.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputStream.java Mon Oct 31 17:33:27 2016
@@ -30,7 +30,6 @@ package org.apache.hc.core5.http.nio.ent
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.hc.core5.http.nio.ContentInputBuffer;
 import org.apache.hc.core5.util.Args;
 
 /**

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ContentOutputBuffer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ContentOutputBuffer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ContentOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java Mon Oct 31 17:33:27 2016
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http.nio;
+package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
 

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputStream.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputStream.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputStream.java Mon Oct 31 17:33:27 2016
@@ -30,7 +30,6 @@ package org.apache.hc.core5.http.nio.ent
 import java.io.IOException;
 import java.io.OutputStream;
 
-import org.apache.hc.core5.http.nio.ContentOutputBuffer;
 import org.apache.hc.core5.util.Args;
 
 /**

Added: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java?rev=1767339&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java Mon Oct 31 17:33:27 2016
@@ -0,0 +1,145 @@
+/*
+ * ====================================================================
+ * 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.hc.core5.http.nio.entity;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public class FileEntityProducer implements AsyncEntityProducer {
+
+    private final File file;
+    private final ByteBuffer bytebuf;
+    private final long length;
+    private final ContentType contentType;
+    private final AtomicReference<Exception> exception;
+
+    private RandomAccessFile accessFile;
+    private boolean eof;
+
+    public FileEntityProducer(final File file, final int bufferSize, final ContentType contentType) {
+        this.file = Args.notNull(file, "File");
+        this.length = file.length();
+        this.contentType = contentType;
+        this.exception = new AtomicReference<>(null);
+        this.bytebuf = ByteBuffer.allocate((int)(bufferSize > this.length ? bufferSize : this.length));
+    }
+
+    public FileEntityProducer(final File file, final ContentType contentType) {
+        this(file, 8192, contentType);
+    }
+
+    public FileEntityProducer(final File content) {
+        this(content, ContentType.APPLICATION_OCTET_STREAM);
+    }
+
+    @Override
+    public final String getContentType() {
+        return contentType != null ? contentType.toString() : null;
+    }
+
+    @Override
+    public long getContentLength() {
+        return length;
+    }
+
+    @Override
+    public int available() {
+        return Integer.MAX_VALUE;
+    }
+
+    @Override
+    public String getContentEncoding() {
+        return null;
+    }
+
+    @Override
+    public boolean isChunked() {
+        return false;
+    }
+
+    @Override
+    public Set<String> getTrailerNames() {
+        return null;
+    }
+
+    @Override
+    public final void produce(final DataStreamChannel channel) throws IOException {
+        if (accessFile == null) {
+            accessFile = new RandomAccessFile(file, "r");
+        }
+        if (!eof) {
+            final int bytesRead = accessFile.getChannel().read(bytebuf);
+            if (bytesRead < 0) {
+                eof = true;
+            }
+        }
+        if (bytebuf.position() > 0) {
+            bytebuf.flip();
+            channel.write(bytebuf);
+            bytebuf.compact();
+        }
+        if (eof && bytebuf.position() == 0) {
+            channel.endStream();
+            releaseResources();
+        }
+    }
+
+    @Override
+    public final void failed(final Exception cause) {
+        if (exception.compareAndSet(null, cause)) {
+            releaseResources();
+        }
+    }
+
+    public final Exception getException() {
+        return exception.get();
+    }
+
+    @Override
+    public void releaseResources() {
+        if (accessFile != null) {
+            try {
+                accessFile.close();
+            } catch (IOException ignore) {
+            }
+            accessFile = null;
+        }
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/FileEntityProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/NoopEntityConsumer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/NoopEntityConsumer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/NoopEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java Mon Oct 31 17:33:27 2016
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio.entity;
+package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -34,8 +34,8 @@ import org.apache.hc.core5.concurrent.Fu
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http2.nio.AsyncEntityConsumer;
-import org.apache.hc.core5.http2.nio.CapacityChannel;
+import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
 
 /**
  * @since 5.0
@@ -52,17 +52,13 @@ public final class NoopEntityConsumer im
     }
 
     @Override
-    public int capacity() {
-        return Integer.MAX_VALUE;
-    }
-
-    @Override
     public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
         capacityChannel.update(Integer.MAX_VALUE);
     }
 
     @Override
-    public final void consume(final ByteBuffer src) throws IOException {
+    public final int consume(final ByteBuffer src) throws IOException {
+        return Integer.MAX_VALUE;
     }
 
     @Override
@@ -73,6 +69,16 @@ public final class NoopEntityConsumer im
     }
 
     @Override
+    public void failed(final Exception cause) {
+        releaseResources();
+    }
+
+    @Override
+    public Void getContent() {
+        return null;
+    }
+
+    @Override
     public void releaseResources() {
     }
 

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/NoopEntityConsumer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/StringAsyncEntityConsumer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/StringAsyncEntityConsumer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/StringAsyncEntityConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java Mon Oct 31 17:33:27 2016
@@ -24,23 +24,24 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio.entity;
+package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
 import java.nio.CharBuffer;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http2.nio.CapacityChannel;
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.nio.CapacityChannel;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.Asserts;
 import org.apache.hc.core5.util.CharArrayBuffer;
 
 public class StringAsyncEntityConsumer extends AbstractCharAsyncEntityConsumer<String> {
 
     private final int capacityIncrement;
     private final CharArrayBuffer content;
+    private final AtomicReference<Exception> exception;
 
     private FutureCallback<String> resultCallback;
 
@@ -48,6 +49,7 @@ public class StringAsyncEntityConsumer e
         Args.positive(capacityIncrement, "Capacity increment");
         this.capacityIncrement = capacityIncrement;
         this.content = new CharArrayBuffer(1024);
+        this.exception = new AtomicReference<>(null);
     }
 
     public StringAsyncEntityConsumer() {
@@ -55,11 +57,6 @@ public class StringAsyncEntityConsumer e
     }
 
     @Override
-    public int capacity() {
-        return capacityIncrement;
-    }
-
-    @Override
     public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
         capacityChannel.update(capacityIncrement);
     }
@@ -81,8 +78,28 @@ public class StringAsyncEntityConsumer e
 
     @Override
     protected void dataEnd() throws IOException {
-        Asserts.notNull(resultCallback, "Result callback");
-        resultCallback.completed(content.toString());
+        if (resultCallback != null) {
+            resultCallback.completed(content.toString());
+        }
+    }
+
+    @Override
+    public void failed(final Exception cause) {
+        if (exception.compareAndSet(null, cause)) {
+            if (resultCallback != null) {
+                resultCallback.failed(cause);
+            }
+            releaseResources();
+        }
+    }
+
+    public Exception getException() {
+        return exception.get();
+    }
+
+    @Override
+    public String getContent() {
+        return content.toString();
     }
 
     @Override

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityConsumer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityProducer.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/StringAsyncEntityProducer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityProducer.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityProducer.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/StringAsyncEntityProducer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/StringAsyncEntityProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityProducer.java Mon Oct 31 17:33:27 2016
@@ -24,37 +24,48 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio.entity;
+package org.apache.hc.core5.http.nio.entity;
 
 import java.io.IOException;
 import java.nio.CharBuffer;
+import java.util.concurrent.atomic.AtomicReference;
 
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http2.nio.StreamChannel;
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.nio.StreamChannel;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
 
 public class StringAsyncEntityProducer extends AbstractCharAsyncEntityProducer {
 
     private final CharBuffer content;
+    private final AtomicReference<Exception> exception;
 
-    public StringAsyncEntityProducer(final CharSequence content, final int bufferSize, final ContentType contentType) {
-        super(bufferSize, contentType);
+    public StringAsyncEntityProducer(
+            final CharSequence content,
+            final int bufferSize,
+            final int fragmentSizeHint,
+            final ContentType contentType) {
+        super(bufferSize, fragmentSizeHint, contentType);
         Args.notNull(content, "Content");
         this.content = CharBuffer.wrap(content);
+        this.exception = new AtomicReference<>(null);
+    }
+
+    public StringAsyncEntityProducer(final CharSequence content, final int bufferSize, final ContentType contentType) {
+        this(content, bufferSize, -1, contentType);
     }
 
     public StringAsyncEntityProducer(final CharSequence content, final ContentType contentType) {
         this(content, 4096, contentType);
     }
 
-    @Override
-    public long getContentLength() {
-        return -1;
+    public StringAsyncEntityProducer(final CharSequence content) {
+        this(content, ContentType.TEXT_PLAIN);
     }
 
     @Override
-    protected void dataStart(final StreamChannel<CharBuffer> channel) throws IOException {
+    public long getContentLength() {
+        return -1;
     }
 
     @Override
@@ -64,7 +75,7 @@ public class StringAsyncEntityProducer e
 
     @Override
     protected void produceData(final StreamChannel<CharBuffer> channel) throws IOException {
-        Asserts.notNull(channel, "StreamChannel");
+        Asserts.notNull(channel, "Channel");
         channel.write(content);
         if (!content.hasRemaining()) {
             channel.endStream();
@@ -72,6 +83,17 @@ public class StringAsyncEntityProducer e
     }
 
     @Override
+    public void failed(final Exception cause) {
+        if (exception.compareAndSet(null, cause)) {
+            releaseResources();
+        }
+    }
+
+    public Exception getException() {
+        return exception.get();
+    }
+
+    @Override
     public void releaseResources() {
     }
 

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/StringAsyncEntityProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicServerExchangeHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicServerExchangeHandler.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicServerExchangeHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java Mon Oct 31 17:33:27 2016
@@ -24,12 +24,11 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.nio.support;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.hc.core5.concurrent.FutureCallback;
@@ -38,36 +37,52 @@ import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.Message;
-import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.http.nio.AsyncPushProducer;
+import org.apache.hc.core5.http.nio.AsyncRequestConsumer;
+import org.apache.hc.core5.http.nio.AsyncResponseProducer;
+import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
+import org.apache.hc.core5.http.nio.BasicResponseProducer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.http.nio.ExpectationChannel;
+import org.apache.hc.core5.http.nio.ResponseChannel;
+import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.util.Asserts;
 
 /**
  * @since 5.0
  */
-public class BasicServerExchangeHandler<T> implements AsyncServerExchangeHandler {
+public abstract class AbstractServerExchangeHandler<T> implements AsyncServerExchangeHandler {
 
-    private final AsyncRequestConsumer<Message<HttpRequest, T>> requestConsumer;
-    private final AtomicReference<AsyncResponseProducer> responseProducer;
-    private final AtomicBoolean dataStarted;
+    private final AtomicReference<AsyncRequestConsumer<T>> requestConsumerRef;
+    private final AtomicReference<AsyncResponseProducer> responseProducerRef;
 
-    public BasicServerExchangeHandler(final AsyncRequestConsumer<Message<HttpRequest, T>> requestConsumer) {
-        this.requestConsumer = Args.notNull(requestConsumer, "Request consumer");
-        this.responseProducer = new AtomicReference<>(null);
-        this.dataStarted = new AtomicBoolean(false);
-    }
+    private volatile HttpContext context;
+    private volatile boolean expectationFailed;
 
-    public BasicServerExchangeHandler(final AsyncEntityConsumer<T> requestEntityConsumer) {
-        this(new BasicRequestConsumer<>(requestEntityConsumer));
+    public AbstractServerExchangeHandler() {
+        this.requestConsumerRef = new AtomicReference<>(null);
+        this.responseProducerRef = new AtomicReference<>(null);
     }
 
-    protected AsyncResponseProducer verify(final HttpRequest request) throws IOException, HttpException {
+    protected AsyncResponseProducer verify(
+            final HttpRequest request,
+            final HttpContext context) throws IOException, HttpException {
         return null;
     }
 
-    protected void handle(
-            final Message<HttpRequest, T> request, final AsyncResponseTrigger responseTrigger) throws IOException, HttpException {
-        responseTrigger.submitResponse(new BasicResponseProducer(HttpStatus.SC_OK, "OK"));
+    protected abstract AsyncRequestConsumer<T> supplyConsumer(
+            HttpRequest request,
+            HttpContext context) throws HttpException;
+
+    protected abstract void handle(
+            T requestMessage,
+            ResponseTrigger responseTrigger,
+            HttpContext context) throws HttpException, IOException;
+
+    @Override
+    public void setContext(final HttpContext context) {
+        this.context = context;
     }
 
     @Override
@@ -75,9 +90,10 @@ public class BasicServerExchangeHandler<
             final HttpRequest request,
             final EntityDetails entityDetails,
             final ExpectationChannel expectationChannel) throws HttpException, IOException {
-        final AsyncResponseProducer producer = verify(request);
+        final AsyncResponseProducer producer = verify(request, context);
         if (producer != null) {
-            responseProducer.set(producer);
+            expectationFailed = true;
+            responseProducerRef.set(producer);
             expectationChannel.sendResponse(producer.produceResponse(), producer.getEntityDetails());
         } else {
             expectationChannel.sendContinue();
@@ -90,17 +106,18 @@ public class BasicServerExchangeHandler<
             final EntityDetails entityDetails,
             final ResponseChannel responseChannel) throws HttpException, IOException {
 
-        final AsyncResponseTrigger responseTrigger = new AsyncResponseTrigger() {
+        final AsyncRequestConsumer<T> requestConsumer = supplyConsumer(request, context);
+        if (requestConsumer == null) {
+            throw new HttpException("Unable to handle request");
+        }
+        requestConsumerRef.set(requestConsumer);
+        final ResponseTrigger responseTrigger = new ResponseTrigger() {
 
             @Override
             public void submitResponse(
                     final AsyncResponseProducer producer) throws HttpException, IOException {
-                try {
-                    if (responseProducer.compareAndSet(null, producer)) {
-                        responseChannel.sendResponse(producer.produceResponse(), producer.getEntityDetails());
-                    }
-                } finally {
-                    requestConsumer.releaseResources();
+                if (responseProducerRef.compareAndSet(null, producer)) {
+                    responseChannel.sendResponse(producer.produceResponse(), producer.getEntityDetails());
                 }
             }
 
@@ -116,12 +133,12 @@ public class BasicServerExchangeHandler<
             }
 
         };
-        requestConsumer.consumeRequest(request, entityDetails, new FutureCallback<Message<HttpRequest, T>>() {
+        requestConsumer.consumeRequest(request, entityDetails, new FutureCallback<T>() {
 
             @Override
-            public void completed(final Message<HttpRequest, T> message) {
+            public void completed(final T result) {
                 try {
-                    handle(message, responseTrigger);
+                    handle(result, responseTrigger, context);
                 } catch (HttpException ex) {
                     try {
                         responseTrigger.submitResponse(
@@ -136,8 +153,7 @@ public class BasicServerExchangeHandler<
 
             @Override
             public void failed(final Exception ex) {
-                BasicServerExchangeHandler.this.failed(ex);
-                releaseResources();
+                AbstractServerExchangeHandler.this.failed(ex);
             }
 
             @Override
@@ -150,55 +166,72 @@ public class BasicServerExchangeHandler<
     }
 
     @Override
-    public final int capacity() {
-        return requestConsumer.capacity();
-    }
-
-    @Override
     public final void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
-        requestConsumer.updateCapacity(capacityChannel);
+        if (!expectationFailed) {
+            final AsyncRequestConsumer<T> requestConsumer = requestConsumerRef.get();
+            Asserts.notNull(requestConsumer, "Data consumer");
+            requestConsumer.updateCapacity(capacityChannel);
+        } else {
+            capacityChannel.update(Integer.MAX_VALUE);
+        }
     }
 
     @Override
-    public final void consume(final ByteBuffer src) throws IOException {
-        requestConsumer.consume(src);
+    public final int consume(final ByteBuffer src) throws IOException {
+        if (!expectationFailed) {
+            final AsyncRequestConsumer<T> requestConsumer = requestConsumerRef.get();
+            Asserts.notNull(requestConsumer, "Data consumer");
+            return requestConsumer.consume(src);
+        } else {
+            return Integer.MAX_VALUE;
+        }
     }
 
     @Override
     public final void streamEnd(final List<Header> trailers) throws HttpException, IOException {
-        requestConsumer.streamEnd(trailers);
+        if (!expectationFailed) {
+            final AsyncRequestConsumer<T> requestConsumer = requestConsumerRef.get();
+            Asserts.notNull(requestConsumer, "Data consumer");
+            requestConsumer.streamEnd(trailers);
+        }
     }
 
     @Override
     public final int available() {
-        final AsyncResponseProducer dataProducer = responseProducer.get();
+        final AsyncResponseProducer dataProducer = responseProducerRef.get();
         return dataProducer != null ? dataProducer.available() : 0;
     }
 
     @Override
     public final void produce(final DataStreamChannel channel) throws IOException {
-        final AsyncResponseProducer dataProducer = responseProducer.get();
+        final AsyncResponseProducer dataProducer = responseProducerRef.get();
         Asserts.notNull(dataProducer, "Data producer");
-        if (dataStarted.compareAndSet(false, true)) {
-            dataProducer.dataStart(channel);
-        }
         dataProducer.produce(channel);
     }
 
     @Override
     public final void failed(final Exception cause) {
-        requestConsumer.failed(cause);
-        final AsyncResponseProducer dataProducer = responseProducer.get();
-        if (dataProducer != null) {
-            dataProducer.failed(cause);
+        try {
+            final AsyncRequestConsumer<T> requestConsumer = requestConsumerRef.get();
+            if (requestConsumer != null) {
+                requestConsumer.failed(cause);
+            }
+            final AsyncResponseProducer dataProducer = responseProducerRef.get();
+            if (dataProducer != null) {
+                dataProducer.failed(cause);
+            }
+        } finally {
+            releaseResources();
         }
-        releaseResources();
     }
 
     @Override
     public final void releaseResources() {
-        requestConsumer.releaseResources();
-        final AsyncResponseProducer dataProducer = responseProducer.get();
+        final AsyncRequestConsumer<T> requestConsumer = requestConsumerRef.getAndSet(null);
+        if (requestConsumer != null) {
+            requestConsumer.releaseResources();
+        }
+        final AsyncResponseProducer dataProducer = responseProducerRef.getAndSet(null);
         if (dataProducer != null) {
             dataProducer.releaseResources();
         }

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractServerExchangeHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncPushHandler.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicAsyncPushHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncPushHandler.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncPushHandler.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicAsyncPushHandler.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicAsyncPushHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncPushHandler.java Mon Oct 31 17:33:27 2016
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.nio.support;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -38,6 +38,9 @@ import org.apache.hc.core5.http.HttpExce
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.nio.AsyncPushConsumer;
+import org.apache.hc.core5.http.nio.AsyncResponseConsumer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -88,18 +91,13 @@ public class BasicAsyncPushHandler<T> im
     }
 
     @Override
-    public int capacity() {
-        return responseConsumer.capacity();
-    }
-
-    @Override
     public final void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
         responseConsumer.updateCapacity(capacityChannel);
     }
 
     @Override
-    public final void consume(final ByteBuffer src) throws IOException {
-        responseConsumer.consume(src);
+    public final int consume(final ByteBuffer src) throws IOException {
+        return responseConsumer.consume(src);
     }
 
     @Override

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncPushHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncPushHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncPushHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicClientExchangeHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicClientExchangeHandler.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/BasicClientExchangeHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java Mon Oct 31 17:33:27 2016
@@ -24,7 +24,7 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.nio.support;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -38,6 +38,12 @@ import org.apache.hc.core5.http.HttpExce
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
+import org.apache.hc.core5.http.nio.AsyncRequestProducer;
+import org.apache.hc.core5.http.nio.AsyncResponseConsumer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.http.nio.RequestChannel;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -48,7 +54,6 @@ public class BasicClientExchangeHandler<
     private final AsyncRequestProducer requestProducer;
     private final AsyncResponseConsumer<T> responseConsumer;
     private final FutureCallback<T> resultCallback;
-    private final AtomicBoolean dataStarted;
     private final AtomicBoolean outputTerminated;
 
     public BasicClientExchangeHandler(
@@ -58,12 +63,11 @@ public class BasicClientExchangeHandler<
         this.requestProducer = Args.notNull(requestProducer, "Request producer");
         this.responseConsumer = Args.notNull(responseConsumer, "Response consumer");
         this.resultCallback = resultCallback;
-        this.dataStarted = new AtomicBoolean(false);
         this.outputTerminated = new AtomicBoolean(false);
     }
 
     @Override
-    public void submitRequest(final RequestChannel requestChannel) throws HttpException, IOException {
+    public void produceRequest(final RequestChannel requestChannel) throws HttpException, IOException {
         final HttpRequest request = requestProducer.produceRequest();
         final EntityDetails entityDetails = requestProducer.getEntityDetails();
         requestChannel.sendRequest(request, entityDetails);
@@ -80,9 +84,6 @@ public class BasicClientExchangeHandler<
             channel.endStream();
             return;
         }
-        if (this.dataStarted.compareAndSet(false, true)) {
-            requestProducer.dataStart(channel);
-        }
         requestProducer.produce(channel);
     }
 
@@ -120,22 +121,20 @@ public class BasicClientExchangeHandler<
 
     @Override
     public void cancel() {
+        if (resultCallback != null) {
+            resultCallback.cancelled();
+        }
         releaseResources();
     }
 
     @Override
-    public int capacity() {
-        return responseConsumer.capacity();
-    }
-
-    @Override
     public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
         responseConsumer.updateCapacity(capacityChannel);
     }
 
     @Override
-    public void consume(final ByteBuffer src) throws IOException {
-        responseConsumer.consume(src);
+    public int consume(final ByteBuffer src) throws IOException {
+        return responseConsumer.consume(src);
     }
 
     @Override
@@ -145,6 +144,9 @@ public class BasicClientExchangeHandler<
 
     @Override
     public final void failed(final Exception cause) {
+        if (resultCallback != null) {
+            resultCallback.failed(cause);
+        }
         requestProducer.failed(cause);
         responseConsumer.failed(cause);
         releaseResources();

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicClientExchangeHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/FixedResponseExchangeHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/FixedResponseExchangeHandler.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/FixedResponseExchangeHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java Mon Oct 31 17:33:27 2016
@@ -24,45 +24,45 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio;
+package org.apache.hc.core5.http.nio.support;
 
 import java.io.IOException;
 
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.Message;
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http.message.BasicHttpResponse;
-import org.apache.hc.core5.http2.nio.entity.NoopEntityConsumer;
-import org.apache.hc.core5.http2.nio.entity.StringAsyncEntityProducer;
+import org.apache.hc.core5.http.nio.AsyncRequestConsumer;
+import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.util.Args;
 
 /**
  * @since 5.0
  */
-public final class FixedResponseExchangeHandler extends BasicServerExchangeHandler<Void> {
+public class BasicServerExchangeHandler<T> extends AbstractServerExchangeHandler<T> {
 
-    private final AsyncResponseProducer responseProducer;
+    private final RequestConsumerSupplier<T> consumerSupplier;
+    private final ResponseHandler<T> responseHandler;
 
-    public FixedResponseExchangeHandler(final AsyncResponseProducer responseProducer) {
-        super(new NoopEntityConsumer());
-        this.responseProducer = Args.notNull(responseProducer, "Response producer");
+    public BasicServerExchangeHandler(
+            final RequestConsumerSupplier<T> consumerSupplier,
+            final ResponseHandler<T> responseHandler) {
+        super();
+        this.consumerSupplier = Args.notNull(consumerSupplier, "Consumer supplier");
+        this.responseHandler = Args.notNull(responseHandler, "Response handler");
     }
 
-    public FixedResponseExchangeHandler(final HttpResponse response, final String message) {
-        this(new BasicResponseProducer(response, new StringAsyncEntityProducer(message, ContentType.TEXT_PLAIN)));
-    }
-
-    public FixedResponseExchangeHandler(final int status, final String message) {
-        this(new BasicHttpResponse(status), message);
+    @Override
+    protected AsyncRequestConsumer<T> supplyConsumer(
+            final HttpRequest request,
+            final HttpContext context) throws HttpException {
+        return consumerSupplier.get(request, context);
     }
 
     @Override
     protected void handle(
-            final Message<HttpRequest, Void> request,
-            final AsyncResponseTrigger responseTrigger) throws IOException, HttpException {
-        responseTrigger.submitResponse(responseProducer);
+            final T requestMessage,
+            final ResponseTrigger responseTrigger,
+            final HttpContext context) throws HttpException, IOException {
+        responseHandler.handle(requestMessage, responseTrigger, context);
     }
 
 }

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicServerExchangeHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain




Mime
View raw message