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 2018/10/05 08:24:46 UTC

httpcomponents-core git commit: Use TimeValue / Timeout to represent time values in config classes

Repository: httpcomponents-core
Updated Branches:
  refs/heads/master 7834aa523 -> 69a0ff7b2


Use TimeValue / Timeout to represent time values in config classes


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

Branch: refs/heads/master
Commit: 69a0ff7b2c51c89d0d9d6c2046cce98777d095f4
Parents: 7834aa5
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Fri Oct 5 10:11:35 2018 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Fri Oct 5 10:18:01 2018 +0200

----------------------------------------------------------------------
 .../core5/testing/nio/Http1IntegrationTest.java |  3 +-
 .../apache/hc/core5/http/config/H1Config.java   | 29 +++++++++++-------
 .../http/impl/nio/ClientHttp1StreamHandler.java |  2 +-
 .../hc/core5/reactor/IOReactorConfig.java       | 31 ++++++++++----------
 .../hc/core5/reactor/SingleCoreIOReactor.java   | 10 +++----
 .../reactor/SingleCoreListeningIOReactor.java   |  6 ++--
 6 files changed, 45 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
index 2e885d6..4b41dfe 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
@@ -128,6 +128,7 @@ import org.apache.hc.core5.testing.SSLTestContexts;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TextUtils;
 import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -872,7 +873,7 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
         });
         final InetSocketAddress serverEndpoint = server.start();
 
-        client.start(H1Config.custom().setWaitForContinueTimeoutMillis(100).build());
+        client.start(H1Config.custom().setWaitForContinueTimeout(Timeout.ofMillis(100)).build());
         final Future<ClientSessionEndpoint> connectFuture = client.connect(
                 "localhost", serverEndpoint.getPort(), TIMEOUT);
         final ClientSessionEndpoint streamEndpoint = connectFuture.get();

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
index 47bfb0f..ca44a01 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
@@ -28,6 +28,7 @@
 package org.apache.hc.core5.http.config;
 
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.Timeout;
 
 /**
  * HTTP/1.1 protocol parameters.
@@ -45,17 +46,17 @@ public class H1Config {
 
     private final int bufferSize;
     private final int chunkSizeHint;
-    private final int waitForContinueTimeoutMillis;
+    private final Timeout waitForContinueTimeout;
     private final int maxLineLength;
     private final int maxHeaderCount;
     private final int maxEmptyLineCount;
 
-    H1Config(final int bufferSize, final int chunkSizeHint, final int waitForContinueTimeout,
+    H1Config(final int bufferSize, final int chunkSizeHint, final Timeout waitForContinueTimeout,
              final int maxLineLength, final int maxHeaderCount, final int maxEmptyLineCount) {
         super();
         this.bufferSize = bufferSize;
         this.chunkSizeHint = chunkSizeHint;
-        this.waitForContinueTimeoutMillis = waitForContinueTimeout;
+        this.waitForContinueTimeout = waitForContinueTimeout;
         this.maxLineLength = maxLineLength;
         this.maxHeaderCount = maxHeaderCount;
         this.maxEmptyLineCount = maxEmptyLineCount;
@@ -69,8 +70,8 @@ public class H1Config {
         return chunkSizeHint;
     }
 
-    public int getWaitForContinueTimeoutMillis() {
-        return waitForContinueTimeoutMillis;
+    public Timeout getWaitForContinueTimeout() {
+        return waitForContinueTimeout;
     }
 
     public int getMaxLineLength() {
@@ -90,7 +91,7 @@ public class H1Config {
         final StringBuilder builder = new StringBuilder();
         builder.append("[bufferSize=").append(bufferSize)
                 .append(", chunkSizeHint=").append(chunkSizeHint)
-                .append(", waitForContinueTimeout=").append(waitForContinueTimeoutMillis)
+                .append(", waitForContinueTimeout=").append(waitForContinueTimeout)
                 .append(", maxLineLength=").append(maxLineLength)
                 .append(", maxHeaderCount=").append(maxHeaderCount)
                 .append(", maxEmptyLineCount=").append(maxEmptyLineCount)
@@ -107,7 +108,7 @@ public class H1Config {
         return new Builder()
                 .setBufferSize(config.getBufferSize())
                 .setChunkSizeHint(config.getChunkSizeHint())
-                .setWaitForContinueTimeoutMillis(config.getWaitForContinueTimeoutMillis())
+                .setWaitForContinueTimeout(config.getWaitForContinueTimeout())
                 .setMaxHeaderCount(config.getMaxHeaderCount())
                 .setMaxLineLength(config.getMaxLineLength())
                 .setMaxEmptyLineCount(config.maxEmptyLineCount);
@@ -117,7 +118,7 @@ public class H1Config {
 
         private int bufferSize;
         private int chunkSizeHint;
-        private int waitForContinueTimeout;
+        private Timeout waitForContinueTimeout;
         private int maxLineLength;
         private int maxHeaderCount;
         private int maxEmptyLineCount;
@@ -125,7 +126,7 @@ public class H1Config {
         Builder() {
             this.bufferSize = -1;
             this.chunkSizeHint = -1;
-            this.waitForContinueTimeout = 3000;
+            this.waitForContinueTimeout = Timeout.ofSeconds(3);
             this.maxLineLength = -1;
             this.maxHeaderCount = -1;
             this.maxEmptyLineCount = 10;
@@ -141,7 +142,7 @@ public class H1Config {
             return this;
         }
 
-        public Builder setWaitForContinueTimeoutMillis(final int waitForContinueTimeout) {
+        public Builder setWaitForContinueTimeout(final Timeout waitForContinueTimeout) {
             this.waitForContinueTimeout = waitForContinueTimeout;
             return this;
         }
@@ -162,7 +163,13 @@ public class H1Config {
         }
 
         public H1Config build() {
-            return new H1Config(bufferSize > 0 ? bufferSize : 8192, chunkSizeHint, waitForContinueTimeout, maxLineLength, maxHeaderCount, maxEmptyLineCount);
+            return new H1Config(
+                    bufferSize > 0 ? bufferSize : 8192,
+                    chunkSizeHint,
+                    waitForContinueTimeout != null ? waitForContinueTimeout : Timeout.ofSeconds(3),
+                    maxLineLength,
+                    maxHeaderCount,
+                    maxEmptyLineCount);
         }
 
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/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 56766af..c5e20b6 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
@@ -163,7 +163,7 @@ class ClientHttp1StreamHandler implements ResourceHolder {
                 if (expectContinue) {
                     requestState = MessageState.ACK;
                     timeout = outputChannel.getSocketTimeoutMillis();
-                    outputChannel.setSocketTimeoutMillis(h1Config.getWaitForContinueTimeoutMillis());
+                    outputChannel.setSocketTimeoutMillis(h1Config.getWaitForContinueTimeout().toMillisIntBound());
                 } else {
                     requestState = MessageState.BODY;
                     exchangeHandler.produce(internalDataChannel);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/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 b89b8e4..0b67b88 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
@@ -45,7 +45,7 @@ public final class IOReactorConfig {
 
     public static final IOReactorConfig DEFAULT = new Builder().build();
 
-    private final long selectIntervalMillis;
+    private final TimeValue selectInterval;
     private final int ioThreadCount;
     private final Timeout  soTimeout;
     private final boolean soReuseAddress;
@@ -57,7 +57,7 @@ public final class IOReactorConfig {
     private final int backlogSize;
 
     IOReactorConfig(
-            final long selectIntervalMillis,
+            final TimeValue selectInterval,
             final int ioThreadCount,
             final Timeout soTimeout,
             final boolean soReuseAddress,
@@ -68,8 +68,8 @@ public final class IOReactorConfig {
             final int rcvBufSize,
             final int backlogSize) {
         super();
-        this.selectIntervalMillis = selectIntervalMillis;
-        this.ioThreadCount = Args.positive(ioThreadCount, "ioThreadCount");
+        this.selectInterval = selectInterval;
+        this.ioThreadCount = ioThreadCount;
         this.soTimeout = soTimeout;
         this.soReuseAddress = soReuseAddress;
         this.soLinger = soLinger;
@@ -81,14 +81,14 @@ public final class IOReactorConfig {
     }
 
     /**
-     * Determines time interval in milliseconds at which the I/O reactor wakes up to check for
-     * timed out sessions and session requests.
+     * Determines time interval at which the I/O reactor wakes up to check for timed out sessions
+     * and session requests.
      * <p>
      * Default: {@code 1000} milliseconds.
      * </p>
      */
-    public long getSelectIntervalMillis() {
-        return this.selectIntervalMillis;
+    public TimeValue getSelectInterval() {
+        return this.selectInterval;
     }
 
     /**
@@ -210,7 +210,7 @@ public final class IOReactorConfig {
     public static Builder copy(final IOReactorConfig config) {
         Args.notNull(config, "I/O reactor config");
         return new Builder()
-            .setSelectIntervalMillis(config.getSelectIntervalMillis())
+            .setSelectInterval(config.getSelectInterval())
             .setIoThreadCount(config.getIoThreadCount())
             .setSoTimeout(config.getSoTimeout())
             .setSoReuseAddress(config.isSoReuseAddress())
@@ -251,7 +251,7 @@ public final class IOReactorConfig {
             DefaultMaxIoThreadCount = defaultMaxIoThreadCount;
         }
 
-        private long selectIntervalMillis;
+        private TimeValue selectInterval;
         private int ioThreadCount;
         private Timeout  soTimeout;
         private boolean soReuseAddress;
@@ -263,7 +263,7 @@ public final class IOReactorConfig {
         private int backlogSize;
 
         Builder() {
-            this.selectIntervalMillis = 1000;
+            this.selectInterval = TimeValue.ofMicroseconds(1000);
             this.ioThreadCount = Builder.getDefaultMaxIoThreadCount();
             this.soTimeout = Timeout.ZERO_MILLISECONDS;
             this.soReuseAddress = false;
@@ -275,8 +275,8 @@ public final class IOReactorConfig {
             this.backlogSize = 0;
         }
 
-        public Builder setSelectIntervalMillis(final long selectIntervalMillis) {
-            this.selectIntervalMillis = selectIntervalMillis;
+        public Builder setSelectInterval(final TimeValue selectInterval) {
+            this.selectInterval = selectInterval;
             return this;
         }
 
@@ -337,7 +337,8 @@ public final class IOReactorConfig {
 
         public IOReactorConfig build() {
             return new IOReactorConfig(
-                    selectIntervalMillis, ioThreadCount,
+                    selectInterval != null ? selectInterval : TimeValue.ofMicroseconds(1000),
+                    ioThreadCount,
                     Timeout.defaultsToDisabled(soTimeout),
                     soReuseAddress,
                     TimeValue.defaultsToNegativeOneMillisecond(soLinger),
@@ -351,7 +352,7 @@ public final class IOReactorConfig {
     @Override
     public String toString() {
         final StringBuilder builder = new StringBuilder();
-        builder.append("[selectIntervalMillis=").append(this.selectIntervalMillis)
+        builder.append("[selectIntervalMillis=").append(this.selectInterval)
                 .append(", ioThreadCount=").append(this.ioThreadCount)
                 .append(", soTimeout=").append(this.soTimeout)
                 .append(", soReuseAddress=").append(this.soReuseAddress)

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
index a031de7..ab6c155 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
@@ -46,9 +46,9 @@ import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.io.Closer;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.io.Closer;
 import org.apache.hc.core5.util.TimeValue;
 
 class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements ConnectionInitiator {
@@ -64,7 +64,7 @@ class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements Connect
     private final Queue<SocketChannel> channelQueue;
     private final Queue<IOSessionRequest> requestQueue;
     private final AtomicBoolean shutdownInitiated;
-
+    private final long selectTimeoutMillis;
     private volatile long lastTimeoutCheckMillis;
 
     SingleCoreIOReactor(
@@ -84,6 +84,7 @@ class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements Connect
         this.closedSessions = new ConcurrentLinkedQueue<>();
         this.channelQueue = new ConcurrentLinkedQueue<>();
         this.requestQueue = new ConcurrentLinkedQueue<>();
+        this.selectTimeoutMillis = this.reactorConfig.getSelectInterval().toMillis();
     }
 
     void enqueueChannel(final SocketChannel socketChannel) throws IOReactorShutdownException {
@@ -104,10 +105,9 @@ class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements Connect
 
     @Override
     void doExecute() throws IOException {
-        final long selectTimeoutMillis = this.reactorConfig.getSelectIntervalMillis();
         while (!Thread.currentThread().isInterrupted()) {
 
-            final int readyCount = this.selector.select(selectTimeoutMillis);
+            final int readyCount = this.selector.select(this.selectTimeoutMillis);
 
             if (getStatus().compareTo(IOReactorStatus.SHUTTING_DOWN) >= 0) {
                 if (this.shutdownInitiated.compareAndSet(false, true)) {
@@ -159,7 +159,7 @@ class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements Connect
 
     private void validateActiveChannels() {
         final long currentTimeMillis = System.currentTimeMillis();
-        if ((currentTimeMillis - this.lastTimeoutCheckMillis) >= this.reactorConfig.getSelectIntervalMillis()) {
+        if ((currentTimeMillis - this.lastTimeoutCheckMillis) >= this.selectTimeoutMillis) {
             this.lastTimeoutCheckMillis = currentTimeMillis;
             for (final SelectionKey key : this.selector.keys()) {
                 checkTimeout(key, currentTimeMillis);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
index 6496712..91b1b22 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
@@ -55,8 +55,8 @@ class SingleCoreListeningIOReactor extends AbstractSingleCoreIOReactor implement
     private final Callback<SocketChannel> callback;
     private final Queue<ListenerEndpointRequest> requestQueue;
     private final ConcurrentMap<ListenerEndpoint, Boolean> endpoints;
-
     private final AtomicBoolean paused;
+    private final long selectTimeoutMillis;
 
     SingleCoreListeningIOReactor(
             final Queue<ExceptionEvent> auditLog,
@@ -68,6 +68,7 @@ class SingleCoreListeningIOReactor extends AbstractSingleCoreIOReactor implement
         this.requestQueue = new ConcurrentLinkedQueue<>();
         this.endpoints = new ConcurrentHashMap<>();
         this.paused = new AtomicBoolean(false);
+        this.selectTimeoutMillis = this.reactorConfig.getSelectInterval().toMillis();
     }
 
     @Override
@@ -80,13 +81,12 @@ class SingleCoreListeningIOReactor extends AbstractSingleCoreIOReactor implement
 
     @Override
     protected final void doExecute() throws IOException {
-        final long selectTimeoutMillis = this.reactorConfig.getSelectIntervalMillis();
         while (!Thread.currentThread().isInterrupted()) {
             if (getStatus().compareTo(IOReactorStatus.ACTIVE) != 0) {
                 break;
             }
 
-            final int readyCount = this.selector.select(selectTimeoutMillis);
+            final int readyCount = this.selector.select(this.selectTimeoutMillis);
 
             if (getStatus().compareTo(IOReactorStatus.ACTIVE) != 0) {
                 break;


Re: Fwd: httpcomponents-core git commit: Use TimeValue / Timeout to represent time values in config classes

Posted by Gary Gregory <ga...@gmail.com>.
On Sat, Oct 6, 2018 at 1:23 PM Michael Osipov <mi...@apache.org> wrote:

> Am 2018-10-06 um 21:15 schrieb Gary Gregory:
> > On Sat, Oct 6, 2018 at 12:57 PM Michael Osipov <mi...@apache.org>
> wrote:
> >
> >> Am 2018-10-06 um 19:37 schrieb Oleg Kalnichevski:
> >>> On Sat, 2018-10-06 at 10:03 +0200, Michael Osipov wrote:
> >>>> I like it a lot too, but why are internal value retained as int/long
> >>>> and
> >>>> not use the TimeValue clasS?
> >>>>
> >>>
> >>> Should they be?
> >>
> >>   From a consistency point of view doesn't it make sense? Otherwise if
> >> the int/long is an implementation detail and is not exposed outside that
> >> is perfectly fine I think.
> >>
> >
> > One thing that sucks is that TimeUnit millis are longs and that low level
> > APIs like Socket timeout take int millis.
>
> Yet, that is awkward throughout the entire JDK. I'd expect long
> everywhere where milliseconds have to be provided. E.g.,
> Thread#sleep(long).
>

FWIW, I'm all for using TimeUnit in all APIs, not just the public ones.
Then in whatever crucial spots we can deal with int vs. long.

Gary

>
> M
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

Re: Fwd: httpcomponents-core git commit: Use TimeValue / Timeout to represent time values in config classes

Posted by Michael Osipov <mi...@apache.org>.
Am 2018-10-06 um 21:15 schrieb Gary Gregory:
> On Sat, Oct 6, 2018 at 12:57 PM Michael Osipov <mi...@apache.org> wrote:
> 
>> Am 2018-10-06 um 19:37 schrieb Oleg Kalnichevski:
>>> On Sat, 2018-10-06 at 10:03 +0200, Michael Osipov wrote:
>>>> I like it a lot too, but why are internal value retained as int/long
>>>> and
>>>> not use the TimeValue clasS?
>>>>
>>>
>>> Should they be?
>>
>>   From a consistency point of view doesn't it make sense? Otherwise if
>> the int/long is an implementation detail and is not exposed outside that
>> is perfectly fine I think.
>>
> 
> One thing that sucks is that TimeUnit millis are longs and that low level
> APIs like Socket timeout take int millis.

Yet, that is awkward throughout the entire JDK. I'd expect long 
everywhere where milliseconds have to be provided. E.g., Thread#sleep(long).

M

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: Fwd: httpcomponents-core git commit: Use TimeValue / Timeout to represent time values in config classes

Posted by Gary Gregory <ga...@gmail.com>.
On Sat, Oct 6, 2018 at 12:57 PM Michael Osipov <mi...@apache.org> wrote:

> Am 2018-10-06 um 19:37 schrieb Oleg Kalnichevski:
> > On Sat, 2018-10-06 at 10:03 +0200, Michael Osipov wrote:
> >> I like it a lot too, but why are internal value retained as int/long
> >> and
> >> not use the TimeValue clasS?
> >>
> >
> > Should they be?
>
>  From a consistency point of view doesn't it make sense? Otherwise if
> the int/long is an implementation detail and is not exposed outside that
> is perfectly fine I think.
>

One thing that sucks is that TimeUnit millis are longs and that low level
APIs like Socket timeout take int millis.

Gary


>
> Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

Re: Fwd: httpcomponents-core git commit: Use TimeValue / Timeout to represent time values in config classes

Posted by Michael Osipov <mi...@apache.org>.
Am 2018-10-06 um 19:37 schrieb Oleg Kalnichevski:
> On Sat, 2018-10-06 at 10:03 +0200, Michael Osipov wrote:
>> I like it a lot too, but why are internal value retained as int/long
>> and
>> not use the TimeValue clasS?
>>
> 
> Should they be?

 From a consistency point of view doesn't it make sense? Otherwise if 
the int/long is an implementation detail and is not exposed outside that 
is perfectly fine I think.

Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: Fwd: httpcomponents-core git commit: Use TimeValue / Timeout to represent time values in config classes

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sat, 2018-10-06 at 10:03 +0200, Michael Osipov wrote:
> I like it a lot too, but why are internal value retained as int/long
> and 
> not use the TimeValue clasS?
> 

Should they be?

Oleg


> Am 2018-10-05 um 16:05 schrieb Gary Gregory:
> > Nice! :-)
> > 
> > Gary
> > 
> > ---------- Forwarded message ---------
> > From: <ol...@apache.org>
> > Date: Fri, Oct 5, 2018 at 2:24 AM
> > Subject: httpcomponents-core git commit: Use TimeValue / Timeout to
> > represent time values in config classes
> > To: <co...@hc.apache.org>
> > 
> > 
> > Repository: httpcomponents-core
> > Updated Branches:
> >    refs/heads/master 7834aa523 -> 69a0ff7b2
> > 
> > 
> > Use TimeValue / Timeout to represent time values in config classes
> > 
> > 
> > Project: 
> > http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
> > Commit:
> > 
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/69a0ff7b
> > Tree:
> > 
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/69a0ff7b
> > Diff:
> > 
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/69a0ff7b
> > 
> > Branch: refs/heads/master
> > Commit: 69a0ff7b2c51c89d0d9d6c2046cce98777d095f4
> > Parents: 7834aa5
> > Author: Oleg Kalnichevski <ol...@apache.org>
> > Authored: Fri Oct 5 10:11:35 2018 +0200
> > Committer: Oleg Kalnichevski <ol...@apache.org>
> > Committed: Fri Oct 5 10:18:01 2018 +0200
> > 
> > -----------------------------------------------------------------
> > -----
> >   .../core5/testing/nio/Http1IntegrationTest.java |  3 +-
> >   .../apache/hc/core5/http/config/H1Config.java   | 29 +++++++++++-
> > ------
> >   .../http/impl/nio/ClientHttp1StreamHandler.java |  2 +-
> >   .../hc/core5/reactor/IOReactorConfig.java       | 31 ++++++++++
> > ----------
> >   .../hc/core5/reactor/SingleCoreIOReactor.java   | 10 +++----
> >   .../reactor/SingleCoreListeningIOReactor.java   |  6 ++--
> >   6 files changed, 45 insertions(+), 36 deletions(-)
> > -----------------------------------------------------------------
> > -----
> > 
> > 
> > 
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
> > -----------------------------------------------------------------
> > -----
> > diff --git
> > a/httpcore5-
> > testing/src/test/java/org/apache/hc/core5/testing/nio/Http1Integrat
> > ionTest.java
> > b/httpcore5-
> > testing/src/test/java/org/apache/hc/core5/testing/nio/Http1Integrat
> > ionTest.java
> > index 2e885d6..4b41dfe 100644
> > ---
> > a/httpcore5-
> > testing/src/test/java/org/apache/hc/core5/testing/nio/Http1Integrat
> > ionTest.java
> > +++
> > b/httpcore5-
> > testing/src/test/java/org/apache/hc/core5/testing/nio/Http1Integrat
> > ionTest.java
> > @@ -128,6 +128,7 @@ import
> > org.apache.hc.core5.testing.SSLTestContexts;
> >   import org.apache.hc.core5.util.CharArrayBuffer;
> >   import org.apache.hc.core5.util.TextUtils;
> >   import org.apache.hc.core5.util.TimeValue;
> > +import org.apache.hc.core5.util.Timeout;
> >   import org.junit.After;
> >   import org.junit.Assert;
> >   import org.junit.Before;
> > @@ -872,7 +873,7 @@ public class Http1IntegrationTest extends
> > InternalHttp1ServerTestBase {
> >           });
> >           final InetSocketAddress serverEndpoint = server.start();
> > 
> > -
> > client.start(H1Config.custom().setWaitForContinueTimeoutMillis(100)
> > .build());
> > +
> > client.start(H1Config.custom().setWaitForContinueTimeout(Timeout.of
> > Millis(100)).build());
> >           final Future<ClientSessionEndpoint> connectFuture =
> > client.connect(
> >                   "localhost", serverEndpoint.getPort(), TIMEOUT);
> >           final ClientSessionEndpoint streamEndpoint =
> > connectFuture.get();
> > 
> > 
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
> > -----------------------------------------------------------------
> > -----
> > diff --git
> > a/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.
> > java
> > b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.
> > java
> > index 47bfb0f..ca44a01 100644
> > ---
> > a/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.
> > java
> > +++
> > b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.
> > java
> > @@ -28,6 +28,7 @@
> >   package org.apache.hc.core5.http.config;
> > 
> >   import org.apache.hc.core5.util.Args;
> > +import org.apache.hc.core5.util.Timeout;
> > 
> >   /**
> >    * HTTP/1.1 protocol parameters.
> > @@ -45,17 +46,17 @@ public class H1Config {
> > 
> >       private final int bufferSize;
> >       private final int chunkSizeHint;
> > -    private final int waitForContinueTimeoutMillis;
> > +    private final Timeout waitForContinueTimeout;
> >       private final int maxLineLength;
> >       private final int maxHeaderCount;
> >       private final int maxEmptyLineCount;
> > 
> > -    H1Config(final int bufferSize, final int chunkSizeHint, final
> > int
> > waitForContinueTimeout,
> > +    H1Config(final int bufferSize, final int chunkSizeHint, final
> > Timeout
> > waitForContinueTimeout,
> >                final int maxLineLength, final int maxHeaderCount,
> > final int
> > maxEmptyLineCount) {
> >           super();
> >           this.bufferSize = bufferSize;
> >           this.chunkSizeHint = chunkSizeHint;
> > -        this.waitForContinueTimeoutMillis =
> > waitForContinueTimeout;
> > +        this.waitForContinueTimeout = waitForContinueTimeout;
> >           this.maxLineLength = maxLineLength;
> >           this.maxHeaderCount = maxHeaderCount;
> >           this.maxEmptyLineCount = maxEmptyLineCount;
> > @@ -69,8 +70,8 @@ public class H1Config {
> >           return chunkSizeHint;
> >       }
> > 
> > -    public int getWaitForContinueTimeoutMillis() {
> > -        return waitForContinueTimeoutMillis;
> > +    public Timeout getWaitForContinueTimeout() {
> > +        return waitForContinueTimeout;
> >       }
> > 
> >       public int getMaxLineLength() {
> > @@ -90,7 +91,7 @@ public class H1Config {
> >           final StringBuilder builder = new StringBuilder();
> >           builder.append("[bufferSize=").append(bufferSize)
> >                   .append(", chunkSizeHint=").append(chunkSizeHint)
> > -                .append(",
> > waitForContinueTimeout=").append(waitForContinueTimeoutMillis)
> > +                .append(",
> > waitForContinueTimeout=").append(waitForContinueTimeout)
> >                   .append(", maxLineLength=").append(maxLineLength)
> >                   .append(",
> > maxHeaderCount=").append(maxHeaderCount)
> >                   .append(",
> > maxEmptyLineCount=").append(maxEmptyLineCount)
> > @@ -107,7 +108,7 @@ public class H1Config {
> >           return new Builder()
> >                   .setBufferSize(config.getBufferSize())
> >                   .setChunkSizeHint(config.getChunkSizeHint())
> > -
> > .setWaitForContinueTimeoutMillis(config.getWaitForContinueTimeoutMi
> > llis())
> > +
> > .setWaitForContinueTimeout(config.getWaitForContinueTimeout())
> >                   .setMaxHeaderCount(config.getMaxHeaderCount())
> >                   .setMaxLineLength(config.getMaxLineLength())
> >                   .setMaxEmptyLineCount(config.maxEmptyLineCount);
> > @@ -117,7 +118,7 @@ public class H1Config {
> > 
> >           private int bufferSize;
> >           private int chunkSizeHint;
> > -        private int waitForContinueTimeout;
> > +        private Timeout waitForContinueTimeout;
> >           private int maxLineLength;
> >           private int maxHeaderCount;
> >           private int maxEmptyLineCount;
> > @@ -125,7 +126,7 @@ public class H1Config {
> >           Builder() {
> >               this.bufferSize = -1;
> >               this.chunkSizeHint = -1;
> > -            this.waitForContinueTimeout = 3000;
> > +            this.waitForContinueTimeout = Timeout.ofSeconds(3);
> >               this.maxLineLength = -1;
> >               this.maxHeaderCount = -1;
> >               this.maxEmptyLineCount = 10;
> > @@ -141,7 +142,7 @@ public class H1Config {
> >               return this;
> >           }
> > 
> > -        public Builder setWaitForContinueTimeoutMillis(final int
> > waitForContinueTimeout) {
> > +        public Builder setWaitForContinueTimeout(final Timeout
> > waitForContinueTimeout) {
> >               this.waitForContinueTimeout = waitForContinueTimeout;
> >               return this;
> >           }
> > @@ -162,7 +163,13 @@ public class H1Config {
> >           }
> > 
> >           public H1Config build() {
> > -            return new H1Config(bufferSize > 0 ? bufferSize :
> > 8192,
> > chunkSizeHint, waitForContinueTimeout, maxLineLength,
> > maxHeaderCount,
> > maxEmptyLineCount);
> > +            return new H1Config(
> > +                    bufferSize > 0 ? bufferSize : 8192,
> > +                    chunkSizeHint,
> > +                    waitForContinueTimeout != null ?
> > waitForContinueTimeout : Timeout.ofSeconds(3),
> > +                    maxLineLength,
> > +                    maxHeaderCount,
> > +                    maxEmptyLineCount);
> >           }
> > 
> >       }
> > 
> > 
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/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/ClientH
> > ttp1StreamHandler.java
> > b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientH
> > ttp1StreamHandler.java
> > index 56766af..c5e20b6 100644
> > ---
> > a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientH
> > ttp1StreamHandler.java
> > +++
> > b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientH
> > ttp1StreamHandler.java
> > @@ -163,7 +163,7 @@ class ClientHttp1StreamHandler implements
> > ResourceHolder {
> >                   if (expectContinue) {
> >                       requestState = MessageState.ACK;
> >                       timeout =
> > outputChannel.getSocketTimeoutMillis();
> > -
> > outputChannel.setSocketTimeoutMillis(h1Config.getWaitForContinueTim
> > eoutMillis());
> > +
> > outputChannel.setSocketTimeoutMillis(h1Config.getWaitForContinueTim
> > eout().toMillisIntBound());
> >                   } else {
> >                       requestState = MessageState.BODY;
> >                       exchangeHandler.produce(internalDataChannel);
> > 
> > 
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java
> > -----------------------------------------------------------------
> > -----
> > diff --git
> > a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConf
> > ig.java
> > b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConf
> > ig.java
> > index b89b8e4..0b67b88 100644
> > ---
> > a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConf
> > ig.java
> > +++
> > b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConf
> > ig.java
> > @@ -45,7 +45,7 @@ public final class IOReactorConfig {
> > 
> >       public static final IOReactorConfig DEFAULT = new
> > Builder().build();
> > 
> > -    private final long selectIntervalMillis;
> > +    private final TimeValue selectInterval;
> >       private final int ioThreadCount;
> >       private final Timeout  soTimeout;
> >       private final boolean soReuseAddress;
> > @@ -57,7 +57,7 @@ public final class IOReactorConfig {
> >       private final int backlogSize;
> > 
> >       IOReactorConfig(
> > -            final long selectIntervalMillis,
> > +            final TimeValue selectInterval,
> >               final int ioThreadCount,
> >               final Timeout soTimeout,
> >               final boolean soReuseAddress,
> > @@ -68,8 +68,8 @@ public final class IOReactorConfig {
> >               final int rcvBufSize,
> >               final int backlogSize) {
> >           super();
> > -        this.selectIntervalMillis = selectIntervalMillis;
> > -        this.ioThreadCount = Args.positive(ioThreadCount,
> > "ioThreadCount");
> > +        this.selectInterval = selectInterval;
> > +        this.ioThreadCount = ioThreadCount;
> >           this.soTimeout = soTimeout;
> >           this.soReuseAddress = soReuseAddress;
> >           this.soLinger = soLinger;
> > @@ -81,14 +81,14 @@ public final class IOReactorConfig {
> >       }
> > 
> >       /**
> > -     * Determines time interval in milliseconds at which the I/O
> > reactor
> > wakes up to check for
> > -     * timed out sessions and session requests.
> > +     * Determines time interval at which the I/O reactor wakes up
> > to check
> > for timed out sessions
> > +     * and session requests.
> >        * <p>
> >        * Default: {@code 1000} milliseconds.
> >        * </p>
> >        */
> > -    public long getSelectIntervalMillis() {
> > -        return this.selectIntervalMillis;
> > +    public TimeValue getSelectInterval() {
> > +        return this.selectInterval;
> >       }
> > 
> >       /**
> > @@ -210,7 +210,7 @@ public final class IOReactorConfig {
> >       public static Builder copy(final IOReactorConfig config) {
> >           Args.notNull(config, "I/O reactor config");
> >           return new Builder()
> > -            .setSelectIntervalMillis(config.getSelectIntervalMilli
> > s())
> > +            .setSelectInterval(config.getSelectInterval())
> >               .setIoThreadCount(config.getIoThreadCount())
> >               .setSoTimeout(config.getSoTimeout())
> >               .setSoReuseAddress(config.isSoReuseAddress())
> > @@ -251,7 +251,7 @@ public final class IOReactorConfig {
> >               DefaultMaxIoThreadCount = defaultMaxIoThreadCount;
> >           }
> > 
> > -        private long selectIntervalMillis;
> > +        private TimeValue selectInterval;
> >           private int ioThreadCount;
> >           private Timeout  soTimeout;
> >           private boolean soReuseAddress;
> > @@ -263,7 +263,7 @@ public final class IOReactorConfig {
> >           private int backlogSize;
> > 
> >           Builder() {
> > -            this.selectIntervalMillis = 1000;
> > +            this.selectInterval = TimeValue.ofMicroseconds(1000);
> >               this.ioThreadCount =
> > Builder.getDefaultMaxIoThreadCount();
> >               this.soTimeout = Timeout.ZERO_MILLISECONDS;
> >               this.soReuseAddress = false;
> > @@ -275,8 +275,8 @@ public final class IOReactorConfig {
> >               this.backlogSize = 0;
> >           }
> > 
> > -        public Builder setSelectIntervalMillis(final long
> > selectIntervalMillis) {
> > -            this.selectIntervalMillis = selectIntervalMillis;
> > +        public Builder setSelectInterval(final TimeValue
> > selectInterval) {
> > +            this.selectInterval = selectInterval;
> >               return this;
> >           }
> > 
> > @@ -337,7 +337,8 @@ public final class IOReactorConfig {
> > 
> >           public IOReactorConfig build() {
> >               return new IOReactorConfig(
> > -                    selectIntervalMillis, ioThreadCount,
> > +                    selectInterval != null ? selectInterval :
> > TimeValue.ofMicroseconds(1000),
> > +                    ioThreadCount,
> >                       Timeout.defaultsToDisabled(soTimeout),
> >                       soReuseAddress,
> >                       TimeValue.defaultsToNegativeOneMillisecond(so
> > Linger),
> > @@ -351,7 +352,7 @@ public final class IOReactorConfig {
> >       @Override
> >       public String toString() {
> >           final StringBuilder builder = new StringBuilder();
> > -
> > builder.append("[selectIntervalMillis=").append(this.selectInterval
> > Millis)
> > +
> > builder.append("[selectIntervalMillis=").append(this.selectInterval
> > )
> >                   .append(",
> > ioThreadCount=").append(this.ioThreadCount)
> >                   .append(", soTimeout=").append(this.soTimeout)
> >                   .append(",
> > soReuseAddress=").append(this.soReuseAddress)
> > 
> > 
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
> > -----------------------------------------------------------------
> > -----
> > diff --git
> > a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOR
> > eactor.java
> > b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOR
> > eactor.java
> > index a031de7..ab6c155 100644
> > ---
> > a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOR
> > eactor.java
> > +++
> > b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOR
> > eactor.java
> > @@ -46,9 +46,9 @@ import
> > org.apache.hc.core5.concurrent.FutureCallback;
> >   import org.apache.hc.core5.function.Callback;
> >   import org.apache.hc.core5.function.Decorator;
> >   import org.apache.hc.core5.io.CloseMode;
> > +import org.apache.hc.core5.io.Closer;
> >   import org.apache.hc.core5.net.NamedEndpoint;
> >   import org.apache.hc.core5.util.Args;
> > -import org.apache.hc.core5.io.Closer;
> >   import org.apache.hc.core5.util.TimeValue;
> > 
> >   class SingleCoreIOReactor extends AbstractSingleCoreIOReactor
> > implements
> > ConnectionInitiator {
> > @@ -64,7 +64,7 @@ class SingleCoreIOReactor extends
> > AbstractSingleCoreIOReactor implements Connect
> >       private final Queue<SocketChannel> channelQueue;
> >       private final Queue<IOSessionRequest> requestQueue;
> >       private final AtomicBoolean shutdownInitiated;
> > -
> > +    private final long selectTimeoutMillis;
> >       private volatile long lastTimeoutCheckMillis;
> > 
> >       SingleCoreIOReactor(
> > @@ -84,6 +84,7 @@ class SingleCoreIOReactor extends
> > AbstractSingleCoreIOReactor implements Connect
> >           this.closedSessions = new ConcurrentLinkedQueue<>();
> >           this.channelQueue = new ConcurrentLinkedQueue<>();
> >           this.requestQueue = new ConcurrentLinkedQueue<>();
> > +        this.selectTimeoutMillis =
> > this.reactorConfig.getSelectInterval().toMillis();
> >       }
> > 
> >       void enqueueChannel(final SocketChannel socketChannel) throws
> > IOReactorShutdownException {
> > @@ -104,10 +105,9 @@ class SingleCoreIOReactor extends
> > AbstractSingleCoreIOReactor implements Connect
> > 
> >       @Override
> >       void doExecute() throws IOException {
> > -        final long selectTimeoutMillis =
> > this.reactorConfig.getSelectIntervalMillis();
> >           while (!Thread.currentThread().isInterrupted()) {
> > 
> > -            final int readyCount =
> > this.selector.select(selectTimeoutMillis);
> > +            final int readyCount =
> > this.selector.select(this.selectTimeoutMillis);
> > 
> >               if
> > (getStatus().compareTo(IOReactorStatus.SHUTTING_DOWN) >= 0)
> > {
> >                   if (this.shutdownInitiated.compareAndSet(false,
> > true)) {
> > @@ -159,7 +159,7 @@ class SingleCoreIOReactor extends
> > AbstractSingleCoreIOReactor implements Connect
> > 
> >       private void validateActiveChannels() {
> >           final long currentTimeMillis =
> > System.currentTimeMillis();
> > -        if ((currentTimeMillis - this.lastTimeoutCheckMillis) >=
> > this.reactorConfig.getSelectIntervalMillis()) {
> > +        if ((currentTimeMillis - this.lastTimeoutCheckMillis) >=
> > this.selectTimeoutMillis) {
> >               this.lastTimeoutCheckMillis = currentTimeMillis;
> >               for (final SelectionKey key : this.selector.keys()) {
> >                   checkTimeout(key, currentTimeMillis);
> > 
> > 
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
> > -----------------------------------------------------------------
> > -----
> > diff --git
> > a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreLis
> > teningIOReactor.java
> > b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreLis
> > teningIOReactor.java
> > index 6496712..91b1b22 100644
> > ---
> > a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreLis
> > teningIOReactor.java
> > +++
> > b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreLis
> > teningIOReactor.java
> > @@ -55,8 +55,8 @@ class SingleCoreListeningIOReactor extends
> > AbstractSingleCoreIOReactor implement
> >       private final Callback<SocketChannel> callback;
> >       private final Queue<ListenerEndpointRequest> requestQueue;
> >       private final ConcurrentMap<ListenerEndpoint, Boolean>
> > endpoints;
> > -
> >       private final AtomicBoolean paused;
> > +    private final long selectTimeoutMillis;
> > 
> >       SingleCoreListeningIOReactor(
> >               final Queue<ExceptionEvent> auditLog,
> > @@ -68,6 +68,7 @@ class SingleCoreListeningIOReactor extends
> > AbstractSingleCoreIOReactor implement
> >           this.requestQueue = new ConcurrentLinkedQueue<>();
> >           this.endpoints = new ConcurrentHashMap<>();
> >           this.paused = new AtomicBoolean(false);
> > +        this.selectTimeoutMillis =
> > this.reactorConfig.getSelectInterval().toMillis();
> >       }
> > 
> >       @Override
> > @@ -80,13 +81,12 @@ class SingleCoreListeningIOReactor extends
> > AbstractSingleCoreIOReactor implement
> > 
> >       @Override
> >       protected final void doExecute() throws IOException {
> > -        final long selectTimeoutMillis =
> > this.reactorConfig.getSelectIntervalMillis();
> >           while (!Thread.currentThread().isInterrupted()) {
> >               if (getStatus().compareTo(IOReactorStatus.ACTIVE) !=
> > 0) {
> >                   break;
> >               }
> > 
> > -            final int readyCount =
> > this.selector.select(selectTimeoutMillis);
> > +            final int readyCount =
> > this.selector.select(this.selectTimeoutMillis);
> > 
> >               if (getStatus().compareTo(IOReactorStatus.ACTIVE) !=
> > 0) {
> >                   break;
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: Fwd: httpcomponents-core git commit: Use TimeValue / Timeout to represent time values in config classes

Posted by Michael Osipov <mi...@apache.org>.
I like it a lot too, but why are internal value retained as int/long and 
not use the TimeValue clasS?

Am 2018-10-05 um 16:05 schrieb Gary Gregory:
> Nice! :-)
> 
> Gary
> 
> ---------- Forwarded message ---------
> From: <ol...@apache.org>
> Date: Fri, Oct 5, 2018 at 2:24 AM
> Subject: httpcomponents-core git commit: Use TimeValue / Timeout to
> represent time values in config classes
> To: <co...@hc.apache.org>
> 
> 
> Repository: httpcomponents-core
> Updated Branches:
>    refs/heads/master 7834aa523 -> 69a0ff7b2
> 
> 
> Use TimeValue / Timeout to represent time values in config classes
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
> Commit:
> http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/69a0ff7b
> Tree:
> http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/69a0ff7b
> Diff:
> http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/69a0ff7b
> 
> Branch: refs/heads/master
> Commit: 69a0ff7b2c51c89d0d9d6c2046cce98777d095f4
> Parents: 7834aa5
> Author: Oleg Kalnichevski <ol...@apache.org>
> Authored: Fri Oct 5 10:11:35 2018 +0200
> Committer: Oleg Kalnichevski <ol...@apache.org>
> Committed: Fri Oct 5 10:18:01 2018 +0200
> 
> ----------------------------------------------------------------------
>   .../core5/testing/nio/Http1IntegrationTest.java |  3 +-
>   .../apache/hc/core5/http/config/H1Config.java   | 29 +++++++++++-------
>   .../http/impl/nio/ClientHttp1StreamHandler.java |  2 +-
>   .../hc/core5/reactor/IOReactorConfig.java       | 31 ++++++++++----------
>   .../hc/core5/reactor/SingleCoreIOReactor.java   | 10 +++----
>   .../reactor/SingleCoreListeningIOReactor.java   |  6 ++--
>   6 files changed, 45 insertions(+), 36 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
> ----------------------------------------------------------------------
> diff --git
> a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
> b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
> index 2e885d6..4b41dfe 100644
> ---
> a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
> +++
> b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
> @@ -128,6 +128,7 @@ import org.apache.hc.core5.testing.SSLTestContexts;
>   import org.apache.hc.core5.util.CharArrayBuffer;
>   import org.apache.hc.core5.util.TextUtils;
>   import org.apache.hc.core5.util.TimeValue;
> +import org.apache.hc.core5.util.Timeout;
>   import org.junit.After;
>   import org.junit.Assert;
>   import org.junit.Before;
> @@ -872,7 +873,7 @@ public class Http1IntegrationTest extends
> InternalHttp1ServerTestBase {
>           });
>           final InetSocketAddress serverEndpoint = server.start();
> 
> -
> client.start(H1Config.custom().setWaitForContinueTimeoutMillis(100).build());
> +
> client.start(H1Config.custom().setWaitForContinueTimeout(Timeout.ofMillis(100)).build());
>           final Future<ClientSessionEndpoint> connectFuture = client.connect(
>                   "localhost", serverEndpoint.getPort(), TIMEOUT);
>           final ClientSessionEndpoint streamEndpoint = connectFuture.get();
> 
> http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
> ----------------------------------------------------------------------
> diff --git
> a/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
> b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
> index 47bfb0f..ca44a01 100644
> --- a/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
> +++ b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
> @@ -28,6 +28,7 @@
>   package org.apache.hc.core5.http.config;
> 
>   import org.apache.hc.core5.util.Args;
> +import org.apache.hc.core5.util.Timeout;
> 
>   /**
>    * HTTP/1.1 protocol parameters.
> @@ -45,17 +46,17 @@ public class H1Config {
> 
>       private final int bufferSize;
>       private final int chunkSizeHint;
> -    private final int waitForContinueTimeoutMillis;
> +    private final Timeout waitForContinueTimeout;
>       private final int maxLineLength;
>       private final int maxHeaderCount;
>       private final int maxEmptyLineCount;
> 
> -    H1Config(final int bufferSize, final int chunkSizeHint, final int
> waitForContinueTimeout,
> +    H1Config(final int bufferSize, final int chunkSizeHint, final Timeout
> waitForContinueTimeout,
>                final int maxLineLength, final int maxHeaderCount, final int
> maxEmptyLineCount) {
>           super();
>           this.bufferSize = bufferSize;
>           this.chunkSizeHint = chunkSizeHint;
> -        this.waitForContinueTimeoutMillis = waitForContinueTimeout;
> +        this.waitForContinueTimeout = waitForContinueTimeout;
>           this.maxLineLength = maxLineLength;
>           this.maxHeaderCount = maxHeaderCount;
>           this.maxEmptyLineCount = maxEmptyLineCount;
> @@ -69,8 +70,8 @@ public class H1Config {
>           return chunkSizeHint;
>       }
> 
> -    public int getWaitForContinueTimeoutMillis() {
> -        return waitForContinueTimeoutMillis;
> +    public Timeout getWaitForContinueTimeout() {
> +        return waitForContinueTimeout;
>       }
> 
>       public int getMaxLineLength() {
> @@ -90,7 +91,7 @@ public class H1Config {
>           final StringBuilder builder = new StringBuilder();
>           builder.append("[bufferSize=").append(bufferSize)
>                   .append(", chunkSizeHint=").append(chunkSizeHint)
> -                .append(",
> waitForContinueTimeout=").append(waitForContinueTimeoutMillis)
> +                .append(",
> waitForContinueTimeout=").append(waitForContinueTimeout)
>                   .append(", maxLineLength=").append(maxLineLength)
>                   .append(", maxHeaderCount=").append(maxHeaderCount)
>                   .append(", maxEmptyLineCount=").append(maxEmptyLineCount)
> @@ -107,7 +108,7 @@ public class H1Config {
>           return new Builder()
>                   .setBufferSize(config.getBufferSize())
>                   .setChunkSizeHint(config.getChunkSizeHint())
> -
> .setWaitForContinueTimeoutMillis(config.getWaitForContinueTimeoutMillis())
> +
> .setWaitForContinueTimeout(config.getWaitForContinueTimeout())
>                   .setMaxHeaderCount(config.getMaxHeaderCount())
>                   .setMaxLineLength(config.getMaxLineLength())
>                   .setMaxEmptyLineCount(config.maxEmptyLineCount);
> @@ -117,7 +118,7 @@ public class H1Config {
> 
>           private int bufferSize;
>           private int chunkSizeHint;
> -        private int waitForContinueTimeout;
> +        private Timeout waitForContinueTimeout;
>           private int maxLineLength;
>           private int maxHeaderCount;
>           private int maxEmptyLineCount;
> @@ -125,7 +126,7 @@ public class H1Config {
>           Builder() {
>               this.bufferSize = -1;
>               this.chunkSizeHint = -1;
> -            this.waitForContinueTimeout = 3000;
> +            this.waitForContinueTimeout = Timeout.ofSeconds(3);
>               this.maxLineLength = -1;
>               this.maxHeaderCount = -1;
>               this.maxEmptyLineCount = 10;
> @@ -141,7 +142,7 @@ public class H1Config {
>               return this;
>           }
> 
> -        public Builder setWaitForContinueTimeoutMillis(final int
> waitForContinueTimeout) {
> +        public Builder setWaitForContinueTimeout(final Timeout
> waitForContinueTimeout) {
>               this.waitForContinueTimeout = waitForContinueTimeout;
>               return this;
>           }
> @@ -162,7 +163,13 @@ public class H1Config {
>           }
> 
>           public H1Config build() {
> -            return new H1Config(bufferSize > 0 ? bufferSize : 8192,
> chunkSizeHint, waitForContinueTimeout, maxLineLength, maxHeaderCount,
> maxEmptyLineCount);
> +            return new H1Config(
> +                    bufferSize > 0 ? bufferSize : 8192,
> +                    chunkSizeHint,
> +                    waitForContinueTimeout != null ?
> waitForContinueTimeout : Timeout.ofSeconds(3),
> +                    maxLineLength,
> +                    maxHeaderCount,
> +                    maxEmptyLineCount);
>           }
> 
>       }
> 
> http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/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 56766af..c5e20b6 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
> @@ -163,7 +163,7 @@ class ClientHttp1StreamHandler implements
> ResourceHolder {
>                   if (expectContinue) {
>                       requestState = MessageState.ACK;
>                       timeout = outputChannel.getSocketTimeoutMillis();
> -
> outputChannel.setSocketTimeoutMillis(h1Config.getWaitForContinueTimeoutMillis());
> +
> outputChannel.setSocketTimeoutMillis(h1Config.getWaitForContinueTimeout().toMillisIntBound());
>                   } else {
>                       requestState = MessageState.BODY;
>                       exchangeHandler.produce(internalDataChannel);
> 
> http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/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 b89b8e4..0b67b88 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
> @@ -45,7 +45,7 @@ public final class IOReactorConfig {
> 
>       public static final IOReactorConfig DEFAULT = new Builder().build();
> 
> -    private final long selectIntervalMillis;
> +    private final TimeValue selectInterval;
>       private final int ioThreadCount;
>       private final Timeout  soTimeout;
>       private final boolean soReuseAddress;
> @@ -57,7 +57,7 @@ public final class IOReactorConfig {
>       private final int backlogSize;
> 
>       IOReactorConfig(
> -            final long selectIntervalMillis,
> +            final TimeValue selectInterval,
>               final int ioThreadCount,
>               final Timeout soTimeout,
>               final boolean soReuseAddress,
> @@ -68,8 +68,8 @@ public final class IOReactorConfig {
>               final int rcvBufSize,
>               final int backlogSize) {
>           super();
> -        this.selectIntervalMillis = selectIntervalMillis;
> -        this.ioThreadCount = Args.positive(ioThreadCount, "ioThreadCount");
> +        this.selectInterval = selectInterval;
> +        this.ioThreadCount = ioThreadCount;
>           this.soTimeout = soTimeout;
>           this.soReuseAddress = soReuseAddress;
>           this.soLinger = soLinger;
> @@ -81,14 +81,14 @@ public final class IOReactorConfig {
>       }
> 
>       /**
> -     * Determines time interval in milliseconds at which the I/O reactor
> wakes up to check for
> -     * timed out sessions and session requests.
> +     * Determines time interval at which the I/O reactor wakes up to check
> for timed out sessions
> +     * and session requests.
>        * <p>
>        * Default: {@code 1000} milliseconds.
>        * </p>
>        */
> -    public long getSelectIntervalMillis() {
> -        return this.selectIntervalMillis;
> +    public TimeValue getSelectInterval() {
> +        return this.selectInterval;
>       }
> 
>       /**
> @@ -210,7 +210,7 @@ public final class IOReactorConfig {
>       public static Builder copy(final IOReactorConfig config) {
>           Args.notNull(config, "I/O reactor config");
>           return new Builder()
> -            .setSelectIntervalMillis(config.getSelectIntervalMillis())
> +            .setSelectInterval(config.getSelectInterval())
>               .setIoThreadCount(config.getIoThreadCount())
>               .setSoTimeout(config.getSoTimeout())
>               .setSoReuseAddress(config.isSoReuseAddress())
> @@ -251,7 +251,7 @@ public final class IOReactorConfig {
>               DefaultMaxIoThreadCount = defaultMaxIoThreadCount;
>           }
> 
> -        private long selectIntervalMillis;
> +        private TimeValue selectInterval;
>           private int ioThreadCount;
>           private Timeout  soTimeout;
>           private boolean soReuseAddress;
> @@ -263,7 +263,7 @@ public final class IOReactorConfig {
>           private int backlogSize;
> 
>           Builder() {
> -            this.selectIntervalMillis = 1000;
> +            this.selectInterval = TimeValue.ofMicroseconds(1000);
>               this.ioThreadCount = Builder.getDefaultMaxIoThreadCount();
>               this.soTimeout = Timeout.ZERO_MILLISECONDS;
>               this.soReuseAddress = false;
> @@ -275,8 +275,8 @@ public final class IOReactorConfig {
>               this.backlogSize = 0;
>           }
> 
> -        public Builder setSelectIntervalMillis(final long
> selectIntervalMillis) {
> -            this.selectIntervalMillis = selectIntervalMillis;
> +        public Builder setSelectInterval(final TimeValue selectInterval) {
> +            this.selectInterval = selectInterval;
>               return this;
>           }
> 
> @@ -337,7 +337,8 @@ public final class IOReactorConfig {
> 
>           public IOReactorConfig build() {
>               return new IOReactorConfig(
> -                    selectIntervalMillis, ioThreadCount,
> +                    selectInterval != null ? selectInterval :
> TimeValue.ofMicroseconds(1000),
> +                    ioThreadCount,
>                       Timeout.defaultsToDisabled(soTimeout),
>                       soReuseAddress,
>                       TimeValue.defaultsToNegativeOneMillisecond(soLinger),
> @@ -351,7 +352,7 @@ public final class IOReactorConfig {
>       @Override
>       public String toString() {
>           final StringBuilder builder = new StringBuilder();
> -
> builder.append("[selectIntervalMillis=").append(this.selectIntervalMillis)
> +
> builder.append("[selectIntervalMillis=").append(this.selectInterval)
>                   .append(", ioThreadCount=").append(this.ioThreadCount)
>                   .append(", soTimeout=").append(this.soTimeout)
>                   .append(", soReuseAddress=").append(this.soReuseAddress)
> 
> http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
> ----------------------------------------------------------------------
> diff --git
> a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
> b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
> index a031de7..ab6c155 100644
> ---
> a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
> +++
> b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
> @@ -46,9 +46,9 @@ import org.apache.hc.core5.concurrent.FutureCallback;
>   import org.apache.hc.core5.function.Callback;
>   import org.apache.hc.core5.function.Decorator;
>   import org.apache.hc.core5.io.CloseMode;
> +import org.apache.hc.core5.io.Closer;
>   import org.apache.hc.core5.net.NamedEndpoint;
>   import org.apache.hc.core5.util.Args;
> -import org.apache.hc.core5.io.Closer;
>   import org.apache.hc.core5.util.TimeValue;
> 
>   class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements
> ConnectionInitiator {
> @@ -64,7 +64,7 @@ class SingleCoreIOReactor extends
> AbstractSingleCoreIOReactor implements Connect
>       private final Queue<SocketChannel> channelQueue;
>       private final Queue<IOSessionRequest> requestQueue;
>       private final AtomicBoolean shutdownInitiated;
> -
> +    private final long selectTimeoutMillis;
>       private volatile long lastTimeoutCheckMillis;
> 
>       SingleCoreIOReactor(
> @@ -84,6 +84,7 @@ class SingleCoreIOReactor extends
> AbstractSingleCoreIOReactor implements Connect
>           this.closedSessions = new ConcurrentLinkedQueue<>();
>           this.channelQueue = new ConcurrentLinkedQueue<>();
>           this.requestQueue = new ConcurrentLinkedQueue<>();
> +        this.selectTimeoutMillis =
> this.reactorConfig.getSelectInterval().toMillis();
>       }
> 
>       void enqueueChannel(final SocketChannel socketChannel) throws
> IOReactorShutdownException {
> @@ -104,10 +105,9 @@ class SingleCoreIOReactor extends
> AbstractSingleCoreIOReactor implements Connect
> 
>       @Override
>       void doExecute() throws IOException {
> -        final long selectTimeoutMillis =
> this.reactorConfig.getSelectIntervalMillis();
>           while (!Thread.currentThread().isInterrupted()) {
> 
> -            final int readyCount =
> this.selector.select(selectTimeoutMillis);
> +            final int readyCount =
> this.selector.select(this.selectTimeoutMillis);
> 
>               if (getStatus().compareTo(IOReactorStatus.SHUTTING_DOWN) >= 0)
> {
>                   if (this.shutdownInitiated.compareAndSet(false, true)) {
> @@ -159,7 +159,7 @@ class SingleCoreIOReactor extends
> AbstractSingleCoreIOReactor implements Connect
> 
>       private void validateActiveChannels() {
>           final long currentTimeMillis = System.currentTimeMillis();
> -        if ((currentTimeMillis - this.lastTimeoutCheckMillis) >=
> this.reactorConfig.getSelectIntervalMillis()) {
> +        if ((currentTimeMillis - this.lastTimeoutCheckMillis) >=
> this.selectTimeoutMillis) {
>               this.lastTimeoutCheckMillis = currentTimeMillis;
>               for (final SelectionKey key : this.selector.keys()) {
>                   checkTimeout(key, currentTimeMillis);
> 
> http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
> ----------------------------------------------------------------------
> diff --git
> a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
> b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
> index 6496712..91b1b22 100644
> ---
> a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
> +++
> b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
> @@ -55,8 +55,8 @@ class SingleCoreListeningIOReactor extends
> AbstractSingleCoreIOReactor implement
>       private final Callback<SocketChannel> callback;
>       private final Queue<ListenerEndpointRequest> requestQueue;
>       private final ConcurrentMap<ListenerEndpoint, Boolean> endpoints;
> -
>       private final AtomicBoolean paused;
> +    private final long selectTimeoutMillis;
> 
>       SingleCoreListeningIOReactor(
>               final Queue<ExceptionEvent> auditLog,
> @@ -68,6 +68,7 @@ class SingleCoreListeningIOReactor extends
> AbstractSingleCoreIOReactor implement
>           this.requestQueue = new ConcurrentLinkedQueue<>();
>           this.endpoints = new ConcurrentHashMap<>();
>           this.paused = new AtomicBoolean(false);
> +        this.selectTimeoutMillis =
> this.reactorConfig.getSelectInterval().toMillis();
>       }
> 
>       @Override
> @@ -80,13 +81,12 @@ class SingleCoreListeningIOReactor extends
> AbstractSingleCoreIOReactor implement
> 
>       @Override
>       protected final void doExecute() throws IOException {
> -        final long selectTimeoutMillis =
> this.reactorConfig.getSelectIntervalMillis();
>           while (!Thread.currentThread().isInterrupted()) {
>               if (getStatus().compareTo(IOReactorStatus.ACTIVE) != 0) {
>                   break;
>               }
> 
> -            final int readyCount =
> this.selector.select(selectTimeoutMillis);
> +            final int readyCount =
> this.selector.select(this.selectTimeoutMillis);
> 
>               if (getStatus().compareTo(IOReactorStatus.ACTIVE) != 0) {
>                   break;
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Fwd: httpcomponents-core git commit: Use TimeValue / Timeout to represent time values in config classes

Posted by Gary Gregory <ga...@gmail.com>.
Nice! :-)

Gary

---------- Forwarded message ---------
From: <ol...@apache.org>
Date: Fri, Oct 5, 2018 at 2:24 AM
Subject: httpcomponents-core git commit: Use TimeValue / Timeout to
represent time values in config classes
To: <co...@hc.apache.org>


Repository: httpcomponents-core
Updated Branches:
  refs/heads/master 7834aa523 -> 69a0ff7b2


Use TimeValue / Timeout to represent time values in config classes


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

Branch: refs/heads/master
Commit: 69a0ff7b2c51c89d0d9d6c2046cce98777d095f4
Parents: 7834aa5
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Fri Oct 5 10:11:35 2018 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Fri Oct 5 10:18:01 2018 +0200

----------------------------------------------------------------------
 .../core5/testing/nio/Http1IntegrationTest.java |  3 +-
 .../apache/hc/core5/http/config/H1Config.java   | 29 +++++++++++-------
 .../http/impl/nio/ClientHttp1StreamHandler.java |  2 +-
 .../hc/core5/reactor/IOReactorConfig.java       | 31 ++++++++++----------
 .../hc/core5/reactor/SingleCoreIOReactor.java   | 10 +++----
 .../reactor/SingleCoreListeningIOReactor.java   |  6 ++--
 6 files changed, 45 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
----------------------------------------------------------------------
diff --git
a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
index 2e885d6..4b41dfe 100644
---
a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
+++
b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
@@ -128,6 +128,7 @@ import org.apache.hc.core5.testing.SSLTestContexts;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TextUtils;
 import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -872,7 +873,7 @@ public class Http1IntegrationTest extends
InternalHttp1ServerTestBase {
         });
         final InetSocketAddress serverEndpoint = server.start();

-
client.start(H1Config.custom().setWaitForContinueTimeoutMillis(100).build());
+
client.start(H1Config.custom().setWaitForContinueTimeout(Timeout.ofMillis(100)).build());
         final Future<ClientSessionEndpoint> connectFuture = client.connect(
                 "localhost", serverEndpoint.getPort(), TIMEOUT);
         final ClientSessionEndpoint streamEndpoint = connectFuture.get();

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
----------------------------------------------------------------------
diff --git
a/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
index 47bfb0f..ca44a01 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/config/H1Config.java
@@ -28,6 +28,7 @@
 package org.apache.hc.core5.http.config;

 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.Timeout;

 /**
  * HTTP/1.1 protocol parameters.
@@ -45,17 +46,17 @@ public class H1Config {

     private final int bufferSize;
     private final int chunkSizeHint;
-    private final int waitForContinueTimeoutMillis;
+    private final Timeout waitForContinueTimeout;
     private final int maxLineLength;
     private final int maxHeaderCount;
     private final int maxEmptyLineCount;

-    H1Config(final int bufferSize, final int chunkSizeHint, final int
waitForContinueTimeout,
+    H1Config(final int bufferSize, final int chunkSizeHint, final Timeout
waitForContinueTimeout,
              final int maxLineLength, final int maxHeaderCount, final int
maxEmptyLineCount) {
         super();
         this.bufferSize = bufferSize;
         this.chunkSizeHint = chunkSizeHint;
-        this.waitForContinueTimeoutMillis = waitForContinueTimeout;
+        this.waitForContinueTimeout = waitForContinueTimeout;
         this.maxLineLength = maxLineLength;
         this.maxHeaderCount = maxHeaderCount;
         this.maxEmptyLineCount = maxEmptyLineCount;
@@ -69,8 +70,8 @@ public class H1Config {
         return chunkSizeHint;
     }

-    public int getWaitForContinueTimeoutMillis() {
-        return waitForContinueTimeoutMillis;
+    public Timeout getWaitForContinueTimeout() {
+        return waitForContinueTimeout;
     }

     public int getMaxLineLength() {
@@ -90,7 +91,7 @@ public class H1Config {
         final StringBuilder builder = new StringBuilder();
         builder.append("[bufferSize=").append(bufferSize)
                 .append(", chunkSizeHint=").append(chunkSizeHint)
-                .append(",
waitForContinueTimeout=").append(waitForContinueTimeoutMillis)
+                .append(",
waitForContinueTimeout=").append(waitForContinueTimeout)
                 .append(", maxLineLength=").append(maxLineLength)
                 .append(", maxHeaderCount=").append(maxHeaderCount)
                 .append(", maxEmptyLineCount=").append(maxEmptyLineCount)
@@ -107,7 +108,7 @@ public class H1Config {
         return new Builder()
                 .setBufferSize(config.getBufferSize())
                 .setChunkSizeHint(config.getChunkSizeHint())
-
.setWaitForContinueTimeoutMillis(config.getWaitForContinueTimeoutMillis())
+
.setWaitForContinueTimeout(config.getWaitForContinueTimeout())
                 .setMaxHeaderCount(config.getMaxHeaderCount())
                 .setMaxLineLength(config.getMaxLineLength())
                 .setMaxEmptyLineCount(config.maxEmptyLineCount);
@@ -117,7 +118,7 @@ public class H1Config {

         private int bufferSize;
         private int chunkSizeHint;
-        private int waitForContinueTimeout;
+        private Timeout waitForContinueTimeout;
         private int maxLineLength;
         private int maxHeaderCount;
         private int maxEmptyLineCount;
@@ -125,7 +126,7 @@ public class H1Config {
         Builder() {
             this.bufferSize = -1;
             this.chunkSizeHint = -1;
-            this.waitForContinueTimeout = 3000;
+            this.waitForContinueTimeout = Timeout.ofSeconds(3);
             this.maxLineLength = -1;
             this.maxHeaderCount = -1;
             this.maxEmptyLineCount = 10;
@@ -141,7 +142,7 @@ public class H1Config {
             return this;
         }

-        public Builder setWaitForContinueTimeoutMillis(final int
waitForContinueTimeout) {
+        public Builder setWaitForContinueTimeout(final Timeout
waitForContinueTimeout) {
             this.waitForContinueTimeout = waitForContinueTimeout;
             return this;
         }
@@ -162,7 +163,13 @@ public class H1Config {
         }

         public H1Config build() {
-            return new H1Config(bufferSize > 0 ? bufferSize : 8192,
chunkSizeHint, waitForContinueTimeout, maxLineLength, maxHeaderCount,
maxEmptyLineCount);
+            return new H1Config(
+                    bufferSize > 0 ? bufferSize : 8192,
+                    chunkSizeHint,
+                    waitForContinueTimeout != null ?
waitForContinueTimeout : Timeout.ofSeconds(3),
+                    maxLineLength,
+                    maxHeaderCount,
+                    maxEmptyLineCount);
         }

     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/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 56766af..c5e20b6 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
@@ -163,7 +163,7 @@ class ClientHttp1StreamHandler implements
ResourceHolder {
                 if (expectContinue) {
                     requestState = MessageState.ACK;
                     timeout = outputChannel.getSocketTimeoutMillis();
-
outputChannel.setSocketTimeoutMillis(h1Config.getWaitForContinueTimeoutMillis());
+
outputChannel.setSocketTimeoutMillis(h1Config.getWaitForContinueTimeout().toMillisIntBound());
                 } else {
                     requestState = MessageState.BODY;
                     exchangeHandler.produce(internalDataChannel);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/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 b89b8e4..0b67b88 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
@@ -45,7 +45,7 @@ public final class IOReactorConfig {

     public static final IOReactorConfig DEFAULT = new Builder().build();

-    private final long selectIntervalMillis;
+    private final TimeValue selectInterval;
     private final int ioThreadCount;
     private final Timeout  soTimeout;
     private final boolean soReuseAddress;
@@ -57,7 +57,7 @@ public final class IOReactorConfig {
     private final int backlogSize;

     IOReactorConfig(
-            final long selectIntervalMillis,
+            final TimeValue selectInterval,
             final int ioThreadCount,
             final Timeout soTimeout,
             final boolean soReuseAddress,
@@ -68,8 +68,8 @@ public final class IOReactorConfig {
             final int rcvBufSize,
             final int backlogSize) {
         super();
-        this.selectIntervalMillis = selectIntervalMillis;
-        this.ioThreadCount = Args.positive(ioThreadCount, "ioThreadCount");
+        this.selectInterval = selectInterval;
+        this.ioThreadCount = ioThreadCount;
         this.soTimeout = soTimeout;
         this.soReuseAddress = soReuseAddress;
         this.soLinger = soLinger;
@@ -81,14 +81,14 @@ public final class IOReactorConfig {
     }

     /**
-     * Determines time interval in milliseconds at which the I/O reactor
wakes up to check for
-     * timed out sessions and session requests.
+     * Determines time interval at which the I/O reactor wakes up to check
for timed out sessions
+     * and session requests.
      * <p>
      * Default: {@code 1000} milliseconds.
      * </p>
      */
-    public long getSelectIntervalMillis() {
-        return this.selectIntervalMillis;
+    public TimeValue getSelectInterval() {
+        return this.selectInterval;
     }

     /**
@@ -210,7 +210,7 @@ public final class IOReactorConfig {
     public static Builder copy(final IOReactorConfig config) {
         Args.notNull(config, "I/O reactor config");
         return new Builder()
-            .setSelectIntervalMillis(config.getSelectIntervalMillis())
+            .setSelectInterval(config.getSelectInterval())
             .setIoThreadCount(config.getIoThreadCount())
             .setSoTimeout(config.getSoTimeout())
             .setSoReuseAddress(config.isSoReuseAddress())
@@ -251,7 +251,7 @@ public final class IOReactorConfig {
             DefaultMaxIoThreadCount = defaultMaxIoThreadCount;
         }

-        private long selectIntervalMillis;
+        private TimeValue selectInterval;
         private int ioThreadCount;
         private Timeout  soTimeout;
         private boolean soReuseAddress;
@@ -263,7 +263,7 @@ public final class IOReactorConfig {
         private int backlogSize;

         Builder() {
-            this.selectIntervalMillis = 1000;
+            this.selectInterval = TimeValue.ofMicroseconds(1000);
             this.ioThreadCount = Builder.getDefaultMaxIoThreadCount();
             this.soTimeout = Timeout.ZERO_MILLISECONDS;
             this.soReuseAddress = false;
@@ -275,8 +275,8 @@ public final class IOReactorConfig {
             this.backlogSize = 0;
         }

-        public Builder setSelectIntervalMillis(final long
selectIntervalMillis) {
-            this.selectIntervalMillis = selectIntervalMillis;
+        public Builder setSelectInterval(final TimeValue selectInterval) {
+            this.selectInterval = selectInterval;
             return this;
         }

@@ -337,7 +337,8 @@ public final class IOReactorConfig {

         public IOReactorConfig build() {
             return new IOReactorConfig(
-                    selectIntervalMillis, ioThreadCount,
+                    selectInterval != null ? selectInterval :
TimeValue.ofMicroseconds(1000),
+                    ioThreadCount,
                     Timeout.defaultsToDisabled(soTimeout),
                     soReuseAddress,
                     TimeValue.defaultsToNegativeOneMillisecond(soLinger),
@@ -351,7 +352,7 @@ public final class IOReactorConfig {
     @Override
     public String toString() {
         final StringBuilder builder = new StringBuilder();
-
builder.append("[selectIntervalMillis=").append(this.selectIntervalMillis)
+
builder.append("[selectIntervalMillis=").append(this.selectInterval)
                 .append(", ioThreadCount=").append(this.ioThreadCount)
                 .append(", soTimeout=").append(this.soTimeout)
                 .append(", soReuseAddress=").append(this.soReuseAddress)

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
----------------------------------------------------------------------
diff --git
a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
index a031de7..ab6c155 100644
---
a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
+++
b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java
@@ -46,9 +46,9 @@ import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.io.CloseMode;
+import org.apache.hc.core5.io.Closer;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.io.Closer;
 import org.apache.hc.core5.util.TimeValue;

 class SingleCoreIOReactor extends AbstractSingleCoreIOReactor implements
ConnectionInitiator {
@@ -64,7 +64,7 @@ class SingleCoreIOReactor extends
AbstractSingleCoreIOReactor implements Connect
     private final Queue<SocketChannel> channelQueue;
     private final Queue<IOSessionRequest> requestQueue;
     private final AtomicBoolean shutdownInitiated;
-
+    private final long selectTimeoutMillis;
     private volatile long lastTimeoutCheckMillis;

     SingleCoreIOReactor(
@@ -84,6 +84,7 @@ class SingleCoreIOReactor extends
AbstractSingleCoreIOReactor implements Connect
         this.closedSessions = new ConcurrentLinkedQueue<>();
         this.channelQueue = new ConcurrentLinkedQueue<>();
         this.requestQueue = new ConcurrentLinkedQueue<>();
+        this.selectTimeoutMillis =
this.reactorConfig.getSelectInterval().toMillis();
     }

     void enqueueChannel(final SocketChannel socketChannel) throws
IOReactorShutdownException {
@@ -104,10 +105,9 @@ class SingleCoreIOReactor extends
AbstractSingleCoreIOReactor implements Connect

     @Override
     void doExecute() throws IOException {
-        final long selectTimeoutMillis =
this.reactorConfig.getSelectIntervalMillis();
         while (!Thread.currentThread().isInterrupted()) {

-            final int readyCount =
this.selector.select(selectTimeoutMillis);
+            final int readyCount =
this.selector.select(this.selectTimeoutMillis);

             if (getStatus().compareTo(IOReactorStatus.SHUTTING_DOWN) >= 0)
{
                 if (this.shutdownInitiated.compareAndSet(false, true)) {
@@ -159,7 +159,7 @@ class SingleCoreIOReactor extends
AbstractSingleCoreIOReactor implements Connect

     private void validateActiveChannels() {
         final long currentTimeMillis = System.currentTimeMillis();
-        if ((currentTimeMillis - this.lastTimeoutCheckMillis) >=
this.reactorConfig.getSelectIntervalMillis()) {
+        if ((currentTimeMillis - this.lastTimeoutCheckMillis) >=
this.selectTimeoutMillis) {
             this.lastTimeoutCheckMillis = currentTimeMillis;
             for (final SelectionKey key : this.selector.keys()) {
                 checkTimeout(key, currentTimeMillis);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/69a0ff7b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
----------------------------------------------------------------------
diff --git
a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
index 6496712..91b1b22 100644
---
a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
+++
b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreListeningIOReactor.java
@@ -55,8 +55,8 @@ class SingleCoreListeningIOReactor extends
AbstractSingleCoreIOReactor implement
     private final Callback<SocketChannel> callback;
     private final Queue<ListenerEndpointRequest> requestQueue;
     private final ConcurrentMap<ListenerEndpoint, Boolean> endpoints;
-
     private final AtomicBoolean paused;
+    private final long selectTimeoutMillis;

     SingleCoreListeningIOReactor(
             final Queue<ExceptionEvent> auditLog,
@@ -68,6 +68,7 @@ class SingleCoreListeningIOReactor extends
AbstractSingleCoreIOReactor implement
         this.requestQueue = new ConcurrentLinkedQueue<>();
         this.endpoints = new ConcurrentHashMap<>();
         this.paused = new AtomicBoolean(false);
+        this.selectTimeoutMillis =
this.reactorConfig.getSelectInterval().toMillis();
     }

     @Override
@@ -80,13 +81,12 @@ class SingleCoreListeningIOReactor extends
AbstractSingleCoreIOReactor implement

     @Override
     protected final void doExecute() throws IOException {
-        final long selectTimeoutMillis =
this.reactorConfig.getSelectIntervalMillis();
         while (!Thread.currentThread().isInterrupted()) {
             if (getStatus().compareTo(IOReactorStatus.ACTIVE) != 0) {
                 break;
             }

-            final int readyCount =
this.selector.select(selectTimeoutMillis);
+            final int readyCount =
this.selector.select(this.selectTimeoutMillis);

             if (getStatus().compareTo(IOReactorStatus.ACTIVE) != 0) {
                 break;