399535 - Websocket-client connect should have configurable connect timeout

+ Made default value for connectTimeout be exposed from SelectorManager.
 + Added javadoc on time unit.
This commit is contained in:
Joakim Erdfelt 2013-02-12 12:56:46 -07:00
parent 5c68d23138
commit ebaffcfd27
2 changed files with 28 additions and 8 deletions

View File

@ -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;
}
/**

View File

@ -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)