hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1583590 - /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
Date Tue, 01 Apr 2014 10:04:22 GMT
Author: olegk
Date: Tue Apr  1 10:04:21 2014
New Revision: 1583590

URL: http://svn.apache.org/r1583590
Log:
HTTPCLIENT-1492: connection time to live not settable via HttpClientBuilder
Contributed by Matt Inger <mattinger at yahoo.com>

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java?rev=1583590&r1=1583589&r2=1583590&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpClientBuilder.java
Tue Apr  1 10:04:21 2014
@@ -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;
@@ -310,6 +314,20 @@ public class HttpClientBuilder {
     }
 
     /**
+     * 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.
      */
     public final HttpClientBuilder setConnectionManager(
@@ -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);
             }



Mime
View raw message