HTTPCLIENT-1492: connection time to live not settable via HttpClientBuilder

Contributed by Matt Inger <mattinger at yahoo.com>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1583590 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-04-01 10:04:21 +00:00
parent 85f876d6b1
commit 719daae514
1 changed files with 24 additions and 1 deletions

View File

@ -34,6 +34,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.Map;
import javax.net.ssl.SSLContext;
@ -201,6 +202,9 @@ public class HttpClientBuilder {
private int maxConnTotal = 0;
private int maxConnPerRoute = 0;
private long connTimeToLive = -1;
private TimeUnit connTimeToLiveTimeUnit = TimeUnit.MILLISECONDS;
private List<Closeable> closeables;
static final String DEFAULT_USER_AGENT;
@ -309,6 +313,20 @@ public class HttpClientBuilder {
return this;
}
/**
* Sets maximum time to live for persistent connections
* <p/>
* Please note this value can be overridden by the {@link #setConnectionManager(
* org.apache.http.conn.HttpClientConnectionManager)} method.
*
* @since 4.4
*/
public final HttpClientBuilder setConnectionTimeToLive(final long connTimeToLive, final TimeUnit connTimeToLiveTimeUnit) {
this.connTimeToLive = connTimeToLive;
this.connTimeToLiveTimeUnit = connTimeToLiveTimeUnit;
return this;
}
/**
* Assigns {@link HttpClientConnectionManager} instance.
*/
@ -743,7 +761,12 @@ public class HttpClientBuilder {
RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslSocketFactoryCopy)
.build());
.build(),
null,
null,
null,
connTimeToLive,
connTimeToLiveTimeUnit != null ? connTimeToLiveTimeUnit : TimeUnit.MILLISECONDS);
if (defaultSocketConfig != null) {
poolingmgr.setDefaultSocketConfig(defaultSocketConfig);
}