You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2018/08/04 20:24:27 UTC
[09/19] httpcomponents-core git commit: * Refactor timeout APIs to
include the actual timeout value. * Refactor timeout APIs to include the
scale in the method name;
for example 'int getSocketTimeout()' vs. int 'getSocketTimeoutMillis()'.
* Refactor timeout APIs to include the actual timeout value.
* Refactor timeout APIs to include the scale in the method name; for
example 'int getSocketTimeout()' vs. int 'getSocketTimeoutMillis()'.
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/d01b7ec0
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/d01b7ec0
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/d01b7ec0
Branch: refs/heads/master
Commit: d01b7ec0787d032931deea9b137439d32ff662d8
Parents: 872dcf2
Author: Gary Gregory <gg...@apache.org>
Authored: Sat Aug 4 08:25:52 2018 -0600
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sat Aug 4 17:27:35 2018 +0200
----------------------------------------------------------------------
RELEASE_NOTES.txt | 6 ++
.../impl/nio/AbstractHttp2IOEventHandler.java | 12 ++--
.../nio/AbstractHttp2StreamMultiplexer.java | 20 +++++--
.../impl/nio/ClientHttpProtocolNegotiator.java | 10 ++--
.../nio/Http2OnlyClientProtocolNegotiator.java | 10 ++--
.../impl/nio/ServerHttpProtocolNegotiator.java | 10 ++--
.../nio/TestDefaultListeningIOReactor.java | 2 +-
.../apache/hc/core5/http/HttpConnection.java | 4 +-
.../core5/http/impl/io/BHttpConnectionBase.java | 4 +-
.../impl/nio/AbstractHttp1IOEventHandler.java | 12 ++--
.../impl/nio/AbstractHttp1StreamDuplexer.java | 10 ++--
.../impl/nio/ClientHttp1StreamDuplexer.java | 4 +-
.../http/impl/nio/ClientHttp1StreamHandler.java | 8 +--
.../core5/http/impl/nio/Http1StreamChannel.java | 4 +-
.../impl/nio/ServerHttp1StreamDuplexer.java | 12 ++--
.../apache/hc/core5/reactor/IOEventHandler.java | 3 +-
.../hc/core5/reactor/InternalChannel.java | 12 ++--
.../core5/reactor/InternalConnectChannel.java | 8 +--
.../hc/core5/reactor/InternalDataChannel.java | 6 +-
.../util/SocketTimeoutExceptionFactory.java | 58 ++++++++++++++++++++
.../http/impl/io/TestBHttpConnectionBase.java | 12 ++--
21 files changed, 150 insertions(+), 77 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index d55f155..b8a1fa3 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -52,6 +52,12 @@ adds several incremental improvements.
* Refactor duplicate messages into a new 0-arg constructor for org.apache.hc.core5.http.StreamClosedException.
Contributed by Gary Gregory <ggregory at apache.org>
+* Refactor timeout APIs to include the actual timeout value.
+ Contributed by Gary Gregory <ggregory at apache.org>
+
+* Refactor timeout APIs to include the scale in the method name; for example 'int getSocketTimeout()' vs. int 'getSocketTimeoutMillis()'.
+ Contributed by Gary Gregory <ggregory at apache.org>
+
Release 5.0-BETA2
-------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java
index 24c2967..d79914d 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2IOEventHandler.java
@@ -76,9 +76,9 @@ class AbstractHttp2IOEventHandler implements HttpConnectionEventHandler {
}
@Override
- public void timeout(final IOSession session) throws IOException {
+ public void timeout(final IOSession session, final int timeoutMillis) throws IOException {
try {
- streamMultiplexer.onTimeout();
+ streamMultiplexer.onTimeout(timeoutMillis);
} catch (final HttpException ex) {
streamMultiplexer.onException(ex);
}
@@ -110,8 +110,8 @@ class AbstractHttp2IOEventHandler implements HttpConnectionEventHandler {
}
@Override
- public void setSocketTimeout(final int timeout) {
- streamMultiplexer.setSocketTimeout(timeout);
+ public void setSocketTimeoutMillis(final int timeout) {
+ streamMultiplexer.setSocketTimeoutMillis(timeout);
}
@Override
@@ -125,8 +125,8 @@ class AbstractHttp2IOEventHandler implements HttpConnectionEventHandler {
}
@Override
- public int getSocketTimeout() {
- return streamMultiplexer.getSocketTimeout();
+ public int getSocketTimeoutMillis() {
+ return streamMultiplexer.getSocketTimeoutMillis();
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
index 572ff8c..6d73284 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
@@ -90,6 +90,7 @@ import org.apache.hc.core5.reactor.ssl.TlsDetails;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.ByteArrayBuffer;
import org.apache.hc.core5.util.Identifiable;
+import org.apache.hc.core5.util.SocketTimeoutExceptionFactory;
abstract class AbstractHttp2StreamMultiplexer implements Identifiable, HttpConnection {
@@ -528,20 +529,27 @@ abstract class AbstractHttp2StreamMultiplexer implements Identifiable, HttpConne
}
}
- public final void onTimeout() throws HttpException, IOException {
+ public final void onTimeout(final int timeoutMillis) throws HttpException, IOException {
connState = ConnectionHandshake.SHUTDOWN;
final RawFrame goAway;
if (localSettingState != SettingsHandshake.ACKED) {
- goAway = frameFactory.createGoAway(processedRemoteStreamId, H2Error.SETTINGS_TIMEOUT, "Setting timeout");
+ goAway = frameFactory.createGoAway(processedRemoteStreamId, H2Error.SETTINGS_TIMEOUT,
+ "Setting timeout ("
+ + SocketTimeoutExceptionFactory.toMessage(timeoutMillis)
+ + ")");
} else {
- goAway = frameFactory.createGoAway(processedRemoteStreamId, H2Error.NO_ERROR, "Timeout due to inactivity");
+ goAway = frameFactory.createGoAway(processedRemoteStreamId, H2Error.NO_ERROR,
+ "Timeout due to inactivity "
+ + SocketTimeoutExceptionFactory.toMessage(timeoutMillis)
+ + ")");
}
commitFrame(goAway);
for (final Iterator<Map.Entry<Integer, Http2Stream>> it = streamMap.entrySet().iterator(); it.hasNext(); ) {
final Map.Entry<Integer, Http2Stream> entry = it.next();
final Http2Stream stream = entry.getValue();
- stream.reset(new H2StreamResetException(H2Error.NO_ERROR, "Timeout due to inactivity"));
+ stream.reset(new H2StreamResetException(H2Error.NO_ERROR, "Timeout due to inactivity ("
+ + SocketTimeoutExceptionFactory.toMessage(timeoutMillis) + ")"));
}
streamMap.clear();
}
@@ -1198,7 +1206,7 @@ abstract class AbstractHttp2StreamMultiplexer implements Identifiable, HttpConne
}
@Override
- public void setSocketTimeout(final int timeout) {
+ public void setSocketTimeoutMillis(final int timeout) {
ioSession.setSocketTimeout(timeout);
}
@@ -1218,7 +1226,7 @@ abstract class AbstractHttp2StreamMultiplexer implements Identifiable, HttpConne
}
@Override
- public int getSocketTimeout() {
+ public int getSocketTimeoutMillis() {
return ioSession.getSocketTimeout();
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
index b8f8fa7..62d3d1d 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
@@ -29,7 +29,6 @@ package org.apache.hc.core5.http2.impl.nio;
import java.io.IOException;
import java.net.SocketAddress;
-import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
@@ -55,6 +54,7 @@ import org.apache.hc.core5.reactor.IOSession;
import org.apache.hc.core5.reactor.ProtocolIOSession;
import org.apache.hc.core5.reactor.ssl.TlsDetails;
import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.SocketTimeoutExceptionFactory;
/**
* @since 5.0
@@ -160,8 +160,8 @@ public class ClientHttpProtocolNegotiator implements HttpConnectionEventHandler
}
@Override
- public void timeout(final IOSession session) {
- exception(session, new SocketTimeoutException());
+ public void timeout(final IOSession session, final int timeoutMillis) {
+ exception(session, SocketTimeoutExceptionFactory.create(timeoutMillis));
}
@Override
@@ -218,12 +218,12 @@ public class ClientHttpProtocolNegotiator implements HttpConnectionEventHandler
}
@Override
- public void setSocketTimeout(final int timeout) {
+ public void setSocketTimeoutMillis(final int timeout) {
ioSession.setSocketTimeout(timeout);
}
@Override
- public int getSocketTimeout() {
+ public int getSocketTimeoutMillis() {
return ioSession.getSocketTimeout();
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/Http2OnlyClientProtocolNegotiator.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/Http2OnlyClientProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/Http2OnlyClientProtocolNegotiator.java
index 04957d4..286ec02 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/Http2OnlyClientProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/Http2OnlyClientProtocolNegotiator.java
@@ -29,7 +29,6 @@ package org.apache.hc.core5.http2.impl.nio;
import java.io.IOException;
import java.net.SocketAddress;
-import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
@@ -52,6 +51,7 @@ import org.apache.hc.core5.reactor.IOSession;
import org.apache.hc.core5.reactor.ProtocolIOSession;
import org.apache.hc.core5.reactor.ssl.TlsDetails;
import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.SocketTimeoutExceptionFactory;
import org.apache.hc.core5.util.TextUtils;
/**
@@ -132,8 +132,8 @@ public class Http2OnlyClientProtocolNegotiator implements HttpConnectionEventHan
}
@Override
- public void timeout(final IOSession session) {
- exception(session, new SocketTimeoutException());
+ public void timeout(final IOSession session, final int timeoutMillis) {
+ exception(session, SocketTimeoutExceptionFactory.create(timeoutMillis));
}
@Override
@@ -190,12 +190,12 @@ public class Http2OnlyClientProtocolNegotiator implements HttpConnectionEventHan
}
@Override
- public void setSocketTimeout(final int timeout) {
+ public void setSocketTimeoutMillis(final int timeout) {
ioSession.setSocketTimeout(timeout);
}
@Override
- public int getSocketTimeout() {
+ public int getSocketTimeoutMillis() {
return ioSession.getSocketTimeout();
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
index afa1839..18c70d9 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
@@ -29,7 +29,6 @@ package org.apache.hc.core5.http2.impl.nio;
import java.io.IOException;
import java.net.SocketAddress;
-import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import javax.net.ssl.SSLSession;
@@ -52,6 +51,7 @@ import org.apache.hc.core5.reactor.IOSession;
import org.apache.hc.core5.reactor.ProtocolIOSession;
import org.apache.hc.core5.reactor.ssl.TlsDetails;
import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.SocketTimeoutExceptionFactory;
/**
* @since 5.0
@@ -161,8 +161,8 @@ public class ServerHttpProtocolNegotiator implements HttpConnectionEventHandler
}
@Override
- public void timeout(final IOSession session) {
- exception(session, new SocketTimeoutException());
+ public void timeout(final IOSession session, final int timeoutMillis) {
+ exception(session, SocketTimeoutExceptionFactory.create(timeoutMillis));
}
@Override
@@ -186,12 +186,12 @@ public class ServerHttpProtocolNegotiator implements HttpConnectionEventHandler
}
@Override
- public void setSocketTimeout(final int timeout) {
+ public void setSocketTimeoutMillis(final int timeout) {
ioSession.setSocketTimeout(timeout);
}
@Override
- public int getSocketTimeout() {
+ public int getSocketTimeoutMillis() {
return ioSession.getSocketTimeout();
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
index 3ce6bff..629847d 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
@@ -73,7 +73,7 @@ public class TestDefaultListeningIOReactor {
}
@Override
- public void timeout(final IOSession session) {
+ public void timeout(final IOSession session, final int timeoutMillis) {
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/http/HttpConnection.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpConnection.java b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpConnection.java
index 5523e68..b65856f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpConnection.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpConnection.java
@@ -72,7 +72,7 @@ public interface HttpConnection extends ModalCloseable {
*
* @param timeout timeout value in milliseconds
*/
- void setSocketTimeout(int timeout);
+ void setSocketTimeoutMillis(int timeout);
/**
* Returns the socket timeout value.
@@ -81,7 +81,7 @@ public interface HttpConnection extends ModalCloseable {
* {@code 0} if timeout is disabled or {@code -1} if
* timeout is undefined.
*/
- int getSocketTimeout();
+ int getSocketTimeoutMillis();
/**
* Returns protocol version used by this connection or {@code null} if unknown.
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
index 628c39c..1ce2083 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/BHttpConnectionBase.java
@@ -191,7 +191,7 @@ class BHttpConnectionBase implements BHttpConnection {
}
@Override
- public void setSocketTimeout(final int timeout) {
+ public void setSocketTimeoutMillis(final int timeout) {
final SocketHolder socketHolder = this.socketHolderRef.get();
if (socketHolder != null) {
try {
@@ -205,7 +205,7 @@ class BHttpConnectionBase implements BHttpConnection {
}
@Override
- public int getSocketTimeout() {
+ public int getSocketTimeoutMillis() {
final SocketHolder socketHolder = this.socketHolderRef.get();
if (socketHolder != null) {
try {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
index 37113ab..f90e164 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
@@ -75,9 +75,9 @@ class AbstractHttp1IOEventHandler implements HttpConnectionEventHandler {
}
@Override
- public void timeout(final IOSession session) throws IOException {
+ public void timeout(final IOSession session, final int timeoutMillis) throws IOException {
try {
- streamDuplexer.onTimeout();
+ streamDuplexer.onTimeout(timeoutMillis);
} catch (final HttpException ex) {
streamDuplexer.onException(ex);
}
@@ -109,8 +109,8 @@ class AbstractHttp1IOEventHandler implements HttpConnectionEventHandler {
}
@Override
- public void setSocketTimeout(final int timeout) {
- streamDuplexer.setSocketTimeout(timeout);
+ public void setSocketTimeoutMillis(final int timeout) {
+ streamDuplexer.setSocketTimeoutMillis(timeout);
}
@Override
@@ -124,8 +124,8 @@ class AbstractHttp1IOEventHandler implements HttpConnectionEventHandler {
}
@Override
- public int getSocketTimeout() {
- return streamDuplexer.getSocketTimeout();
+ public int getSocketTimeoutMillis() {
+ return streamDuplexer.getSocketTimeoutMillis();
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
index c5cea79..7b603b6 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
@@ -29,7 +29,6 @@ package org.apache.hc.core5.http.impl.nio;
import java.io.IOException;
import java.net.SocketAddress;
-import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ReadableByteChannel;
@@ -77,6 +76,7 @@ import org.apache.hc.core5.reactor.ProtocolIOSession;
import org.apache.hc.core5.reactor.ssl.TlsDetails;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Identifiable;
+import org.apache.hc.core5.util.SocketTimeoutExceptionFactory;
abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage, OutgoingMessage extends HttpMessage>
implements Identifiable, HttpConnection {
@@ -390,9 +390,9 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
}
}
- public final void onTimeout() throws IOException, HttpException {
+ public final void onTimeout(final int timeoutMillis) throws IOException, HttpException {
if (!handleTimeout()) {
- onException(new SocketTimeoutException());
+ onException(SocketTimeoutExceptionFactory.create(timeoutMillis));
}
}
@@ -563,7 +563,7 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
}
@Override
- public void setSocketTimeout(final int timeout) {
+ public void setSocketTimeoutMillis(final int timeout) {
ioSession.setSocketTimeout(timeout);
}
@@ -577,7 +577,7 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
}
@Override
- public int getSocketTimeout() {
+ public int getSocketTimeoutMillis() {
return ioSession.getSocketTimeout();
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
index a7f5ed6..186f8b4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
@@ -124,12 +124,12 @@ public class ClientHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
}
@Override
- public int getSocketTimeout() {
+ public int getSocketTimeoutMillis() {
return getSessionTimeout();
}
@Override
- public void setSocketTimeout(final int timeout) {
+ public void setSocketTimeoutMillis(final int timeout) {
setSessionTimeout(timeout);
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
index 75cda22..41562d5 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
@@ -162,8 +162,8 @@ class ClientHttp1StreamHandler implements ResourceHolder {
final boolean expectContinue = h != null && "100-continue".equalsIgnoreCase(h.getValue());
if (expectContinue) {
requestState = MessageState.ACK;
- timeout = outputChannel.getSocketTimeout();
- outputChannel.setSocketTimeout(h1Config.getWaitForContinueTimeout());
+ timeout = outputChannel.getSocketTimeoutMillis();
+ outputChannel.setSocketTimeoutMillis(h1Config.getWaitForContinueTimeout());
} else {
requestState = MessageState.BODY;
exchangeHandler.produce(internalDataChannel);
@@ -219,7 +219,7 @@ class ClientHttp1StreamHandler implements ResourceHolder {
}
if (requestState == MessageState.ACK) {
if (status == HttpStatus.SC_CONTINUE || status >= HttpStatus.SC_SUCCESS) {
- outputChannel.setSocketTimeout(timeout);
+ outputChannel.setSocketTimeoutMillis(timeout);
requestState = MessageState.BODY;
if (status < HttpStatus.SC_CLIENT_ERROR) {
exchangeHandler.produce(internalDataChannel);
@@ -277,7 +277,7 @@ class ClientHttp1StreamHandler implements ResourceHolder {
boolean handleTimeout() {
if (requestState == MessageState.ACK) {
requestState = MessageState.BODY;
- outputChannel.setSocketTimeout(timeout);
+ outputChannel.setSocketTimeoutMillis(timeout);
outputChannel.requestOutput();
return true;
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamChannel.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamChannel.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamChannel.java
index 2e562a5..59847f7 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/Http1StreamChannel.java
@@ -46,8 +46,8 @@ interface Http1StreamChannel<OutgoingMessage extends HttpMessage> extends Conten
boolean abortGracefully() throws IOException;
- int getSocketTimeout();
+ int getSocketTimeoutMillis();
- void setSocketTimeout(int timeout);
+ void setSocketTimeoutMillis(int timeout);
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
index 3d24e6d..1491da1 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
@@ -129,12 +129,12 @@ public class ServerHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
}
@Override
- public int getSocketTimeout() {
+ public int getSocketTimeoutMillis() {
return getSessionTimeout();
}
@Override
- public void setSocketTimeout(final int timeout) {
+ public void setSocketTimeoutMillis(final int timeout) {
setSessionTimeout(timeout);
}
@@ -437,13 +437,13 @@ public class ServerHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
}
@Override
- public int getSocketTimeout() {
- return channel.getSocketTimeout();
+ public int getSocketTimeoutMillis() {
+ return channel.getSocketTimeoutMillis();
}
@Override
- public void setSocketTimeout(final int timeout) {
- channel.setSocketTimeout(timeout);
+ public void setSocketTimeoutMillis(final int timeout) {
+ channel.setSocketTimeoutMillis(timeout);
}
@Override
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandler.java
index 0a256b6..51a6283 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOEventHandler.java
@@ -65,8 +65,9 @@ public interface IOEventHandler {
* Triggered when the given session as timed out.
*
* @param session the I/O session.
+ * @param timeoutMillis the timeout in milliseconds.
*/
- void timeout(IOSession session) throws IOException;
+ void timeout(IOSession session, int timeoutMillis) throws IOException;
/**
* Triggered when the given session throws a exception.
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
index 59319d9..22cbc7f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
@@ -37,11 +37,11 @@ abstract class InternalChannel implements ModalCloseable {
abstract void onIOEvent(final int ops) throws IOException;
- abstract void onTimeout() throws IOException;
+ abstract void onTimeout(int timeoutMillis) throws IOException;
abstract void onException(final Exception cause);
- abstract int getTimeout();
+ abstract int getTimeoutMillis();
abstract long getLastReadTime();
@@ -57,12 +57,12 @@ abstract class InternalChannel implements ModalCloseable {
}
final boolean checkTimeout(final long currentTime) {
- final int timeout = getTimeout();
- if (timeout > 0) {
- final long deadline = getLastReadTime() + timeout;
+ final int timeoutMillis = getTimeoutMillis();
+ if (timeoutMillis > 0) {
+ final long deadline = getLastReadTime() + timeoutMillis;
if (currentTime > deadline) {
try {
- onTimeout();
+ onTimeout(timeoutMillis);
} catch (final CancelledKeyException ex) {
close(CloseMode.GRACEFUL);
} catch (final Exception ex) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
index e7bc153..4cde455 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalConnectChannel.java
@@ -28,11 +28,11 @@
package org.apache.hc.core5.reactor;
import java.io.IOException;
-import java.net.SocketTimeoutException;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.util.SocketTimeoutExceptionFactory;
import org.apache.hc.core5.util.TimeValue;
final class InternalConnectChannel extends InternalChannel {
@@ -78,7 +78,7 @@ final class InternalConnectChannel extends InternalChannel {
}
@Override
- int getTimeout() {
+ int getTimeoutMillis() {
return TimeValue.defaultsToZeroMillis(sessionRequest.timeout).toMillisIntBound();
}
@@ -88,8 +88,8 @@ final class InternalConnectChannel extends InternalChannel {
}
@Override
- void onTimeout() throws IOException {
- sessionRequest.failed(new SocketTimeoutException());
+ void onTimeout(final int timeoutMillis) throws IOException {
+ sessionRequest.failed(SocketTimeoutExceptionFactory.create(timeoutMillis));
close();
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
index dfe4e86..3f4878e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalDataChannel.java
@@ -172,14 +172,14 @@ final class InternalDataChannel extends InternalChannel implements ProtocolIOSes
}
@Override
- int getTimeout() {
+ int getTimeoutMillis() {
return ioSession.getSocketTimeout();
}
@Override
- void onTimeout() throws IOException {
+ void onTimeout(final int timeoutMillis) throws IOException {
final IOEventHandler handler = ensureHandler();
- handler.timeout(this);
+ handler.timeout(this, timeoutMillis);
final SSLIOSession tlsSession = tlsSessionRef.get();
if (tlsSession != null) {
if (tlsSession.isOutboundDone() && !tlsSession.isInboundDone()) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/main/java/org/apache/hc/core5/util/SocketTimeoutExceptionFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/SocketTimeoutExceptionFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/util/SocketTimeoutExceptionFactory.java
new file mode 100644
index 0000000..6af2bb7
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/SocketTimeoutExceptionFactory.java
@@ -0,0 +1,58 @@
+/*
+ * ====================================================================
+ * 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.util;
+
+import java.net.SocketTimeoutException;
+
+/**
+ * Creates SocketTimeoutException instances.
+ */
+public class SocketTimeoutExceptionFactory {
+
+ /**
+ * Creates a new SocketTimeoutException with a message for the given timeout.
+ *
+ * @param timeoutMillis
+ * a timeout in milliseconds.
+ * @return a new SocketTimeoutException with a message for the given timeout.
+ */
+ static public SocketTimeoutException create(final int timeoutMillis) {
+ return new SocketTimeoutException(toMessage(timeoutMillis));
+ }
+
+ /**
+ * Creates a message for the given timeout.
+ *
+ * @param timeoutMillis
+ * a timeout in milliseconds.
+ * @return a message for the given timeout.
+ */
+ public static String toMessage(final int timeoutMillis) {
+ return String.format("%,d millisecond", timeoutMillis);
+ }
+}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d01b7ec0/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
index 1e84b8a..2913f55 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
@@ -202,7 +202,7 @@ public class TestBHttpConnectionBase {
public void testSetSocketTimeout() throws Exception {
conn.bind(socket);
- conn.setSocketTimeout(123);
+ conn.setSocketTimeoutMillis(123);
Mockito.verify(socket, Mockito.times(1)).setSoTimeout(123);
}
@@ -213,29 +213,29 @@ public class TestBHttpConnectionBase {
Mockito.doThrow(new SocketException()).when(socket).setSoTimeout(Mockito.anyInt());
- conn.setSocketTimeout(123);
+ conn.setSocketTimeoutMillis(123);
Mockito.verify(socket, Mockito.times(1)).setSoTimeout(123);
}
@Test
public void testGetSocketTimeout() throws Exception {
- Assert.assertEquals(-1, conn.getSocketTimeout());
+ Assert.assertEquals(-1, conn.getSocketTimeoutMillis());
Mockito.when(socket.getSoTimeout()).thenReturn(345);
conn.bind(socket);
- Assert.assertEquals(345, conn.getSocketTimeout());
+ Assert.assertEquals(345, conn.getSocketTimeoutMillis());
}
@Test
public void testGetSocketTimeoutException() throws Exception {
- Assert.assertEquals(-1, conn.getSocketTimeout());
+ Assert.assertEquals(-1, conn.getSocketTimeoutMillis());
Mockito.when(socket.getSoTimeout()).thenThrow(new SocketException());
conn.bind(socket);
- Assert.assertEquals(-1, conn.getSocketTimeout());
+ Assert.assertEquals(-1, conn.getSocketTimeoutMillis());
}
@Test