From ebaffcfd27d98ae6c71976910a891b1b23162b4f Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 12 Feb 2013 12:56:46 -0700 Subject: [PATCH] 399535 - Websocket-client connect should have configurable connect timeout + Made default value for connectTimeout be exposed from SelectorManager. + Added javadoc on time unit. --- .../org/eclipse/jetty/io/SelectorManager.java | 20 ++++++++++++++++--- .../websocket/client/WebSocketClient.java | 16 ++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java index 7163989b0cd..bffa13ba415 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java @@ -57,11 +57,15 @@ import org.eclipse.jetty.util.thread.Scheduler; public abstract class SelectorManager extends AbstractLifeCycle implements Dumpable { protected static final Logger LOG = Log.getLogger(SelectorManager.class); + /** + * The default connect timeout, in milliseconds + */ + public static final int DEFAULT_CONNECT_TIMEOUT = 15000; private final Executor executor; private final Scheduler scheduler; private final ManagedSelector[] _selectors; - private long _connectTimeout = 15000; + private long _connectTimeout = DEFAULT_CONNECT_TIMEOUT; private long _selectorIndex; protected SelectorManager(Executor executor, Scheduler scheduler) @@ -86,14 +90,24 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa return scheduler; } + /** + * Get the connect timeout + * + * @return the connect timeout (in milliseconds) + */ public long getConnectTimeout() { return _connectTimeout; } - public void setConnectTimeout(long connectTimeout) + /** + * Set the connect timeout (in milliseconds) + * + * @param milliseconds the number of milliseconds for the timeout + */ + public void setConnectTimeout(long milliseconds) { - _connectTimeout = connectTimeout; + _connectTimeout = milliseconds; } /** diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index e06e707f25f..603c89cf116 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -30,6 +30,7 @@ import java.util.concurrent.Future; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; +import org.eclipse.jetty.io.SelectorManager; import org.eclipse.jetty.util.HttpCookieStore; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.component.ContainerLifeCycle; @@ -58,7 +59,6 @@ import org.eclipse.jetty.websocket.common.extensions.WebSocketExtensionFactory; public class WebSocketClient extends ContainerLifeCycle { private static final Logger LOG = Log.getLogger(WebSocketClient.class); - private static final int DEFAULT_TIMEOUT = 1500; private final WebSocketPolicy policy; private final SslContextFactory sslContextFactory; @@ -71,7 +71,7 @@ public class WebSocketClient extends ContainerLifeCycle private ConnectionManager connectionManager; private Masker masker; private SocketAddress bindAddress; - private long connectTimeout = DEFAULT_TIMEOUT; + private long connectTimeout = SelectorManager.DEFAULT_CONNECT_TIMEOUT; public WebSocketClient() { @@ -300,13 +300,19 @@ public class WebSocketClient extends ContainerLifeCycle this.bufferPool = bufferPool; } - public void setConnectTimeout(long connectTimeout) + /** + * Set the timeout for connecting to the remote server. + * + * @param timeoutMilliseconds + * the timeout in milliseconds + */ + public void setConnectTimeout(long timeoutMilliseconds) { - if (connectTimeout < 0) + if (timeoutMilliseconds < 0) { throw new IllegalStateException("Connect Timeout cannot be negative"); } - this.connectTimeout = connectTimeout; + this.connectTimeout = timeoutMilliseconds; } public void setCookieStore(CookieStore cookieStore)