diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java index 56da800f7..79d9068c2 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java @@ -28,7 +28,6 @@ package org.apache.hc.client5.http.impl; import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.ThreadingBehavior; @@ -36,6 +35,7 @@ import org.apache.hc.core5.concurrent.DefaultThreadFactory; import org.apache.hc.core5.pool.ConnPoolControl; import org.apache.hc.core5.util.Args; import org.apache.hc.core5.util.TimeValue; +import org.apache.hc.core5.util.Timeout; /** * This class maintains a background thread to enforce an eviction policy for expired / idle @@ -94,8 +94,8 @@ public final class IdleConnectionEvictor { return thread.isAlive(); } - public void awaitTermination(final long time, final TimeUnit timeUnit) throws InterruptedException { - thread.join((timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS).toMillis(time)); + public void awaitTermination(final Timeout timeout) throws InterruptedException { + thread.join(timeout != null ? timeout.toMillis() : Long.MAX_VALUE); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java index 7199263f2..ed4d63d13 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java @@ -36,7 +36,6 @@ import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeUnit; import org.apache.hc.client5.http.AuthenticationStrategy; import org.apache.hc.client5.http.ConnectionKeepAliveStrategy; @@ -46,12 +45,12 @@ import org.apache.hc.client5.http.ServiceUnavailableRetryStrategy; import org.apache.hc.client5.http.SystemDefaultDnsResolver; import org.apache.hc.client5.http.UserTokenHandler; import org.apache.hc.client5.http.auth.AuthSchemeProvider; +import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.auth.CredentialsProvider; import org.apache.hc.client5.http.auth.KerberosConfig; import org.apache.hc.client5.http.classic.BackoffManager; import org.apache.hc.client5.http.classic.ConnectionBackoffStrategy; import org.apache.hc.client5.http.classic.ExecChainHandler; -import org.apache.hc.client5.http.auth.AuthSchemes; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.cookie.BasicCookieStore; import org.apache.hc.client5.http.cookie.CookieSpecProvider; @@ -112,6 +111,7 @@ import org.apache.hc.core5.http.protocol.RequestUserAgent; import org.apache.hc.core5.pool.ConnPoolControl; import org.apache.hc.core5.util.Args; import org.apache.hc.core5.util.TimeValue; +import org.apache.hc.core5.util.Timeout; import org.apache.hc.core5.util.VersionInfo; /** @@ -993,7 +993,7 @@ public class HttpClientBuilder { public void close() throws IOException { connectionEvictor.shutdown(); try { - connectionEvictor.awaitTermination(1L, TimeUnit.SECONDS); + connectionEvictor.awaitTermination(Timeout.ofSeconds(1)); } catch (final InterruptedException interrupted) { Thread.currentThread().interrupt(); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java index 5f3c7dae5..cecf114ae 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java @@ -30,7 +30,6 @@ package org.apache.hc.client5.http.impl.io; import java.io.IOException; import java.util.Date; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -340,13 +339,13 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan } } - public synchronized void closeIdle(final long idletime, final TimeUnit timeUnit) { - Args.notNull(timeUnit, "Time unit"); + public synchronized void closeIdle(final TimeValue idleTime) { + Args.notNull(idleTime, "Idle time"); if (this.closed.get()) { return; } if (!this.leased) { - long time = timeUnit.toMillis(idletime); + long time = idleTime.toMillis(); if (time < 0) { time = 0; } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestIdleConnectionEvictor.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestIdleConnectionEvictor.java index 2c14b3985..1475eb5d9 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestIdleConnectionEvictor.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/TestIdleConnectionEvictor.java @@ -27,10 +27,9 @@ package org.apache.hc.client5.http.impl; -import java.util.concurrent.TimeUnit; - import org.apache.hc.core5.pool.ConnPoolControl; 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.ArgumentMatchers; @@ -56,7 +55,7 @@ public class TestIdleConnectionEvictor { Assert.assertTrue(connectionEvictor.isRunning()); connectionEvictor.shutdown(); - connectionEvictor.awaitTermination(1, TimeUnit.SECONDS); + connectionEvictor.awaitTermination(Timeout.ofSeconds(1)); Assert.assertFalse(connectionEvictor.isRunning()); } @@ -75,7 +74,7 @@ public class TestIdleConnectionEvictor { Assert.assertTrue(connectionEvictor.isRunning()); connectionEvictor.shutdown(); - connectionEvictor.awaitTermination(1, TimeUnit.SECONDS); + connectionEvictor.awaitTermination(Timeout.ofSeconds(1)); Assert.assertFalse(connectionEvictor.isRunning()); } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestBasicHttpClientConnectionManager.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestBasicHttpClientConnectionManager.java index 51ab77bad..0f29534e1 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestBasicHttpClientConnectionManager.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestBasicHttpClientConnectionManager.java @@ -30,7 +30,6 @@ package org.apache.hc.client5.http.impl.io; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; -import java.util.concurrent.TimeUnit; import org.apache.hc.client5.http.DnsResolver; import org.apache.hc.client5.http.HttpRoute; @@ -269,7 +268,7 @@ public class TestBasicHttpClientConnectionManager { // Should have no effect mgr.closeExpired(); - mgr.closeIdle(0L, TimeUnit.MILLISECONDS); + mgr.closeIdle(TimeValue.ZERO_MILLISECONDS); mgr.close(); Mockito.verify(conn, Mockito.times(1)).close(CloseMode.GRACEFUL); @@ -324,7 +323,7 @@ public class TestBasicHttpClientConnectionManager { Thread.sleep(100); - mgr.closeIdle(50, TimeUnit.MILLISECONDS); + mgr.closeIdle(TimeValue.ofMillis(50)); Mockito.verify(conn).close(CloseMode.GRACEFUL); }