337678 use the httpClient timerQ for connect timeouts

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2819 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2011-02-22 22:05:43 +00:00
parent f6349cd762
commit 8acf49568c
2 changed files with 7 additions and 28 deletions

View File

@ -246,6 +246,7 @@ public class HttpClient extends HttpBuffers implements Attributes
_timeoutQ.schedule(task); _timeoutQ.schedule(task);
} }
/* ------------------------------------------------------------ */
public void schedule(Timeout.Task task, long timeout) public void schedule(Timeout.Task task, long timeout)
{ {
_timeoutQ.schedule(task, timeout - _timeoutQ.getDuration()); _timeoutQ.schedule(task, timeout - _timeoutQ.getDuration());
@ -529,6 +530,7 @@ public class HttpClient extends HttpBuffers implements Attributes
public void startConnection(HttpDestination destination) throws IOException; public void startConnection(HttpDestination destination) throws IOException;
} }
/* ------------------------------------------------------------ */
/** /**
* if a keystore location has been provided then client will attempt to use it as the keystore, * if a keystore location has been provided then client will attempt to use it as the keystore,
* otherwise we simply ignore certificates and run with a loose ssl context. * otherwise we simply ignore certificates and run with a loose ssl context.
@ -567,6 +569,7 @@ public class HttpClient extends HttpBuffers implements Attributes
_idleTimeout = ms; _idleTimeout = ms;
} }
/* ------------------------------------------------------------ */
/** /**
* @return the period in ms that an exchange will wait for a response from the server. * @return the period in ms that an exchange will wait for a response from the server.
* @deprecated use {@link #getTimeout()} instead. * @deprecated use {@link #getTimeout()} instead.
@ -577,6 +580,7 @@ public class HttpClient extends HttpBuffers implements Attributes
return Long.valueOf(getTimeout()).intValue(); return Long.valueOf(getTimeout()).intValue();
} }
/* ------------------------------------------------------------ */
/** /**
* @deprecated use {@link #setTimeout(long)} instead. * @deprecated use {@link #setTimeout(long)} instead.
* @param timeout the period in ms that an exchange will wait for a response from the server. * @param timeout the period in ms that an exchange will wait for a response from the server.
@ -605,6 +609,7 @@ public class HttpClient extends HttpBuffers implements Attributes
_timeout = timeout; _timeout = timeout;
} }
/* ------------------------------------------------------------ */
/** /**
* @return the period in ms before timing out an attempt to connect * @return the period in ms before timing out an attempt to connect
*/ */
@ -613,6 +618,7 @@ public class HttpClient extends HttpBuffers implements Attributes
return _connectTimeout; return _connectTimeout;
} }
/* ------------------------------------------------------------ */
/** /**
* @param connectTimeout the period in ms before timing out an attempt to connect * @param connectTimeout the period in ms before timing out an attempt to connect
*/ */

View File

@ -44,7 +44,6 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
{ {
private final HttpClient _httpClient; private final HttpClient _httpClient;
private final Manager _selectorManager=new Manager(); private final Manager _selectorManager=new Manager();
private final Timeout _connectTimer = new Timeout();
private final Map<SocketChannel, Timeout.Task> _connectingChannels = new ConcurrentHashMap<SocketChannel, Timeout.Task>(); private final Map<SocketChannel, Timeout.Task> _connectingChannels = new ConcurrentHashMap<SocketChannel, Timeout.Task>();
private SSLContext _sslContext; private SSLContext _sslContext;
private Buffers _sslBuffers; private Buffers _sslBuffers;
@ -62,31 +61,6 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
protected void doStart() throws Exception protected void doStart() throws Exception
{ {
super.doStart(); super.doStart();
_connectTimer.setDuration(_httpClient.getConnectTimeout());
_connectTimer.setNow();
if (!_httpClient.isConnectBlocking())
{
_httpClient._threadPool.dispatch(new Runnable()
{
public void run()
{
while (isRunning())
{
_connectTimer.tick(System.currentTimeMillis());
try
{
Thread.sleep(200);
}
catch (InterruptedException x)
{
Thread.currentThread().interrupt();
break;
}
}
}
});
}
_selectorManager.start(); _selectorManager.start();
@ -136,7 +110,6 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
@Override @Override
protected void doStop() throws Exception protected void doStop() throws Exception
{ {
_connectTimer.cancelAll();
_selectorManager.stop(); _selectorManager.stop();
} }
@ -156,7 +129,7 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
channel.connect(address.toSocketAddress()); channel.connect(address.toSocketAddress());
_selectorManager.register( channel, destination ); _selectorManager.register( channel, destination );
ConnectTimeout connectTimeout = new ConnectTimeout(channel, destination); ConnectTimeout connectTimeout = new ConnectTimeout(channel, destination);
_connectTimer.schedule(connectTimeout); _httpClient.schedule(connectTimeout,_httpClient.getConnectTimeout());
_connectingChannels.put(channel, connectTimeout); _connectingChannels.put(channel, connectTimeout);
} }
else else