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: <[email protected]> > > 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: <[email protected]> > > > > > > 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 <[email protected]> > > Authored: Fri Oct 5 10:11:35 2018 +0200 > > Committer: Oleg Kalnichevski <[email protected]> > > 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: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
