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:
parent
5c68d23138
commit
ebaffcfd27
|
@ -57,11 +57,15 @@ import org.eclipse.jetty.util.thread.Scheduler;
|
||||||
public abstract class SelectorManager extends AbstractLifeCycle implements Dumpable
|
public abstract class SelectorManager extends AbstractLifeCycle implements Dumpable
|
||||||
{
|
{
|
||||||
protected static final Logger LOG = Log.getLogger(SelectorManager.class);
|
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 Executor executor;
|
||||||
private final Scheduler scheduler;
|
private final Scheduler scheduler;
|
||||||
private final ManagedSelector[] _selectors;
|
private final ManagedSelector[] _selectors;
|
||||||
private long _connectTimeout = 15000;
|
private long _connectTimeout = DEFAULT_CONNECT_TIMEOUT;
|
||||||
private long _selectorIndex;
|
private long _selectorIndex;
|
||||||
|
|
||||||
protected SelectorManager(Executor executor, Scheduler scheduler)
|
protected SelectorManager(Executor executor, Scheduler scheduler)
|
||||||
|
@ -86,14 +90,24 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
return scheduler;
|
return scheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the connect timeout
|
||||||
|
*
|
||||||
|
* @return the connect timeout (in milliseconds)
|
||||||
|
*/
|
||||||
public long getConnectTimeout()
|
public long getConnectTimeout()
|
||||||
{
|
{
|
||||||
return _connectTimeout;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.concurrent.Future;
|
||||||
|
|
||||||
import org.eclipse.jetty.io.ByteBufferPool;
|
import org.eclipse.jetty.io.ByteBufferPool;
|
||||||
import org.eclipse.jetty.io.MappedByteBufferPool;
|
import org.eclipse.jetty.io.MappedByteBufferPool;
|
||||||
|
import org.eclipse.jetty.io.SelectorManager;
|
||||||
import org.eclipse.jetty.util.HttpCookieStore;
|
import org.eclipse.jetty.util.HttpCookieStore;
|
||||||
import org.eclipse.jetty.util.StringUtil;
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||||
|
@ -58,7 +59,6 @@ import org.eclipse.jetty.websocket.common.extensions.WebSocketExtensionFactory;
|
||||||
public class WebSocketClient extends ContainerLifeCycle
|
public class WebSocketClient extends ContainerLifeCycle
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(WebSocketClient.class);
|
private static final Logger LOG = Log.getLogger(WebSocketClient.class);
|
||||||
private static final int DEFAULT_TIMEOUT = 1500;
|
|
||||||
|
|
||||||
private final WebSocketPolicy policy;
|
private final WebSocketPolicy policy;
|
||||||
private final SslContextFactory sslContextFactory;
|
private final SslContextFactory sslContextFactory;
|
||||||
|
@ -71,7 +71,7 @@ public class WebSocketClient extends ContainerLifeCycle
|
||||||
private ConnectionManager connectionManager;
|
private ConnectionManager connectionManager;
|
||||||
private Masker masker;
|
private Masker masker;
|
||||||
private SocketAddress bindAddress;
|
private SocketAddress bindAddress;
|
||||||
private long connectTimeout = DEFAULT_TIMEOUT;
|
private long connectTimeout = SelectorManager.DEFAULT_CONNECT_TIMEOUT;
|
||||||
|
|
||||||
public WebSocketClient()
|
public WebSocketClient()
|
||||||
{
|
{
|
||||||
|
@ -300,13 +300,19 @@ public class WebSocketClient extends ContainerLifeCycle
|
||||||
this.bufferPool = bufferPool;
|
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");
|
throw new IllegalStateException("Connect Timeout cannot be negative");
|
||||||
}
|
}
|
||||||
this.connectTimeout = connectTimeout;
|
this.connectTimeout = timeoutMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCookieStore(CookieStore cookieStore)
|
public void setCookieStore(CookieStore cookieStore)
|
||||||
|
|
Loading…
Reference in New Issue