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 2017/06/26 07:46:56 UTC
httpcomponents-core git commit: HTTPCORE-454: Use #defaultsTo methods
to choose a default value in case the given time value is null
Repository: httpcomponents-core
Updated Branches:
refs/heads/dev/HTTPCORE-454 cfb878cf9 -> 051a401fc
HTTPCORE-454: Use #defaultsTo methods to choose a default value in case the given time value is null
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/051a401f
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/051a401f
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/051a401f
Branch: refs/heads/dev/HTTPCORE-454
Commit: 051a401fcd1b87e49fc07ff742b8cf794d082054
Parents: cfb878c
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Jun 26 09:44:09 2017 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Jun 26 09:44:09 2017 +0200
----------------------------------------------------------------------
.../org/apache/hc/core5/http/config/SocketConfig.java | 2 +-
.../hc/core5/http/impl/bootstrap/HttpRequester.java | 3 +--
.../org/apache/hc/core5/reactor/IOReactorConfig.java | 4 ++--
.../main/java/org/apache/hc/core5/util/TimeValue.java | 2 +-
.../src/main/java/org/apache/hc/core5/util/Timeout.java | 12 ++++++++++++
5 files changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/051a401f/httpcore5/src/main/java/org/apache/hc/core5/http/config/SocketConfig.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/config/SocketConfig.java b/httpcore5/src/main/java/org/apache/hc/core5/http/config/SocketConfig.java
index 048ddb4..855ff4b 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/config/SocketConfig.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/config/SocketConfig.java
@@ -301,7 +301,7 @@ public class SocketConfig {
public SocketConfig build() {
return new SocketConfig(
- soTimeout != null ? soTimeout : Timeout.ZERO_MILLISECONDS,
+ Timeout.defaultsToDisabled(soTimeout),
soReuseAddress,
soLinger != null ? soLinger : TimeValue.NEG_ONE_SECONDS,
soKeepAlive, tcpNoDelay, sndBufSize, rcvBufSize, backlogSize);
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/051a401f/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
index 69876c7..3a82785 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
@@ -194,8 +194,7 @@ public class HttpRequester implements GracefullyCloseable {
Args.notNull(request, "HTTP request");
final Future<PoolEntry<HttpHost, HttpClientConnection>> leaseFuture = connPool.lease(targetHost, null, null);
final PoolEntry<HttpHost, HttpClientConnection> poolEntry;
- final Timeout timeout = connectTimeout != null ? connectTimeout : Timeout.ZERO_MILLISECONDS;
-
+ final Timeout timeout = Timeout.defaultsToDisabled(connectTimeout);
try {
poolEntry = leaseFuture.get(timeout.getDuration(), timeout.getTimeUnit());
} catch (final InterruptedException ex) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/051a401f/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java
index 19e73c3..ba1d4ea 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java
@@ -303,9 +303,9 @@ public final class IOReactorConfig {
public IOReactorConfig build() {
return new IOReactorConfig(
selectInterval, ioThreadCount,
- soTimeout != null ? soTimeout : Timeout.ZERO_MILLISECONDS,
+ Timeout.defaultsToDisabled(soTimeout),
soReuseAddress,
- soLinger != null ? soLinger : TimeValue.NEG_ONE_SECONDS,
+ TimeValue.defaultsToNegativeOneMillisecond(soLinger),
soKeepAlive,
tcpNoDelay,
sndBufSize, rcvBufSize, backlogSize);
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/051a401f/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
index 2faa019..33a8e7a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
@@ -79,7 +79,7 @@ public class TimeValue {
* may be {@code null}
* @return {@code timeValue} or {@code defaultValue}
*/
- public static TimeValue defaultsTo(final TimeValue timeValue, final TimeValue defaultValue) {
+ public static <T extends TimeValue> T defaultsTo(final T timeValue, final T defaultValue) {
return timeValue != null ? timeValue : defaultValue;
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/051a401f/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
index 3661da1..6c1e00b 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
@@ -49,6 +49,18 @@ public class Timeout extends TimeValue {
public static final Timeout DISABLED = ZERO_MILLISECONDS;
/**
+ * Returns the given {@code timeout} if it is not {@code null}, if {@code null} then returns
+ * {@link #DISABLED}.
+ *
+ * @param timeout
+ * may be {@code null}
+ * @return {@code timeValue} or {@link #DISABLED}
+ */
+ public static Timeout defaultsToDisabled(final Timeout timeout) {
+ return defaultsTo(timeout, DISABLED);
+ }
+
+ /**
* Creates a Timeout.
*
* @param duration