Merge pull request #5151 from olegmoz/5150-zero-connection-timeout
Issue #5150 - Infinite connection timeout support in ManagedSelector
This commit is contained in:
commit
a6e1f9df8f
|
@ -690,7 +690,7 @@ public class HttpClient extends ContainerLifeCycle
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the max time, in milliseconds, a connection can take to connect to destinations
|
* @return the max time, in milliseconds, a connection can take to connect to destinations. Zero value means infinite timeout.
|
||||||
*/
|
*/
|
||||||
@ManagedAttribute("The timeout, in milliseconds, for connect() operations")
|
@ManagedAttribute("The timeout, in milliseconds, for connect() operations")
|
||||||
public long getConnectTimeout()
|
public long getConnectTimeout()
|
||||||
|
@ -699,7 +699,7 @@ public class HttpClient extends ContainerLifeCycle
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param connectTimeout the max time, in milliseconds, a connection can take to connect to destinations
|
* @param connectTimeout the max time, in milliseconds, a connection can take to connect to destinations. Zero value means infinite timeout.
|
||||||
* @see java.net.Socket#connect(SocketAddress, int)
|
* @see java.net.Socket#connect(SocketAddress, int)
|
||||||
*/
|
*/
|
||||||
public void setConnectTimeout(long connectTimeout)
|
public void setConnectTimeout(long connectTimeout)
|
||||||
|
|
|
@ -888,7 +888,11 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
||||||
{
|
{
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.attachment = attachment;
|
this.attachment = attachment;
|
||||||
this.timeout = ManagedSelector.this._selectorManager.getScheduler().schedule(this, ManagedSelector.this._selectorManager.getConnectTimeout(), TimeUnit.MILLISECONDS);
|
long timeout = ManagedSelector.this._selectorManager.getConnectTimeout();
|
||||||
|
if (timeout > 0)
|
||||||
|
this.timeout = ManagedSelector.this._selectorManager.getScheduler().schedule(this, timeout, TimeUnit.MILLISECONDS);
|
||||||
|
else
|
||||||
|
this.timeout = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -919,6 +923,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
|
||||||
{
|
{
|
||||||
if (failed.compareAndSet(false, true))
|
if (failed.compareAndSet(false, true))
|
||||||
{
|
{
|
||||||
|
if (timeout != null)
|
||||||
timeout.cancel();
|
timeout.cancel();
|
||||||
IO.close(channel);
|
IO.close(channel);
|
||||||
ManagedSelector.this._selectorManager.connectionFailed(channel, failure, attachment);
|
ManagedSelector.this._selectorManager.connectionFailed(channel, failure, attachment);
|
||||||
|
|
Loading…
Reference in New Issue