hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1789760 - in /httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5: http/config/ reactor/ util/
Date Fri, 31 Mar 2017 22:57:44 GMT
Author: ggregory
Date: Fri Mar 31 22:57:44 2017
New Revision: 1789760

URL: http://svn.apache.org/viewvc?rev=1789760&view=rev
Log:
HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit. Convert IOReactorConfig.
Document thread safety (immutable) on TimeValue with an annotation.

Modified:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/config/SocketConfig.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/config/SocketConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/config/SocketConfig.java?rev=1789760&r1=1789759&r2=1789760&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/config/SocketConfig.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/config/SocketConfig.java
Fri Mar 31 22:57:44 2017
@@ -249,7 +249,7 @@ public class SocketConfig {
         private int backlogSize;
 
         Builder() {
-            this.soLinger = new TimeValue(-1, TimeUnit.SECONDS);
+            this.soLinger = TimeValue.NEG_ONE_SECONDS;
             this.tcpNoDelay = true;
         }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java?rev=1789760&r1=1789759&r2=1789760&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
Fri Mar 31 22:57:44 2017
@@ -374,8 +374,9 @@ public abstract class AbstractMultiworke
     protected void prepareSocket(final Socket socket) throws IOException {
         socket.setTcpNoDelay(this.reactorConfig.isTcpNoDelay());
         socket.setKeepAlive(this.reactorConfig.isSoKeepalive());
-        if (this.reactorConfig.getSoTimeout() > 0) {
-            socket.setSoTimeout(this.reactorConfig.getSoTimeout());
+        final int millis = this.reactorConfig.getSoTimeout().toMillisIntBound();
+        if (millis > 0) {
+            socket.setSoTimeout(millis);
         }
         if (this.reactorConfig.getSndBufSize() > 0) {
             socket.setSendBufferSize(this.reactorConfig.getSndBufSize());
@@ -383,7 +384,7 @@ public abstract class AbstractMultiworke
         if (this.reactorConfig.getRcvBufSize() > 0) {
             socket.setReceiveBufferSize(this.reactorConfig.getRcvBufSize());
         }
-        final int linger = this.reactorConfig.getSoLinger();
+        final int linger = this.reactorConfig.getSoLinger().toSecondsIntBound();
         if (linger >= 0) {
             socket.setSoLinger(true, linger);
         }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java?rev=1789760&r1=1789759&r2=1789760&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
Fri Mar 31 22:57:44 2017
@@ -195,7 +195,7 @@ public class DefaultConnectingIOReactor
                 localAddress,
                 attachment,
                 callback);
-        sessionRequest.setConnectTimeout(this.reactorConfig.getConnectTimeout());
+        sessionRequest.setConnectTimeout(this.reactorConfig.getConnectTimeout().toMillisIntBound());
 
         this.requestQueue.add(sessionRequest);
         this.selector.wakeup();

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java?rev=1789760&r1=1789759&r2=1789760&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
Fri Mar 31 22:57:44 2017
@@ -215,8 +215,9 @@ public class DefaultListeningIOReactor e
             try {
                 final ServerSocket socket = serverChannel.socket();
                 socket.setReuseAddress(this.reactorConfig.isSoReuseAddress());
-                if (this.reactorConfig.getSoTimeout() > 0) {
-                    socket.setSoTimeout(this.reactorConfig.getSoTimeout());
+                final int millis = this.reactorConfig.getSoTimeout().toMillisIntBound();
+                if (millis > 0) {
+                    socket.setSoTimeout(millis);
                 }
                 if (this.reactorConfig.getRcvBufSize() > 0) {
                     socket.setReceiveBufferSize(this.reactorConfig.getRcvBufSize());

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java?rev=1789760&r1=1789759&r2=1789760&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorConfig.java
Fri Mar 31 22:57:44 2017
@@ -27,9 +27,12 @@
 
 package org.apache.hc.core5.reactor;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.TimeValue;
 
 /**
  * I/O reactor configuration parameters.
@@ -45,12 +48,12 @@ public final class IOReactorConfig {
 
     private final long selectInterval;
     private final int ioThreadCount;
-    private final int soTimeout;
+    private final TimeValue  soTimeout;
     private final boolean soReuseAddress;
-    private final int soLinger;
+    private final TimeValue soLinger;
     private final boolean soKeepAlive;
     private final boolean tcpNoDelay;
-    private final int connectTimeout;
+    private final TimeValue connectTimeout;
     private final int sndBufSize;
     private final int rcvBufSize;
     private final int backlogSize;
@@ -58,12 +61,12 @@ public final class IOReactorConfig {
     IOReactorConfig(
             final long selectInterval,
             final int ioThreadCount,
-            final int soTimeout,
+            final TimeValue soTimeout,
             final boolean soReuseAddress,
-            final int soLinger,
+            final TimeValue soLinger,
             final boolean soKeepAlive,
             final boolean tcpNoDelay,
-            final int connectTimeout,
+            final TimeValue connectTimeout,
             final int sndBufSize,
             final int rcvBufSize,
             final int backlogSize) {
@@ -107,7 +110,7 @@ public final class IOReactorConfig {
      *
      * @see java.net.SocketOptions#SO_TIMEOUT
      */
-    public int getSoTimeout() {
+    public TimeValue getSoTimeout() {
         return soTimeout;
     }
 
@@ -131,7 +134,7 @@ public final class IOReactorConfig {
      *
      * @see java.net.SocketOptions#SO_LINGER
      */
-    public int getSoLinger() {
+    public TimeValue getSoLinger() {
         return soLinger;
     }
 
@@ -164,7 +167,7 @@ public final class IOReactorConfig {
      * <p>
      * Default: {@code 0} (no timeout)
      */
-    public int getConnectTimeout() {
+    public TimeValue getConnectTimeout() {
         return connectTimeout;
     }
 
@@ -227,12 +230,12 @@ public final class IOReactorConfig {
 
         private long selectInterval;
         private int ioThreadCount;
-        private int soTimeout;
+        private TimeValue  soTimeout;
         private boolean soReuseAddress;
-        private int soLinger;
+        private TimeValue soLinger;
         private boolean soKeepAlive;
         private boolean tcpNoDelay;
-        private int connectTimeout;
+        private TimeValue connectTimeout;
         private int sndBufSize;
         private int rcvBufSize;
         private int backlogSize;
@@ -240,12 +243,12 @@ public final class IOReactorConfig {
         Builder() {
             this.selectInterval = 1000;
             this.ioThreadCount = AVAIL_PROCS;
-            this.soTimeout = 0;
+            this.soTimeout = TimeValue.ZERO_MILLIS;
             this.soReuseAddress = false;
-            this.soLinger = -1;
+            this.soLinger = TimeValue.NEG_ONE_SECONDS;
             this.soKeepAlive = false;
             this.tcpNoDelay = true;
-            this.connectTimeout = 0;
+            this.connectTimeout = TimeValue.ZERO_MILLIS;
             this.sndBufSize = 0;
             this.rcvBufSize = 0;
             this.backlogSize = 0;
@@ -261,7 +264,12 @@ public final class IOReactorConfig {
             return this;
         }
 
-        public Builder setSoTimeout(final int soTimeout) {
+        public Builder setSoTimeout(final int soTimeout, final TimeUnit timeUnit) {
+            this.soTimeout = new TimeValue(soTimeout, timeUnit);;
+            return this;
+        }
+
+        public Builder setSoTimeout(final TimeValue soTimeout) {
             this.soTimeout = soTimeout;
             return this;
         }
@@ -271,7 +279,12 @@ public final class IOReactorConfig {
             return this;
         }
 
-        public Builder setSoLinger(final int soLinger) {
+        public Builder setSoLinger(final int soLinger, final TimeUnit timeUnit) {
+            this.soLinger = new TimeValue(soLinger, timeUnit);;
+            return this;
+        }
+
+        public Builder setSoLinger(final TimeValue soLinger) {
             this.soLinger = soLinger;
             return this;
         }
@@ -286,7 +299,12 @@ public final class IOReactorConfig {
             return this;
         }
 
-        public Builder setConnectTimeout(final int connectTimeout) {
+        public Builder setConnectTimeout(final int connectTimeout, final TimeUnit timeUnit)
{
+            this.connectTimeout = new TimeValue(connectTimeout, timeUnit);
+            return this;
+        }
+
+        public Builder setConnectTimeout(final TimeValue connectTimeout) {
             this.connectTimeout = connectTimeout;
             return this;
         }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java?rev=1789760&r1=1789759&r2=1789760&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
Fri Mar 31 22:57:44 2017
@@ -271,7 +271,7 @@ class IOReactorImpl implements IOReactor
                         closedSessions);
                 session.setHandler(this.eventHandlerFactory.createHandler(session,
                         sessionRequest != null ? sessionRequest.getAttachment() : null));
-                session.setSocketTimeout(this.reactorConfig.getSoTimeout());
+                session.setSocketTimeout(this.reactorConfig.getSoTimeout().toMillisIntBound());
                 key.attach(session);
             } catch (final ClosedChannelException ex) {
                 final SessionRequestImpl sessionRequest = pendingSession.sessionRequest;

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java?rev=1789760&r1=1789759&r2=1789760&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
Fri Mar 31 22:57:44 2017
@@ -29,13 +29,20 @@ package org.apache.hc.core5.util;
 
 import java.util.concurrent.TimeUnit;
 
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+
 /**
  * Wraps a time (long) and TimeUnit.
  *
  * @since 5.0
  */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class TimeValue {
 
+    public static final TimeValue ZERO_MILLIS = new TimeValue(0, TimeUnit.MILLISECONDS);
+    public static final TimeValue NEG_ONE_SECONDS = new TimeValue(-1, TimeUnit.SECONDS);
+
     public static int asBoundInt(final long value) {
         if (value > Integer.MAX_VALUE) {
             return Integer.MAX_VALUE;



Mime
View raw message