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 2014/09/29 11:56:37 UTC
svn commit: r1628148 - in
/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods:
AsyncByteConsumer.java AsyncCharConsumer.java
Author: olegk
Date: Mon Sep 29 09:56:37 2014
New Revision: 1628148
URL: http://svn.apache.org/r1628148
Log:
Eliminated looping in content received event (input ready loop is now performed by the I/O reactor)
Modified:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java?rev=1628148&r1=1628147&r2=1628148&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java Mon Sep 29 09:56:37 2014
@@ -28,15 +28,12 @@ package org.apache.http.nio.client.metho
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.nio.channels.SelectionKey;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.IOControl;
-import org.apache.http.nio.conn.ManagedNHttpClientConnection;
import org.apache.http.nio.protocol.AbstractAsyncResponseConsumer;
-import org.apache.http.nio.reactor.IOSession;
import org.apache.http.util.Asserts;
/**
@@ -80,32 +77,13 @@ public abstract class AsyncByteConsumer<
protected final void onContentReceived(
final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
Asserts.notNull(this.bbuf, "Byte buffer");
-
- //FIXME: IOControl needs to expose event mask in order to avoid this extreme ugliness
- final IOSession iosession;
- if (ioctrl instanceof ManagedNHttpClientConnection) {
- final ManagedNHttpClientConnection conn = (ManagedNHttpClientConnection) ioctrl;
- iosession = conn != null ? conn.getIOSession() : null;
- } else {
- iosession = null;
- }
- while (!this.isDone()) {
- final int bytesRead = decoder.read(this.bbuf);
- if (bytesRead <= 0) {
- break;
- }
- this.bbuf.flip();
- onByteReceived(this.bbuf, ioctrl);
- this.bbuf.clear();
- if (decoder.isCompleted()) {
- break;
- } else {
- if (iosession != null && (iosession.isClosed()
- || (iosession.getEventMask() & SelectionKey.OP_READ) == 0)) {
- break;
- }
- }
+ final int bytesRead = decoder.read(this.bbuf);
+ if (bytesRead <= 0) {
+ return;
}
+ this.bbuf.flip();
+ onByteReceived(this.bbuf, ioctrl);
+ this.bbuf.clear();
}
@Override
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java?rev=1628148&r1=1628147&r2=1628148&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java Mon Sep 29 09:56:37 2014
@@ -29,7 +29,6 @@ package org.apache.http.nio.client.metho
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
-import java.nio.channels.SelectionKey;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
@@ -38,9 +37,7 @@ import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.IOControl;
-import org.apache.http.nio.conn.ManagedNHttpClientConnection;
import org.apache.http.nio.protocol.AbstractAsyncResponseConsumer;
-import org.apache.http.nio.reactor.IOSession;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.Asserts;
@@ -97,34 +94,18 @@ public abstract class AsyncCharConsumer<
final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
Asserts.notNull(this.bbuf, "Byte buffer");
- //FIXME: IOControl needs to expose event mask in order to avoid this extreme ugliness
- final IOSession iosession;
- if (ioctrl instanceof ManagedNHttpClientConnection) {
- final ManagedNHttpClientConnection conn = (ManagedNHttpClientConnection) ioctrl;
- iosession = conn != null ? conn.getIOSession() : null;
- } else {
- iosession = null;
+ final int bytesRead = decoder.read(this.bbuf);
+ if (bytesRead <= 0) {
+ return;
}
- while (!this.isDone()) {
- final int bytesRead = decoder.read(this.bbuf);
- if (bytesRead <= 0) {
- break;
- }
- this.bbuf.flip();
- final boolean completed = decoder.isCompleted();
- CoderResult result = this.chardecoder.decode(this.bbuf, this.cbuf, completed);
+ this.bbuf.flip();
+ final boolean completed = decoder.isCompleted();
+ CoderResult result = this.chardecoder.decode(this.bbuf, this.cbuf, completed);
+ handleDecodingResult(result, ioctrl);
+ this.bbuf.compact();
+ if (completed) {
+ result = this.chardecoder.flush(this.cbuf);
handleDecodingResult(result, ioctrl);
- this.bbuf.compact();
- if (completed) {
- result = this.chardecoder.flush(this.cbuf);
- handleDecodingResult(result, ioctrl);
- break;
- } else {
- if (iosession != null && (iosession.isClosed() ||
- (iosession.getEventMask() & SelectionKey.OP_READ) == 0)) {
- break;
- }
- }
}
}