hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [2/2] httpcomponents-core git commit: Configurable connection pool concurrency policy
Date Mon, 21 Aug 2017 21:59:31 GMT
Configurable connection pool concurrency policy


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/bf041e34
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/bf041e34
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/bf041e34

Branch: refs/heads/master
Commit: bf041e34261bba0691965b64be4375eb0d14ab20
Parents: 2a38fb4
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Mon Aug 21 21:32:27 2017 +0200
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Mon Aug 21 21:32:27 2017 +0200

----------------------------------------------------------------------
 .../nio/bootstrap/H2RequesterBootstrap.java     | 39 +++++++++++---
 .../impl/bootstrap/AsyncRequesterBootstrap.java | 39 +++++++++++---
 .../http/impl/bootstrap/HttpAsyncRequester.java | 54 +++++++++++++++++++-
 .../http/impl/bootstrap/HttpRequester.java      | 54 +++++++++++++++++++-
 .../http/impl/bootstrap/RequesterBootstrap.java | 36 ++++++++++---
 .../org/apache/hc/core5/pool/LaxConnPool.java   |  6 +--
 .../hc/core5/pool/PoolConcurrencyPolicy.java    | 46 +++++++++++++++++
 .../apache/hc/core5/pool/TestLaxConnPool.java   | 33 +++++-------
 8 files changed, 264 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bf041e34/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
index 1ef866e..2238f1f 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
@@ -29,6 +29,7 @@ package org.apache.hc.core5.http2.impl.nio.bootstrap;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.hc.core5.annotation.Experimental;
 import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.function.Supplier;
 import org.apache.hc.core5.http.HttpHost;
@@ -51,6 +52,9 @@ import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
 import org.apache.hc.core5.http2.nio.support.DefaultAsyncPushConsumerFactory;
 import org.apache.hc.core5.http2.ssl.H2ClientTlsStrategy;
 import org.apache.hc.core5.pool.ConnPoolListener;
+import org.apache.hc.core5.pool.LaxConnPool;
+import org.apache.hc.core5.pool.ManagedConnPool;
+import org.apache.hc.core5.pool.PoolConcurrencyPolicy;
 import org.apache.hc.core5.pool.PoolReusePolicy;
 import org.apache.hc.core5.pool.StrictConnPool;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -77,6 +81,7 @@ public class H2RequesterBootstrap {
     private int maxTotal;
     private TimeValue timeToLive;
     private PoolReusePolicy poolReusePolicy;
+    private PoolConcurrencyPolicy poolConcurrencyPolicy;
     private TlsStrategy tlsStrategy;
     private Decorator<IOSession> ioSessionDecorator;
     private IOSessionListener sessionListener;
@@ -164,6 +169,15 @@ public class H2RequesterBootstrap {
     }
 
     /**
+     * Assigns {@link PoolConcurrencyPolicy} instance.
+     */
+    @Experimental
+    public final H2RequesterBootstrap setPoolConcurrencyPolicy(final PoolConcurrencyPolicy
poolConcurrencyPolicy) {
+        this.poolConcurrencyPolicy = poolConcurrencyPolicy;
+        return this;
+    }
+
+    /**
      * Assigns {@link TlsStrategy} instance.
      */
     public final H2RequesterBootstrap setTlsStrategy(final TlsStrategy tlsStrategy) {
@@ -250,12 +264,25 @@ public class H2RequesterBootstrap {
     }
 
     public Http2AsyncRequester create() {
-        final StrictConnPool<HttpHost, IOSession> connPool = new StrictConnPool<>(
-                defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
-                maxTotal > 0 ? maxTotal : 50,
-                timeToLive,
-                poolReusePolicy,
-                connPoolListener);
+        final ManagedConnPool<HttpHost, IOSession> connPool;
+        switch (poolConcurrencyPolicy != null ? poolConcurrencyPolicy : PoolConcurrencyPolicy.STRICT)
{
+            case LAX:
+                connPool = new LaxConnPool<>(
+                        defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
+                        timeToLive,
+                        poolReusePolicy,
+                        connPoolListener);
+                break;
+            case STRICT:
+            default:
+                connPool = new StrictConnPool<>(
+                        defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
+                        maxTotal > 0 ? maxTotal : 50,
+                        timeToLive,
+                        poolReusePolicy,
+                        connPoolListener);
+                break;
+        }
         final RequestHandlerRegistry<Supplier<AsyncPushConsumer>> registry =
new RequestHandlerRegistry<>(uriPatternType);
         for (final HandlerEntry<Supplier<AsyncPushConsumer>> entry: pushConsumerList)
{
             registry.register(entry.hostname, entry.uriPattern, entry.handler);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bf041e34/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
index 54d5994..ca77d02 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
@@ -26,6 +26,7 @@
  */
 package org.apache.hc.core5.http.impl.bootstrap;
 
+import org.apache.hc.core5.annotation.Experimental;
 import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.HttpHost;
@@ -39,6 +40,9 @@ import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.pool.ConnPoolListener;
+import org.apache.hc.core5.pool.LaxConnPool;
+import org.apache.hc.core5.pool.ManagedConnPool;
+import org.apache.hc.core5.pool.PoolConcurrencyPolicy;
 import org.apache.hc.core5.pool.PoolReusePolicy;
 import org.apache.hc.core5.pool.StrictConnPool;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -61,6 +65,7 @@ public class AsyncRequesterBootstrap {
     private int maxTotal;
     private Timeout timeToLive;
     private PoolReusePolicy poolReusePolicy;
+    private PoolConcurrencyPolicy poolConcurrencyPolicy;
     private TlsStrategy tlsStrategy;
     private Decorator<IOSession> ioSessionDecorator;
     private IOSessionListener sessionListener;
@@ -138,6 +143,15 @@ public class AsyncRequesterBootstrap {
     }
 
     /**
+     * Assigns {@link PoolConcurrencyPolicy} instance.
+     */
+    @Experimental
+    public final AsyncRequesterBootstrap setPoolConcurrencyPolicy(final PoolConcurrencyPolicy
poolConcurrencyPolicy) {
+        this.poolConcurrencyPolicy = poolConcurrencyPolicy;
+        return this;
+    }
+
+    /**
      * Assigns {@link TlsStrategy} instance.
      */
     public final AsyncRequesterBootstrap setTlsStrategy(final TlsStrategy tlsStrategy) {
@@ -178,12 +192,25 @@ public class AsyncRequesterBootstrap {
     }
 
     public HttpAsyncRequester create() {
-        final StrictConnPool<HttpHost, IOSession> connPool = new StrictConnPool<>(
-                defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
-                maxTotal > 0 ? maxTotal : 50,
-                timeToLive,
-                poolReusePolicy,
-                connPoolListener);
+        final ManagedConnPool<HttpHost, IOSession> connPool;
+        switch (poolConcurrencyPolicy != null ? poolConcurrencyPolicy : PoolConcurrencyPolicy.STRICT)
{
+            case LAX:
+                connPool = new LaxConnPool<>(
+                        defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
+                        timeToLive,
+                        poolReusePolicy,
+                        connPoolListener);
+                break;
+            case STRICT:
+            default:
+                connPool = new StrictConnPool<>(
+                        defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
+                        maxTotal > 0 ? maxTotal : 50,
+                        timeToLive,
+                        poolReusePolicy,
+                        connPoolListener);
+                break;
+        }
         final ClientHttp1StreamDuplexerFactory streamDuplexerFactory = new ClientHttp1StreamDuplexerFactory(
                 httpProcessor != null ? httpProcessor : HttpProcessors.client(),
                 h1Config != null ? h1Config : H1Config.DEFAULT,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bf041e34/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
index 764ee45..8c37d31 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
@@ -61,8 +61,10 @@ import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.net.URIAuthority;
+import org.apache.hc.core5.pool.ConnPoolControl;
 import org.apache.hc.core5.pool.ManagedConnPool;
 import org.apache.hc.core5.pool.PoolEntry;
+import org.apache.hc.core5.pool.PoolStats;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOSession;
@@ -74,7 +76,7 @@ import org.apache.hc.core5.util.TimeValue;
 /**
  * @since 5.0
  */
-public class HttpAsyncRequester extends AsyncRequester {
+public class HttpAsyncRequester extends AsyncRequester implements ConnPoolControl<HttpHost>
{
 
     private final ManagedConnPool<HttpHost, IOSession> connPool;
     private final TlsStrategy tlsStrategy;
@@ -98,6 +100,56 @@ public class HttpAsyncRequester extends AsyncRequester {
         this.tlsStrategy = tlsStrategy;
     }
 
+    @Override
+    public PoolStats getTotalStats() {
+        return connPool.getTotalStats();
+    }
+
+    @Override
+    public PoolStats getStats(final HttpHost route) {
+        return connPool.getStats(route);
+    }
+
+    @Override
+    public void setMaxTotal(final int max) {
+        connPool.setMaxTotal(max);
+    }
+
+    @Override
+    public int getMaxTotal() {
+        return connPool.getMaxTotal();
+    }
+
+    @Override
+    public void setDefaultMaxPerRoute(final int max) {
+        connPool.setDefaultMaxPerRoute(max);
+    }
+
+    @Override
+    public int getDefaultMaxPerRoute() {
+        return connPool.getDefaultMaxPerRoute();
+    }
+
+    @Override
+    public void setMaxPerRoute(final HttpHost route, final int max) {
+        connPool.setMaxPerRoute(route, max);
+    }
+
+    @Override
+    public int getMaxPerRoute(final HttpHost route) {
+        return connPool.getMaxPerRoute(route);
+    }
+
+    @Override
+    public void closeIdle(final TimeValue idleTime) {
+        connPool.closeIdle(idleTime);
+    }
+
+    @Override
+    public void closeExpired() {
+        connPool.closeExpired();
+    }
+
     public Future<AsyncClientEndpoint> connect(
             final HttpHost host,
             final TimeValue timeout,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bf041e34/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
index 32ba00d..0b8c3ce 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
@@ -68,13 +68,15 @@ import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.pool.ConnPoolControl;
 import org.apache.hc.core5.pool.ManagedConnPool;
 import org.apache.hc.core5.pool.PoolEntry;
+import org.apache.hc.core5.pool.PoolStats;
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.TimeValue;
 import org.apache.hc.core5.util.Timeout;
 
 /**
  * @since 5.0
  */
-public class HttpRequester implements GracefullyCloseable {
+public class HttpRequester implements ConnPoolControl<HttpHost>, GracefullyCloseable
{
 
     private final HttpRequestExecutor requestExecutor;
     private final HttpProcessor httpProcessor;
@@ -99,6 +101,56 @@ public class HttpRequester implements GracefullyCloseable {
         this.sslSocketFactory = sslSocketFactory != null ? sslSocketFactory : (SSLSocketFactory)
SSLSocketFactory.getDefault();
     }
 
+    @Override
+    public PoolStats getTotalStats() {
+        return connPool.getTotalStats();
+    }
+
+    @Override
+    public PoolStats getStats(final HttpHost route) {
+        return connPool.getStats(route);
+    }
+
+    @Override
+    public void setMaxTotal(final int max) {
+        connPool.setMaxTotal(max);
+    }
+
+    @Override
+    public int getMaxTotal() {
+        return connPool.getMaxTotal();
+    }
+
+    @Override
+    public void setDefaultMaxPerRoute(final int max) {
+        connPool.setDefaultMaxPerRoute(max);
+    }
+
+    @Override
+    public int getDefaultMaxPerRoute() {
+        return connPool.getDefaultMaxPerRoute();
+    }
+
+    @Override
+    public void setMaxPerRoute(final HttpHost route, final int max) {
+        connPool.setMaxPerRoute(route, max);
+    }
+
+    @Override
+    public int getMaxPerRoute(final HttpHost route) {
+        return connPool.getMaxPerRoute(route);
+    }
+
+    @Override
+    public void closeIdle(final TimeValue idleTime) {
+        connPool.closeIdle(idleTime);
+    }
+
+    @Override
+    public void closeExpired() {
+        connPool.closeExpired();
+    }
+
     public ClassicHttpResponse execute(
             final HttpClientConnection connection,
             final ClassicHttpRequest request,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bf041e34/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
index e7609ca..7a5cebd 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
@@ -28,6 +28,7 @@ package org.apache.hc.core5.http.impl.bootstrap;
 
 import javax.net.ssl.SSLSocketFactory;
 
+import org.apache.hc.core5.annotation.Experimental;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.config.CharCodingConfig;
@@ -42,6 +43,9 @@ import org.apache.hc.core5.http.io.HttpClientConnection;
 import org.apache.hc.core5.http.io.HttpConnectionFactory;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.pool.ConnPoolListener;
+import org.apache.hc.core5.pool.LaxConnPool;
+import org.apache.hc.core5.pool.ManagedConnPool;
+import org.apache.hc.core5.pool.PoolConcurrencyPolicy;
 import org.apache.hc.core5.pool.PoolReusePolicy;
 import org.apache.hc.core5.pool.StrictConnPool;
 import org.apache.hc.core5.util.Timeout;
@@ -60,6 +64,7 @@ public class RequesterBootstrap {
     private int maxTotal;
     private Timeout timeToLive;
     private PoolReusePolicy poolReusePolicy;
+    private PoolConcurrencyPolicy poolConcurrencyPolicy;
     private Http1StreamListener streamListener;
     private ConnPoolListener<HttpHost> connPoolListener;
 
@@ -124,6 +129,12 @@ public class RequesterBootstrap {
         return this;
     }
 
+    @Experimental
+    public final RequesterBootstrap setPoolConcurrencyPolicy(final PoolConcurrencyPolicy
poolConcurrencyPolicy) {
+        this.poolConcurrencyPolicy = poolConcurrencyPolicy;
+        return this;
+    }
+
     public final RequesterBootstrap setStreamListener(final Http1StreamListener streamListener)
{
         this.streamListener = streamListener;
         return this;
@@ -139,12 +150,25 @@ public class RequesterBootstrap {
                 HttpRequestExecutor.DEFAULT_WAIT_FOR_CONTINUE,
                 connReuseStrategy != null ? connReuseStrategy : DefaultConnectionReuseStrategy.INSTANCE,
                 streamListener);
-        final StrictConnPool<HttpHost, HttpClientConnection> connPool = new StrictConnPool<>(
-                defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
-                maxTotal > 0 ? maxTotal : 50,
-                timeToLive,
-                poolReusePolicy,
-                connPoolListener);
+        final ManagedConnPool<HttpHost, HttpClientConnection> connPool;
+        switch (poolConcurrencyPolicy != null ? poolConcurrencyPolicy : PoolConcurrencyPolicy.STRICT)
{
+            case LAX:
+                connPool = new LaxConnPool<>(
+                        defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
+                        timeToLive,
+                        poolReusePolicy,
+                        connPoolListener);
+                break;
+            case STRICT:
+            default:
+                connPool = new StrictConnPool<>(
+                        defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
+                        maxTotal > 0 ? maxTotal : 50,
+                        timeToLive,
+                        poolReusePolicy,
+                        connPoolListener);
+                break;
+        }
         return new HttpRequester(
                 requestExecutor,
                 httpProcessor != null ? httpProcessor : HttpProcessors.client(),

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bf041e34/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java
index 8d197ff..06e2b9f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/LaxConnPool.java
@@ -77,13 +77,11 @@ public class LaxConnPool<T, C extends GracefullyCloseable> implements
ManagedCon
      */
     public LaxConnPool(
             final int defaultMaxPerRoute,
-            final int maxTotal,
             final TimeValue timeToLive,
             final PoolReusePolicy policy,
             final ConnPoolListener<T> connPoolListener) {
         super();
         Args.positive(defaultMaxPerRoute, "Max per route value");
-        Args.positive(maxTotal, "Max total value");
         this.timeToLive = TimeValue.defaultsToNegativeOneMillisecond(timeToLive);
         this.connPoolListener = connPoolListener;
         this.policy = policy != null ? policy : PoolReusePolicy.LIFO;
@@ -92,8 +90,8 @@ public class LaxConnPool<T, C extends GracefullyCloseable> implements
ManagedCon
         this.defaultMaxPerRoute = defaultMaxPerRoute;
     }
 
-    public LaxConnPool(final int defaultMaxPerRoute, final int maxTotal) {
-        this(defaultMaxPerRoute, maxTotal, TimeValue.NEG_ONE_MILLISECONDS, PoolReusePolicy.LIFO,
null);
+    public LaxConnPool(final int defaultMaxPerRoute) {
+        this(defaultMaxPerRoute, TimeValue.NEG_ONE_MILLISECONDS, PoolReusePolicy.LIFO, null);
     }
 
     public boolean isShutdown() {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bf041e34/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolConcurrencyPolicy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolConcurrencyPolicy.java b/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolConcurrencyPolicy.java
new file mode 100644
index 0000000..01216fd
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/pool/PoolConcurrencyPolicy.java
@@ -0,0 +1,46 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.pool;
+
+/**
+ * Enumeration of pool concurrency policies
+ *
+ * @since 5.0
+ */
+public enum PoolConcurrencyPolicy {
+
+    /**
+     * Higher concurrency but with lax connection max limit guarantees.
+     */
+    LAX,
+
+    /**
+     * Strict connection max limit guarantees.
+     */
+    STRICT
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bf041e34/httpcore5/src/test/java/org/apache/hc/core5/pool/TestLaxConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/pool/TestLaxConnPool.java b/httpcore5/src/test/java/org/apache/hc/core5/pool/TestLaxConnPool.java
index 5cfc6ea..01207b3 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/pool/TestLaxConnPool.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/pool/TestLaxConnPool.java
@@ -42,7 +42,7 @@ public class TestLaxConnPool {
 
     @Test
     public void testEmptyPool() throws Exception {
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
10);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
         final PoolStats totals = pool.getTotalStats();
         Assert.assertEquals(0, totals.getAvailable());
         Assert.assertEquals(0, totals.getLeased());
@@ -60,12 +60,7 @@ public class TestLaxConnPool {
     @Test
     public void testInvalidConstruction() throws Exception {
         try {
-            new LaxConnPool<String, HttpConnection>(-1, 1);
-            Assert.fail("IllegalArgumentException should have been thrown");
-        } catch (final IllegalArgumentException expected) {
-        }
-        try {
-            new LaxConnPool<String, HttpConnection>(1, -1);
+            new LaxConnPool<String, HttpConnection>(-1);
             Assert.fail("IllegalArgumentException should have been thrown");
         } catch (final IllegalArgumentException expected) {
         }
@@ -77,7 +72,7 @@ public class TestLaxConnPool {
         final HttpConnection conn2 = Mockito.mock(HttpConnection.class);
         final HttpConnection conn3 = Mockito.mock(HttpConnection.class);
 
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
10);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
         final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost",
null);
         final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost",
null);
         final Future<PoolEntry<String, HttpConnection>> future3 = pool.lease("otherhost",
null);
@@ -107,7 +102,7 @@ public class TestLaxConnPool {
 
     @Test
     public void testLeaseIllegal() throws Exception {
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
10);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
         try {
             pool.lease(null, null, Timeout.ZERO_MILLISECONDS, null);
             Assert.fail("IllegalArgumentException should have been thrown");
@@ -122,7 +117,7 @@ public class TestLaxConnPool {
 
     @Test(expected = IllegalStateException.class)
     public void testReleaseUnknownEntry() throws Exception {
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
2);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
         pool.release(new PoolEntry<String, HttpConnection>("somehost"), true);
     }
 
@@ -132,7 +127,7 @@ public class TestLaxConnPool {
         final HttpConnection conn2 = Mockito.mock(HttpConnection.class);
         final HttpConnection conn3 = Mockito.mock(HttpConnection.class);
 
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
10);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
         pool.setMaxPerRoute("somehost", 2);
         pool.setMaxPerRoute("otherhost", 1);
 
@@ -209,7 +204,7 @@ public class TestLaxConnPool {
     public void testCreateNewIfExpired() throws Exception {
         final HttpConnection conn1 = Mockito.mock(HttpConnection.class);
 
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
2);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
 
         final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost",
null);
 
@@ -243,7 +238,7 @@ public class TestLaxConnPool {
         final HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         final HttpConnection conn2 = Mockito.mock(HttpConnection.class);
 
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
2);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
 
         final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost",
null);
         final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost",
null);
@@ -285,7 +280,7 @@ public class TestLaxConnPool {
         final HttpConnection conn1 = Mockito.mock(HttpConnection.class);
         final HttpConnection conn2 = Mockito.mock(HttpConnection.class);
 
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
2);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
 
         final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost",
null);
         final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost",
null);
@@ -339,7 +334,7 @@ public class TestLaxConnPool {
     public void testLeaseRequestTimeout() throws Exception {
         final HttpConnection conn1 = Mockito.mock(HttpConnection.class);
 
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(1,
1);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(1);
 
         final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost",
null, Timeout.ofMillis(0), null);
         final Future<PoolEntry<String, HttpConnection>> future2 = pool.lease("somehost",
null, Timeout.ofMillis(0), null);
@@ -362,7 +357,7 @@ public class TestLaxConnPool {
 
     @Test
     public void testLeaseRequestCanceled() throws Exception {
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(1,
1);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(1);
 
         final Future<PoolEntry<String, HttpConnection>> future1 = pool.lease("somehost",
null, Timeout.ofMillis(0), null);
 
@@ -383,13 +378,13 @@ public class TestLaxConnPool {
 
     @Test(expected=IllegalArgumentException.class)
     public void testGetStatsInvalid() throws Exception {
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
2);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
         pool.getStats(null);
     }
 
     @Test
     public void testSetMaxInvalid() throws Exception {
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
2);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
         try {
             pool.setMaxPerRoute(null, 1);
             Assert.fail("IllegalArgumentException should have been thrown");
@@ -409,7 +404,7 @@ public class TestLaxConnPool {
 
     @Test
     public void testShutdown() throws Exception {
-        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2,
2);
+        final LaxConnPool<String, HttpConnection> pool = new LaxConnPool<>(2);
         pool.shutdown(ShutdownType.GRACEFUL);
         try {
             pool.lease("somehost", null);


Mime
View raw message