Re-introduced timeout parameter for connection manager operations

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1098098 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2011-04-30 11:11:51 +00:00
parent e0d8ec5d34
commit 4998e3562d
5 changed files with 46 additions and 2 deletions

View File

@ -126,5 +126,16 @@ public interface ClientPNames {
*/
public static final String DEFAULT_HOST = "http.default-host";
/**
* Defines the timeout in milliseconds used when retrieving an instance of
* {@link org.apache.http.conn.ManagedClientConnection} from the
* {@link org.apache.http.conn.ClientConnectionManager}.
* <p>
* This parameter expects a value of type {@link Long}.
* <p>
* @since 4.2
*/
public static final String CONN_MANAGER_TIMEOUT = "http.conn-manager.timeout";
}

View File

@ -96,4 +96,11 @@ public class ClientParamBean extends HttpAbstractParamBean {
params.setParameter(ClientPNames.DEFAULT_HOST, host);
}
/**
* @since 4.2
*/
public void setConnectionManagerTimeout(final long timeout) {
params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, timeout);
}
}

View File

@ -28,6 +28,7 @@ package org.apache.http.client.params;
import org.apache.http.annotation.Immutable;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
/**
@ -93,4 +94,28 @@ public class HttpClientParams {
params.setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
}
/**
* @since 4.2
*/
public static void setConnectionManagerTimeout(final HttpParams params, long timeout) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, timeout);
}
/**
* @since 4.2
*/
public static long getConnectionManagerTimeout(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Long timeout = (Long) params.getParameter(ClientPNames.CONN_MANAGER_TIMEOUT);
if (timeout != null) {
return timeout.longValue();
}
return HttpConnectionParams.getConnectionTimeout(params);
}
}

View File

@ -109,6 +109,7 @@ import org.apache.http.util.VersionInfo;
* <li>{@link org.apache.http.client.params.ClientPNames#DEFAULT_HOST}</li>
* <li>{@link org.apache.http.client.params.ClientPNames#DEFAULT_HEADERS}</li>
* <li>{@link org.apache.http.client.params.ClientPNames#CONNECTION_MANAGER_FACTORY_CLASS_NAME}</li>
* <li>{@link org.apache.http.client.params.ClientPNames#CONN_MANAGER_TIMEOUT}</li>
* </ul>
*
* @since 4.0

View File

@ -126,6 +126,7 @@ import org.apache.http.util.EntityUtils;
* <li>{@link org.apache.http.client.params.ClientPNames#VIRTUAL_HOST}</li>
* <li>{@link org.apache.http.client.params.ClientPNames#DEFAULT_HOST}</li>
* <li>{@link org.apache.http.client.params.ClientPNames#DEFAULT_HEADERS}</li>
* <li>{@link org.apache.http.client.params.ClientPNames#CONN_MANAGER_TIMEOUT}</li>
* </ul>
*
* @since 4.0
@ -360,8 +361,6 @@ public class DefaultRequestDirector implements RequestDirector {
RoutedRequest roureq = new RoutedRequest(origWrapper, origRoute);
long timeout = HttpConnectionParams.getConnectionTimeout(params);
boolean reuse = false;
boolean done = false;
try {
@ -387,6 +386,7 @@ public class DefaultRequestDirector implements RequestDirector {
((AbortableHttpRequest) orig).setConnectionRequest(connRequest);
}
long timeout = HttpClientParams.getConnectionManagerTimeout(params);
try {
managedConn = connRequest.getConnection(timeout, TimeUnit.MILLISECONDS);
} catch(InterruptedException interrupted) {