hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1604772 - in /httpcomponents/httpclient/trunk: ./ fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient/src/examples/org/apache/http/examples/client/ httpclient/src/main/java/org/apache/http/client/config/ httpclient/src/main/j...
Date Mon, 23 Jun 2014 12:13:36 GMT
Author: olegk
Date: Mon Jun 23 12:13:35 2014
New Revision: 1604772

URL: http://svn.apache.org/r1604772
Log:
HTTPCLIENT-1493: Indiscriminate connection checking has been deprecated in favor of conditional
connection state validation. Persistent connections are to be re-validated only after a defined
period inactivity prior to being leased to the consumer.

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java
    httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1604772&r1=1604771&r2=1604772&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Mon Jun 23 12:13:35 2014
@@ -4,6 +4,11 @@ Changes for 4.4-alpha1
 Changelog:
 -------------------
 
+* [HTTPCLIENT-1493] Indiscriminate connection checking has been deprecated in favor of conditional
+  connection state validation. Persistent connections are to be re-validated only after a
defined
+  period inactivity prior to being leased to the consumer.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1519] Use the original HttpHost instance passed as a parameter to
   HttpClient#execute when generating 'Host' request header.
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Modified: httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java?rev=1604772&r1=1604771&r2=1604772&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java
(original)
+++ httpcomponents/httpclient/trunk/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java
Mon Jun 23 12:13:35 2014
@@ -277,6 +277,11 @@ public class Request {
         return this;
     }
 
+    /**
+     * @deprecated (4.4) Use {@link
+     *   org.apache.http.impl.conn.PoolingHttpClientConnectionManager#setValidateAfterInactivity(int)}
+     */
+    @Deprecated
     public Request staleConnectionCheck(final boolean b) {
         this.configBuilder.setStaleConnectionCheckEnabled(b);
         return this;

Modified: httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java?rev=1604772&r1=1604771&r2=1604772&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java
Mon Jun 23 12:13:35 2014
@@ -177,6 +177,8 @@ public class ClientConfiguration {
         // by default or for a specific host.
         connManager.setDefaultSocketConfig(socketConfig);
         connManager.setSocketConfig(new HttpHost("somehost", 80), socketConfig);
+        // Validate connections after 1 sec of inactivity
+        connManager.setValidateAfterInactivity(1000);
 
         // Create message constraints
         MessageConstraints messageConstraints = MessageConstraints.custom()
@@ -209,7 +211,6 @@ public class ClientConfiguration {
         RequestConfig defaultRequestConfig = RequestConfig.custom()
             .setCookieSpec(CookieSpecs.BEST_MATCH)
             .setExpectContinueEnabled(true)
-            .setStaleConnectionCheckEnabled(true)
             .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
             .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
             .build();

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java?rev=1604772&r1=1604771&r2=1604772&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java
Mon Jun 23 12:13:35 2014
@@ -141,7 +141,11 @@ public class RequestConfig implements Cl
      * operations this check should be disabled.
      * <p/>
      * Default: <code>true</code>
+     *
+     * @deprecated (4.4) Use {@link
+     *   org.apache.http.impl.conn.PoolingHttpClientConnectionManager#getValidateAfterInactivity()}
      */
+    @Deprecated
     public boolean isStaleConnectionCheckEnabled() {
         return staleConnectionCheckEnabled;
     }
@@ -288,7 +292,6 @@ public class RequestConfig implements Cl
         builder.append(", expectContinueEnabled=").append(expectContinueEnabled);
         builder.append(", proxy=").append(proxy);
         builder.append(", localAddress=").append(localAddress);
-        builder.append(", staleConnectionCheckEnabled=").append(staleConnectionCheckEnabled);
         builder.append(", cookieSpec=").append(cookieSpec);
         builder.append(", redirectsEnabled=").append(redirectsEnabled);
         builder.append(", relativeRedirectsAllowed=").append(relativeRedirectsAllowed);
@@ -309,6 +312,7 @@ public class RequestConfig implements Cl
         return new Builder();
     }
 
+    @SuppressWarnings("deprecation")
     public static RequestConfig.Builder copy(final RequestConfig config) {
         return new Builder()
             .setExpectContinueEnabled(config.isExpectContinueEnabled())
@@ -350,7 +354,7 @@ public class RequestConfig implements Cl
 
         Builder() {
             super();
-            this.staleConnectionCheckEnabled = true;
+            this.staleConnectionCheckEnabled = false;
             this.redirectsEnabled = true;
             this.maxRedirects = 50;
             this.relativeRedirectsAllowed = true;
@@ -376,6 +380,11 @@ public class RequestConfig implements Cl
             return this;
         }
 
+        /**
+         * @deprecated (4.4) Use {@link
+         *   org.apache.http.impl.conn.PoolingHttpClientConnectionManager#setValidateAfterInactivity(int)}
+         */
+        @Deprecated
         public Builder setStaleConnectionCheckEnabled(final boolean staleConnectionCheckEnabled)
{
             this.staleConnectionCheckEnabled = staleConnectionCheckEnabled;
             return this;

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java?rev=1604772&r1=1604771&r2=1604772&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
Mon Jun 23 12:13:35 2014
@@ -163,6 +163,7 @@ public class PoolingHttpClientConnection
         this.configData = new ConfigData();
         this.pool = new CPool(new InternalConnectionFactory(
                 this.configData, connFactory), 2, 20, timeToLive, tunit);
+        this.pool.setValidateAfterInactivity(5000);
         this.connectionOperator = Args.notNull(httpClientConnectionOperator, "HttpClientConnectionOperator");
         this.isShutDown = new AtomicBoolean(false);
     }
@@ -469,6 +470,30 @@ public class PoolingHttpClientConnection
         this.configData.setConnectionConfig(host, connectionConfig);
     }
 
+    /**
+     * @see #setValidateAfterInactivity(int)
+     *
+     * @since 4.4
+     */
+    public int getValidateAfterInactivity() {
+        return pool.getValidateAfterInactivity();
+    }
+
+    /**
+     * Defines period of inactivity in milliseconds after which persistent connections must
+     * be re-validated prior to being {@link #leaseConnection(java.util.concurrent.Future,
+     *   long, java.util.concurrent.TimeUnit) leased} to the consumer. Non-positive value
passed
+     * to this method disables connection validation. This check helps detect connections
+     * that have become stale (half-closed) while kept inactive in the pool.
+     *
+     * @see #leaseConnection(java.util.concurrent.Future, long, java.util.concurrent.TimeUnit)
+     *
+     * @since 4.4
+     */
+    public void setValidateAfterInactivity(final int ms) {
+        pool.setValidateAfterInactivity(ms);
+    }
+
     static class ConfigData {
 
         private final Map<HttpHost, SocketConfig> socketConfigMap;

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java?rev=1604772&r1=1604771&r2=1604772&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
Mon Jun 23 12:13:35 2014
@@ -84,6 +84,7 @@ import org.apache.http.util.EntityUtils;
  *
  * @since 4.3
  */
+@SuppressWarnings("deprecation")
 @Immutable
 public class MainClientExec implements ClientExecChain {
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java?rev=1604772&r1=1604771&r2=1604772&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java
Mon Jun 23 12:13:35 2014
@@ -27,13 +27,13 @@
 
 package org.apache.http.client.config;
 
+import java.net.InetAddress;
+import java.util.Arrays;
+
 import org.apache.http.HttpHost;
 import org.junit.Assert;
 import org.junit.Test;
 
-import java.net.InetAddress;
-import java.util.Arrays;
-
 public class TestRequestConfig {
 
     @Test
@@ -49,7 +49,6 @@ public class TestRequestConfig {
         Assert.assertEquals(-1, config.getConnectTimeout());
         Assert.assertEquals(-1, config.getConnectionRequestTimeout());
         Assert.assertEquals(false, config.isExpectContinueEnabled());
-        Assert.assertEquals(true, config.isStaleConnectionCheckEnabled());
         Assert.assertEquals(true, config.isAuthenticationEnabled());
         Assert.assertEquals(true, config.isRedirectsEnabled());
         Assert.assertEquals(true, config.isRelativeRedirectsAllowed());
@@ -69,7 +68,6 @@ public class TestRequestConfig {
                 .setConnectTimeout(33)
                 .setConnectionRequestTimeout(44)
                 .setExpectContinueEnabled(true)
-                .setStaleConnectionCheckEnabled(false)
                 .setAuthenticationEnabled(false)
                 .setRedirectsEnabled(false)
                 .setRelativeRedirectsAllowed(false)
@@ -86,7 +84,6 @@ public class TestRequestConfig {
         Assert.assertEquals(33, config.getConnectTimeout());
         Assert.assertEquals(44, config.getConnectionRequestTimeout());
         Assert.assertEquals(true, config.isExpectContinueEnabled());
-        Assert.assertEquals(false, config.isStaleConnectionCheckEnabled());
         Assert.assertEquals(false, config.isAuthenticationEnabled());
         Assert.assertEquals(false, config.isRedirectsEnabled());
         Assert.assertEquals(false, config.isRelativeRedirectsAllowed());

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java?rev=1604772&r1=1604771&r2=1604772&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java
Mon Jun 23 12:13:35 2014
@@ -306,35 +306,6 @@ public class TestMainClientExec {
     }
 
     @Test
-    public void testExecRequestStaleConnectionCheck() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
-        final HttpClientContext context = new HttpClientContext();
-        final RequestConfig config = RequestConfig.custom()
-                .setStaleConnectionCheckEnabled(true)
-                .build();
-        final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
-        context.setRequestConfig(config);
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
-
-        Mockito.when(managedConn.isOpen()).thenReturn(Boolean.TRUE);
-        Mockito.when(managedConn.isStale()).thenReturn(Boolean.TRUE);
-        Mockito.when(requestExecutor.execute(
-                Mockito.same(request),
-                Mockito.<HttpClientConnection>any(),
-                Mockito.<HttpClientContext>any())).thenReturn(response);
-        Mockito.when(reuseStrategy.keepAlive(
-                Mockito.same(response),
-                Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
-
-        final CloseableHttpResponse finalResponse = mainClientExec.execute(
-                route, request, context, execAware);
-        Mockito.verify(managedConn, Mockito.times(1)).close();
-
-        Assert.assertNotNull(finalResponse);
-        Assert.assertTrue(finalResponse instanceof HttpResponseProxy);
-    }
-
-    @Test
     public void testSocketTimeoutExistingConnection() throws Exception {
         final HttpRoute route = new HttpRoute(target);
         final HttpClientContext context = new HttpClientContext();



Mime
View raw message