summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vespa-feed-client-api/abi-spec.json1
-rw-r--r--vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java4
-rw-r--r--vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java8
-rw-r--r--vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/JettyCluster.java5
4 files changed, 17 insertions, 1 deletions
diff --git a/vespa-feed-client-api/abi-spec.json b/vespa-feed-client-api/abi-spec.json
index e8c2b4a3c9e..907d974ff09 100644
--- a/vespa-feed-client-api/abi-spec.json
+++ b/vespa-feed-client-api/abi-spec.json
@@ -144,6 +144,7 @@
"public static void setFeedClientBuilderSupplier(java.util.function.Supplier)",
"public abstract ai.vespa.feed.client.FeedClientBuilder setConnectionsPerEndpoint(int)",
"public abstract ai.vespa.feed.client.FeedClientBuilder setMaxStreamPerConnection(int)",
+ "public abstract ai.vespa.feed.client.FeedClientBuilder setConnectionTimeToLive(java.time.Duration)",
"public abstract ai.vespa.feed.client.FeedClientBuilder setSslContext(javax.net.ssl.SSLContext)",
"public abstract ai.vespa.feed.client.FeedClientBuilder setHostnameVerifier(javax.net.ssl.HostnameVerifier)",
"public abstract ai.vespa.feed.client.FeedClientBuilder setProxyHostnameVerifier(javax.net.ssl.HostnameVerifier)",
diff --git a/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java b/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java
index 270ecad6af8..7101b8452ed 100644
--- a/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java
+++ b/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java
@@ -7,6 +7,7 @@ import java.net.URI;
import java.nio.file.Path;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
+import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -63,6 +64,9 @@ public interface FeedClientBuilder {
*/
FeedClientBuilder setMaxStreamPerConnection(int max);
+ /** Sets a duration after which this client will recycle active connections. This is off ({@code Duration.ZERO}) by default. */
+ FeedClientBuilder setConnectionTimeToLive(Duration ttl);
+
/** Sets {@link SSLContext} instance. */
FeedClientBuilder setSslContext(SSLContext context);
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java
index cacaeac30ae..6b4372fd11a 100644
--- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java
+++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java
@@ -60,6 +60,7 @@ public class FeedClientBuilderImpl implements FeedClientBuilder {
boolean speedTest = false;
Compression compression = auto;
URI proxy;
+ Duration connectionTtl = Duration.ZERO;
public FeedClientBuilderImpl() {
@@ -95,6 +96,13 @@ public class FeedClientBuilderImpl implements FeedClientBuilder {
return this;
}
+ @Override
+ public FeedClientBuilder setConnectionTimeToLive(Duration ttl) {
+ if (ttl.isNegative()) throw new IllegalArgumentException("Connection TTL cannot be negative, but was " + ttl);
+ this.connectionTtl = ttl;
+ return this;
+ }
+
/** Sets {@link SSLContext} instance. */
@Override
public FeedClientBuilderImpl setSslContext(SSLContext context) {
diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/JettyCluster.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/JettyCluster.java
index 1edcc6d6cba..5454249d52e 100644
--- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/JettyCluster.java
+++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/JettyCluster.java
@@ -159,7 +159,10 @@ class JettyCluster implements Cluster {
dest, Pool.StrategyType.RANDOM, connectionsPerEndpoint, false, dest, Integer.MAX_VALUE);
pool.preCreateConnections(connectionsPerEndpoint);
if (secureProxy) pool.setMaxDuration(Duration.ofMinutes(1).toMillis());
- else pool.setMaximizeConnections(true);
+ else {
+ pool.setMaximizeConnections(true);
+ pool.setMaxDuration(b.connectionTtl.toMillis());
+ }
return pool;
});
HttpClient httpClient = new HttpClient(transport);