hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject httpcomponents-core git commit: HTTPCORE-454: use Timeout class to represent timeout values
Date Sun, 25 Jun 2017 20:59:34 GMT
Repository: httpcomponents-core
Updated Branches:
  refs/heads/dev/HTTPCORE-454 [created] cfb878cf9


HTTPCORE-454: use Timeout class to represent timeout values


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/cfb878cf
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/cfb878cf
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/cfb878cf

Branch: refs/heads/dev/HTTPCORE-454
Commit: cfb878cf97d03b6365e66084cfcb0da8205dc0dc
Parents: 8f1b4f6
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Wed Jun 21 10:09:27 2017 +0200
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Sun Jun 25 22:59:00 2017 +0200

----------------------------------------------------------------------
 .../framework/ClassicTestClientAdapter.java     |  6 +--
 .../nio/Http1ServerAndRequesterTest.java        |  3 +-
 .../nio/Http2ProtocolNegotiationTest.java       |  4 +-
 .../nio/Http2ServerAndRequesterTest.java        |  3 +-
 .../examples/ClassicGetExecutionExample.java    |  4 +-
 .../examples/ClassicPostExecutionExample.java   |  4 +-
 ...ClassicPostWithTrailersExecutionExample.java |  4 +-
 .../examples/ClassicReverseProxyExample.java    |  3 +-
 .../hc/core5/http/config/SocketConfig.java      | 19 +++++----
 .../impl/bootstrap/AsyncRequesterBootstrap.java |  6 +--
 .../http/impl/bootstrap/HttpRequester.java      |  8 ++--
 .../http/impl/bootstrap/RequesterBootstrap.java |  6 +--
 .../org/apache/hc/core5/pool/LeaseRequest.java  | 15 ++-----
 .../org/apache/hc/core5/pool/PoolEntry.java     |  4 +-
 .../apache/hc/core5/pool/StrictConnPool.java    |  7 ++--
 .../hc/core5/reactor/IOReactorConfig.java       | 17 ++++----
 .../org/apache/hc/core5/util/TimeValue.java     | 21 +++++++++-
 .../java/org/apache/hc/core5/util/Timeout.java  | 43 ++------------------
 .../hc/core5/pool/TestStrictConnPool.java       | 13 +++---
 .../org/apache/hc/core5/util/TestTimeout.java   | 23 +----------
 20 files changed, 86 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java
b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java
index af26940..e2cf0a7 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClassicTestClientAdapter.java
@@ -45,7 +45,7 @@ import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.testing.classic.ClassicTestClient;
-import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 public class ClassicTestClientAdapter extends ClientPOJOAdapter {
 
@@ -68,9 +68,9 @@ public class ClassicTestClientAdapter extends ClientPOJOAdapter {
             throw new HttpException("Request method should be set.");
         }
 
-        final TimeValue timeout;
+        final Timeout timeout;
         if (request.containsKey(TIMEOUT)) {
-            timeout = TimeValue.ofMillis((long) request.get(TIMEOUT));
+            timeout = Timeout.ofMillis((long) request.get(TIMEOUT));
         } else {
             timeout = null;
         }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1ServerAndRequesterTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1ServerAndRequesterTest.java
b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1ServerAndRequesterTest.java
index 52932b9..9fb4ea5 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1ServerAndRequesterTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1ServerAndRequesterTest.java
@@ -62,6 +62,7 @@ import org.apache.hc.core5.reactor.ExceptionEvent;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.ListenerEndpoint;
 import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.hamcrest.CoreMatchers;
@@ -72,7 +73,7 @@ import org.junit.rules.ExternalResource;
 
 public class Http1ServerAndRequesterTest {
 
-    private static final TimeValue TIMEOUT = TimeValue.ofSeconds(30);
+    private static final Timeout TIMEOUT = Timeout.ofSeconds(30);
 
     private final Logger log = LogManager.getLogger(getClass());
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
index faf8868..32d062e 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
@@ -59,7 +59,7 @@ import org.apache.hc.core5.reactor.ExceptionEvent;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.ListenerEndpoint;
 import org.apache.hc.core5.testing.SSLTestContexts;
-import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.hamcrest.CoreMatchers;
@@ -73,7 +73,7 @@ import org.junit.rules.ExternalResource;
 
 public class Http2ProtocolNegotiationTest {
 
-    private static final TimeValue TIMEOUT = TimeValue.ofSeconds(30);
+    private static final Timeout TIMEOUT = Timeout.ofSeconds(30);
 
     private final Logger log = LogManager.getLogger(getClass());
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
index b87fdb8..559932e 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
@@ -57,6 +57,7 @@ import org.apache.hc.core5.reactor.ExceptionEvent;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.ListenerEndpoint;
 import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.hamcrest.CoreMatchers;
@@ -81,7 +82,7 @@ public class Http2ServerAndRequesterTest {
         });
     }
 
-    private static final TimeValue TIMEOUT = TimeValue.ofSeconds(30);
+    private static final Timeout TIMEOUT = Timeout.ofSeconds(30);
 
     private final HttpVersionPolicy versionPolicy;
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java
b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java
index abb910e..71a8867 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicGetExecutionExample.java
@@ -44,7 +44,7 @@ import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.message.RequestLine;
 import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
-import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * Example of GET requests execution using classic I/O.
@@ -89,7 +89,7 @@ public class ClassicGetExecutionExample {
         for (int i = 0; i < requestUris.length; i++) {
             String requestUri = requestUris[i];
             ClassicHttpRequest request = new BasicClassicHttpRequest("GET", target, requestUri);
-            try (ClassicHttpResponse response = httpRequester.execute(target, request, TimeValue.ofSeconds(5),
coreContext)) {
+            try (ClassicHttpResponse response = httpRequester.execute(target, request, Timeout.ofSeconds(5),
coreContext)) {
                 System.out.println(requestUri + "->" + response.getCode());
                 System.out.println(EntityUtils.toString(response.getEntity()));
                 System.out.println("==============");

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java
b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java
index 61e3716..0d95e84 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostExecutionExample.java
@@ -51,7 +51,7 @@ import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.message.RequestLine;
 import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
-import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * Example of POST requests execution using classic I/O.
@@ -109,7 +109,7 @@ public class ClassicPostExecutionExample {
         for (int i = 0; i < requestBodies.length; i++) {
             ClassicHttpRequest request = new BasicClassicHttpRequest("POST", target,requestUri);
             request.setEntity(requestBodies[i]);
-            try (ClassicHttpResponse response = httpRequester.execute(target, request, TimeValue.ofSeconds(5),
coreContext)) {
+            try (ClassicHttpResponse response = httpRequester.execute(target, request, Timeout.ofSeconds(5),
coreContext)) {
                 System.out.println(requestUri + "->" + response.getCode());
                 System.out.println(EntityUtils.toString(response.getEntity()));
                 System.out.println("==============");

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostWithTrailersExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostWithTrailersExecutionExample.java
b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostWithTrailersExecutionExample.java
index a800a2b..112b517 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostWithTrailersExecutionExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicPostWithTrailersExecutionExample.java
@@ -43,7 +43,7 @@ import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
-import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * Example of POST request with trailers execution using classic I/O.
@@ -67,7 +67,7 @@ public class ClassicPostWithTrailersExecutionExample {
                 .build();
 
         System.out.println(">> Request URI: " + request.getUri());
-        try (ClassicHttpResponse response = httpRequester.execute(target, request, TimeValue.ofSeconds(5),
coreContext)) {
+        try (ClassicHttpResponse response = httpRequester.execute(target, request, Timeout.ofSeconds(5),
coreContext)) {
             System.out.println(requestUri + "->" + response.getCode());
             System.out.println(EntityUtils.toString(response.getEntity()));
             System.out.println("==============");

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicReverseProxyExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicReverseProxyExample.java
b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicReverseProxyExample.java
index ca4723f..961c2d9 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicReverseProxyExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicReverseProxyExample.java
@@ -63,6 +63,7 @@ import org.apache.hc.core5.pool.ConnPoolListener;
 import org.apache.hc.core5.pool.ConnPoolStats;
 import org.apache.hc.core5.pool.PoolStats;
 import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * Example of embedded HTTP/1.1 reverse proxy using classic I/O.
@@ -220,7 +221,7 @@ public class ClassicReverseProxyExample {
                 }
             }
             final ClassicHttpResponse incomingResponse = requester.execute(
-                    targetHost, outgoingRequest, TimeValue.ofMinutes(1), clientContext);
+                    targetHost, outgoingRequest, Timeout.ofMinutes(1), clientContext);
             outgoingResponse.setCode(incomingResponse.getCode());
             for (Iterator<Header> it = incomingResponse.headerIterator(); it.hasNext();
) {
                 Header header = it.next();

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/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 91d60da..048ddb4 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
@@ -33,6 +33,7 @@ import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * Socket configuration.
@@ -44,7 +45,7 @@ public class SocketConfig {
 
     public static final SocketConfig DEFAULT = new Builder().build();
 
-    private final TimeValue soTimeout;
+    private final Timeout soTimeout;
     private final boolean soReuseAddress;
     private final TimeValue soLinger;
     private final boolean soKeepAlive;
@@ -54,7 +55,7 @@ public class SocketConfig {
     private final int backlogSize;
 
     SocketConfig(
-            final TimeValue soTimeout,
+            final Timeout soTimeout,
             final boolean soReuseAddress,
             final TimeValue soLinger,
             final boolean soKeepAlive,
@@ -82,7 +83,7 @@ public class SocketConfig {
      * @return the default socket timeout value for blocking I/O operations.
      * @see java.net.SocketOptions#SO_TIMEOUT
      */
-    public TimeValue getSoTimeout() {
+    public Timeout getSoTimeout() {
         return soTimeout;
     }
 
@@ -219,7 +220,7 @@ public class SocketConfig {
 
     public static class Builder {
 
-        private TimeValue soTimeout;
+        private Timeout soTimeout;
         private boolean soReuseAddress;
         private TimeValue soLinger;
         private boolean soKeepAlive;
@@ -229,7 +230,7 @@ public class SocketConfig {
         private int backlogSize;
 
         Builder() {
-            this.soTimeout = TimeValue.ZERO_MILLISECONDS;
+            this.soTimeout = Timeout.ZERO_MILLISECONDS;
             this.soReuseAddress = false;
             this.soLinger = TimeValue.NEG_ONE_SECONDS;
             this.soKeepAlive = false;
@@ -240,11 +241,11 @@ public class SocketConfig {
         }
 
         public Builder setSoTimeout(final int soTimeout, final TimeUnit timeUnit) {
-            this.soTimeout = TimeValue.of(soTimeout, timeUnit);
+            this.soTimeout = Timeout.of(soTimeout, timeUnit);
             return this;
         }
 
-        public Builder setSoTimeout(final TimeValue soTimeout) {
+        public Builder setSoTimeout(final Timeout soTimeout) {
             this.soTimeout = soTimeout;
             return this;
         }
@@ -255,7 +256,7 @@ public class SocketConfig {
         }
 
         public Builder setSoLinger(final int soLinger, final TimeUnit timeUnit) {
-            this.soLinger = TimeValue.of(soLinger, timeUnit);
+            this.soLinger = Timeout.of(soLinger, timeUnit);
             return this;
         }
 
@@ -300,7 +301,7 @@ public class SocketConfig {
 
         public SocketConfig build() {
             return new SocketConfig(
-                    soTimeout != null ? soTimeout : TimeValue.ZERO_MILLISECONDS,
+                    soTimeout != null ? soTimeout : Timeout.ZERO_MILLISECONDS,
                     soReuseAddress,
                     soLinger != null ? soLinger : TimeValue.NEG_ONE_SECONDS,
                     soKeepAlive, tcpNoDelay, sndBufSize, rcvBufSize, backlogSize);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
index 6e85d0c..55c6bb9 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
@@ -45,7 +45,7 @@ import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.IOSessionListener;
-import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * @since 5.0
@@ -59,7 +59,7 @@ public class AsyncRequesterBootstrap {
     private ConnectionReuseStrategy connStrategy;
     private int defaultMaxPerRoute;
     private int maxTotal;
-    private TimeValue timeToLive;
+    private Timeout timeToLive;
     private ConnPoolPolicy connPoolPolicy;
     private TlsStrategy tlsStrategy;
     private Decorator<IOSession> ioSessionDecorator;
@@ -124,7 +124,7 @@ public class AsyncRequesterBootstrap {
         return this;
     }
 
-    public final AsyncRequesterBootstrap setTimeToLive(final TimeValue timeToLive) {
+    public final AsyncRequesterBootstrap setTimeToLive(final Timeout timeToLive) {
         this.timeToLive = timeToLive;
         return this;
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/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 e158573..69876c7 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
@@ -67,7 +67,7 @@ import org.apache.hc.core5.pool.ConnPoolControl;
 import org.apache.hc.core5.pool.ControlledConnPool;
 import org.apache.hc.core5.pool.PoolEntry;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * @since 5.0
@@ -188,13 +188,13 @@ public class HttpRequester implements GracefullyCloseable {
     public ClassicHttpResponse execute(
             final HttpHost targetHost,
             final ClassicHttpRequest request,
-            final TimeValue connectTimeout,
+            final Timeout connectTimeout,
             final HttpContext context) throws HttpException, IOException {
         Args.notNull(targetHost, "HTTP host");
         Args.notNull(request, "HTTP request");
         final Future<PoolEntry<HttpHost, HttpClientConnection>> leaseFuture =
connPool.lease(targetHost, null, null);
         final PoolEntry<HttpHost, HttpClientConnection> poolEntry;
-        final TimeValue timeout = connectTimeout != null ? connectTimeout : TimeValue.ZERO_MILLISECONDS;
+        final Timeout timeout = connectTimeout != null ? connectTimeout : Timeout.ZERO_MILLISECONDS;
 
         try {
             poolEntry = leaseFuture.get(timeout.getDuration(), timeout.getTimeUnit());
@@ -300,7 +300,7 @@ public class HttpRequester implements GracefullyCloseable {
     public <T> T  execute(
             final HttpHost targetHost,
             final ClassicHttpRequest request,
-            final TimeValue connectTimeout,
+            final Timeout connectTimeout,
             final HttpContext context,
             final ResponseHandler<T> responseHandler) throws HttpException, IOException
{
         try (final ClassicHttpResponse response = execute(targetHost, request, connectTimeout,
context)) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
index 435659d..4110d0e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
@@ -44,7 +44,7 @@ import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.pool.ConnPoolListener;
 import org.apache.hc.core5.pool.ConnPoolPolicy;
 import org.apache.hc.core5.pool.StrictConnPool;
-import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * @since 5.0
@@ -58,7 +58,7 @@ public class RequesterBootstrap {
     private SSLSocketFactory sslSocketFactory;
     private int defaultMaxPerRoute;
     private int maxTotal;
-    private TimeValue timeToLive;
+    private Timeout timeToLive;
     private ConnPoolPolicy connPoolPolicy;
     private Http1StreamListener streamListener;
     private ConnPoolListener<HttpHost> connPoolListener;
@@ -114,7 +114,7 @@ public class RequesterBootstrap {
         return this;
     }
 
-    public final RequesterBootstrap setTimeToLive(final TimeValue timeToLive) {
+    public final RequesterBootstrap setTimeToLive(final Timeout timeToLive) {
         this.timeToLive = timeToLive;
         return this;
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/main/java/org/apache/hc/core5/pool/LeaseRequest.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/LeaseRequest.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/LeaseRequest.java
index ec52d37..42977fb 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/pool/LeaseRequest.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/LeaseRequest.java
@@ -32,7 +32,7 @@ import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.concurrent.BasicFuture;
 import org.apache.hc.core5.io.GracefullyCloseable;
-import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 @Contract(threading = ThreadingBehavior.SAFE_CONDITIONAL)
 class LeaseRequest<T, C extends GracefullyCloseable> {
@@ -45,15 +45,6 @@ class LeaseRequest<T, C extends GracefullyCloseable> {
     private volatile PoolEntry<T, C> result;
     private volatile Exception ex;
 
-    static long calculateDeadline(final long currentTimeMillis, final TimeValue timeValue)
{
-        final long time = TimeValue.isPositive(timeValue) ? currentTimeMillis + timeValue.toMillis()
: Long.MAX_VALUE;
-        if (time < 0 && TimeValue.isPositive(timeValue)) {
-            return Long.MAX_VALUE;
-        } else {
-            return time;
-        }
-    }
-
     /**
      * Constructor
      *
@@ -65,12 +56,12 @@ class LeaseRequest<T, C extends GracefullyCloseable> {
     public LeaseRequest(
             final T route,
             final Object state,
-            final TimeValue requestTimeout,
+            final Timeout requestTimeout,
             final BasicFuture<PoolEntry<T, C>> future) {
         super();
         this.route = route;
         this.state = state;
-        this.deadline = calculateDeadline(System.currentTimeMillis(), requestTimeout);
+        this.deadline = Timeout.calculateDeadline(System.currentTimeMillis(), requestTimeout);
         this.future = future;
         this.completed = new AtomicBoolean(false);
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java
index 4572bb4..3656de0 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolEntry.java
@@ -119,7 +119,7 @@ public final class PoolEntry<T, C extends GracefullyCloseable> {
         if (this.connRef.compareAndSet(null, conn)) {
             this.created = currentTimeMillis();
             this.updated = this.created;
-            this.validityDeadline = LeaseRequest.calculateDeadline(this.created, this.timeToLive);
+            this.validityDeadline = TimeValue.calculateDeadline(this.created, this.timeToLive);
             this.expiry = this.validityDeadline;
             this.state = null;
         } else {
@@ -148,7 +148,7 @@ public final class PoolEntry<T, C extends GracefullyCloseable> {
     public void updateExpiry(final TimeValue expiryTime) {
         Args.notNull(expiryTime, "Expiry time");
         final long currentTime = System.currentTimeMillis();
-        final long newExpiry = LeaseRequest.calculateDeadline(currentTime, expiryTime);
+        final long newExpiry = TimeValue.calculateDeadline(currentTime, expiryTime);
         this.expiry = Math.min(newExpiry, getValidityDeadline());
         this.updated = currentTime;
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
index d8efa59..32faa13 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/StrictConnPool.java
@@ -51,6 +51,7 @@ import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
 import org.apache.hc.core5.util.LangUtils;
 import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * Connection pool with strict max connection limit guarantees.
@@ -148,7 +149,7 @@ public class StrictConnPool<T, C extends GracefullyCloseable> implements
Control
 
     public Future<PoolEntry<T, C>> lease(
             final T route, final Object state,
-            final TimeValue requestTimeout,
+            final Timeout requestTimeout,
             final FutureCallback<PoolEntry<T, C>> callback) {
         Args.notNull(route, "Route");
         Args.notNull(requestTimeout, "Request timeout");
@@ -173,11 +174,11 @@ public class StrictConnPool<T, C extends GracefullyCloseable>
implements Control
 
     @Override
     public Future<PoolEntry<T, C>> lease(final T route, final Object state, final
FutureCallback<PoolEntry<T, C>> callback) {
-        return lease(route, state, TimeValue.NEG_ONE_MILLISECONDS, callback);
+        return lease(route, state, Timeout.DISABLED, callback);
     }
 
     public Future<PoolEntry<T, C>> lease(final T route, final Object state) {
-        return lease(route, state, TimeValue.NEG_ONE_MILLISECONDS, null);
+        return lease(route, state, Timeout.DISABLED, null);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/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 d4f3ac8..19e73c3 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
@@ -33,6 +33,7 @@ import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * I/O reactor configuration parameters.
@@ -48,7 +49,7 @@ public final class IOReactorConfig {
 
     private final long selectInterval;
     private final int ioThreadCount;
-    private final TimeValue  soTimeout;
+    private final Timeout  soTimeout;
     private final boolean soReuseAddress;
     private final TimeValue soLinger;
     private final boolean soKeepAlive;
@@ -60,7 +61,7 @@ public final class IOReactorConfig {
     IOReactorConfig(
             final long selectInterval,
             final int ioThreadCount,
-            final TimeValue soTimeout,
+            final Timeout soTimeout,
             final boolean soReuseAddress,
             final TimeValue soLinger,
             final boolean soKeepAlive,
@@ -107,7 +108,7 @@ public final class IOReactorConfig {
      *
      * @see java.net.SocketOptions#SO_TIMEOUT
      */
-    public TimeValue getSoTimeout() {
+    public Timeout getSoTimeout() {
         return soTimeout;
     }
 
@@ -217,7 +218,7 @@ public final class IOReactorConfig {
 
         private long selectInterval;
         private int ioThreadCount;
-        private TimeValue  soTimeout;
+        private Timeout  soTimeout;
         private boolean soReuseAddress;
         private TimeValue soLinger;
         private boolean soKeepAlive;
@@ -229,7 +230,7 @@ public final class IOReactorConfig {
         Builder() {
             this.selectInterval = 1000;
             this.ioThreadCount = AVAIL_PROCS;
-            this.soTimeout = TimeValue.ZERO_MILLISECONDS;
+            this.soTimeout = Timeout.ZERO_MILLISECONDS;
             this.soReuseAddress = false;
             this.soLinger = TimeValue.NEG_ONE_SECONDS;
             this.soKeepAlive = false;
@@ -250,11 +251,11 @@ public final class IOReactorConfig {
         }
 
         public Builder setSoTimeout(final int soTimeout, final TimeUnit timeUnit) {
-            this.soTimeout = TimeValue.of(soTimeout, timeUnit);;
+            this.soTimeout = Timeout.of(soTimeout, timeUnit);;
             return this;
         }
 
-        public Builder setSoTimeout(final TimeValue soTimeout) {
+        public Builder setSoTimeout(final Timeout soTimeout) {
             this.soTimeout = soTimeout;
             return this;
         }
@@ -302,7 +303,7 @@ public final class IOReactorConfig {
         public IOReactorConfig build() {
             return new IOReactorConfig(
                     selectInterval, ioThreadCount,
-                    soTimeout != null ? soTimeout : TimeValue.ZERO_MILLISECONDS,
+                    soTimeout != null ? soTimeout : Timeout.ZERO_MILLISECONDS,
                     soReuseAddress,
                     soLinger != null ? soLinger : TimeValue.NEG_ONE_SECONDS,
                     soKeepAlive,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/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 a8646ca..2faa019 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
@@ -187,6 +187,23 @@ public class TimeValue {
                 TimeUnit.valueOf(split[1].trim().toUpperCase(Locale.ROOT)));
     }
 
+    /**
+     * Calculates the deadline with the current time in milliseconds and the given time value.
+     * Non-positive time value represents an indefinite timeout without a deadline.
+     *
+     * @param currentTimeMillis current time
+     * @param timeValue time value
+     * @return deadline in milliseconds
+     */
+    public static long calculateDeadline(final long currentTimeMillis, final TimeValue timeValue)
{
+        if (TimeValue.isPositive(timeValue)) {
+            final long deadline = currentTimeMillis + timeValue.toMillis();
+            return deadline >= 0 ? deadline : Long.MAX_VALUE;
+        } else {
+            return Long.MAX_VALUE;
+        }
+    }
+
     private final long duration;
 
     private final TimeUnit timeUnit;
@@ -224,7 +241,7 @@ public class TimeValue {
     @Override
     public int hashCode() {
         int hash = LangUtils.HASH_SEED;
-        hash = LangUtils.hashCode(hash, Long.valueOf(duration));
+        hash = LangUtils.hashCode(hash, duration);
         hash = LangUtils.hashCode(hash, timeUnit);
         return hash;
     }
@@ -279,7 +296,7 @@ public class TimeValue {
 
     @Override
     public String toString() {
-        return String.format("%,d %s", Long.valueOf(duration), timeUnit);
+        return String.format("%,d %s", duration, timeUnit);
     }
 
     public Timeout toTimeout() {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/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 888a25b..3661da1 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
@@ -34,7 +34,7 @@ import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 
 /**
- * Represents a timeout value as a {@code long} time and {@link TimeUnit}.
+ * Represents a timeout value as a non-negative {@code long} time and {@link TimeUnit}.
  *
  * @since 5.0
  */
@@ -46,17 +46,7 @@ public class Timeout extends TimeValue {
     /**
      * A disabled timeout represented as 0 {@code MILLISECONDS}.
      */
-    public static final Timeout DISABLED = new Timeout(0, TimeUnit.MILLISECONDS);
-
-    /**
-     * An undefined timeout represented as -1 {@code MILLISECONDS}.
-     */
-    public static final Timeout UNDEFINED_MILLISECONDS = new Timeout(INT_UNDEFINED, TimeUnit.MILLISECONDS);
-
-    /**
-     * An undefined timeout represented as -1 {@code SECONDS}.
-     */
-    public static final Timeout UNDEFINED_SECONDS = new Timeout(INT_UNDEFINED, TimeUnit.SECONDS);
+    public static final Timeout DISABLED = ZERO_MILLISECONDS;
 
     /**
      * Creates a Timeout.
@@ -161,15 +151,8 @@ public class Timeout extends TimeValue {
         return TimeValue.parse(value).toTimeout();
     }
 
-    private static long validateDuration(final long duration) {
-        if (duration < INT_UNDEFINED) {
-            throw new IllegalArgumentException("Duration may not be less than " + INT_UNDEFINED);
-        }
-        return duration;
-    }
-
     Timeout(final long duration, final TimeUnit timeUnit) {
-        super(validateDuration(duration), Args.notNull(timeUnit, "timeUnit"));
+        super(Args.notNegative(duration, "Duration"), Args.notNull(timeUnit, "timeUnit"));
     }
 
     /**
@@ -187,25 +170,7 @@ public class Timeout extends TimeValue {
      * @return Whether this timeout is disabled.
      */
     public boolean isEnabled() {
-        return !isDisabled() && !(isUndefinedMilliseconds() || isUndefinedSeconds());
-    }
-
-    /**
-     * Whether this timeout is undefined.
-     *
-     * @return Whether this timeout is undefined.
-     */
-    public boolean isUndefinedMilliseconds() {
-        return getDuration() == INT_UNDEFINED && getTimeUnit() == TimeUnit.MILLISECONDS;
-    }
-
-    /**
-     * Whether this timeout is undefined.
-     *
-     * @return Whether this timeout is undefined.
-     */
-    public boolean isUndefinedSeconds() {
-        return getDuration() == INT_UNDEFINED && getTimeUnit() == TimeUnit.SECONDS;
+        return !isDisabled();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java b/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java
index 4435479..732513e 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java
@@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.hc.core5.http.HttpConnection;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -108,7 +109,7 @@ public class TestStrictConnPool {
     public void testLeaseIllegal() throws Exception {
         final StrictConnPool<String, HttpConnection> pool = new StrictConnPool<>(2,
10);
         try {
-            pool.lease(null, null, TimeValue.ZERO_MILLISECONDS, null);
+            pool.lease(null, null, Timeout.ZERO_MILLISECONDS, null);
             Assert.fail("IllegalArgumentException should have been thrown");
         } catch (final IllegalArgumentException expected) {
         }
@@ -491,9 +492,9 @@ public class TestStrictConnPool {
 
         final StrictConnPool<String, HttpConnection> pool = new StrictConnPool<>(1,
1);
 
-        final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost",
null, TimeValue.of(0, TimeUnit.MILLISECONDS), null);
-        final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost",
null, TimeValue.of(0, TimeUnit.MILLISECONDS), null);
-        final Future<PoolEntry<String, HttpConnection>> future3 = pool.lease("somehost",
null, TimeValue.of(10, TimeUnit.MILLISECONDS), null);
+        final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost",
null, Timeout.ofMillis(0), null);
+        final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost",
null, Timeout.ofMillis(0), null);
+        final Future<PoolEntry<String, HttpConnection>> future3 = pool.lease("somehost",
null, Timeout.ofMillis(10), null);
 
         Assert.assertTrue(future1.isDone());
         final PoolEntry<String, HttpConnection> entry1 = future1.get();
@@ -514,14 +515,14 @@ public class TestStrictConnPool {
     public void testLeaseRequestCanceled() throws Exception {
         final StrictConnPool<String, HttpConnection> pool = new StrictConnPool<>(1,
1);
 
-        final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost",
null, TimeValue.of(0, TimeUnit.MILLISECONDS), null);
+        final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost",
null, Timeout.ofMillis(0), null);
 
         Assert.assertTrue(future1.isDone());
         final PoolEntry<String, HttpConnection> entry1 = future1.get();
         Assert.assertNotNull(entry1);
         entry1.assignConnection(Mockito.mock(HttpConnection.class));
 
-        final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost",
null, TimeValue.of(0, TimeUnit.MILLISECONDS), null);
+        final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost",
null, Timeout.ofMillis(0), null);
         future2.cancel(true);
 
         pool.release(entry1, true);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cfb878cf/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
index 25d62a5..336ff7b 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
@@ -89,8 +89,6 @@ public class TestTimeout {
     public void testDisabled() {
         Assert.assertTrue(Timeout.DISABLED.isDisabled());
         Assert.assertFalse(Timeout.DISABLED.isEnabled());
-        Assert.assertFalse(Timeout.DISABLED.isUndefinedMilliseconds());
-        Assert.assertFalse(Timeout.DISABLED.isUndefinedSeconds());
     }
 
     private void testFactory(final TimeUnit timeUnit) {
@@ -142,30 +140,11 @@ public class TestTimeout {
         test(Long.MAX_VALUE);
     }
 
-    @Test
+    @Test(expected = IllegalArgumentException.class)
     public void testNegative1() {
         test(-1);
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testNegative2() {
-        test(-2);
-    }
-
-    @Test
-    public void testUndefinedMilliseconds() {
-        Assert.assertTrue(Timeout.UNDEFINED_MILLISECONDS.isUndefinedMilliseconds());
-        Assert.assertFalse(Timeout.UNDEFINED_MILLISECONDS.isEnabled());
-        Assert.assertFalse(Timeout.UNDEFINED_MILLISECONDS.isDisabled());
-    }
-
-    @Test
-    public void testUndefinedSeconds() {
-        Assert.assertTrue(Timeout.UNDEFINED_SECONDS.isUndefinedSeconds());
-        Assert.assertFalse(Timeout.UNDEFINED_SECONDS.isEnabled());
-        Assert.assertFalse(Timeout.UNDEFINED_SECONDS.isDisabled());
-    }
-
     @Test
     public void testToString() {
         Assert.assertEquals("9,223,372,036,854,775,807 SECONDS", Timeout.ofSeconds(Long.MAX_VALUE).toString());


Mime
View raw message