aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-feed-client-api
diff options
context:
space:
mode:
authorMorten Tokle <mortent@verizonmedia.com>2021-12-09 15:49:51 +0100
committerMorten Tokle <mortent@verizonmedia.com>2021-12-14 08:36:53 +0100
commitf16f20804691546bba8c234c47fb713ab9db1a18 (patch)
tree3889cb6fe5b83eb0d1ca7eaa00d69df1a545ef04 /vespa-feed-client-api
parent5a35f284c78f8f6c834013614a977f63536b5c4e (diff)
Support preferred implementation
Diffstat (limited to 'vespa-feed-client-api')
-rw-r--r--vespa-feed-client-api/abi-spec.json4
-rw-r--r--vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java14
2 files changed, 15 insertions, 3 deletions
diff --git a/vespa-feed-client-api/abi-spec.json b/vespa-feed-client-api/abi-spec.json
index cabe9afde20..a9047365a7a 100644
--- a/vespa-feed-client-api/abi-spec.json
+++ b/vespa-feed-client-api/abi-spec.json
@@ -139,7 +139,9 @@
"public abstract ai.vespa.feed.client.FeedClientBuilder setEndpointUris(java.util.List)",
"public abstract ai.vespa.feed.client.FeedClient build()"
],
- "fields": []
+ "fields": [
+ "public static final java.lang.String PREFERRED_IMPLEMENTATION_PROPERTY"
+ ]
},
"ai.vespa.feed.client.FeedException": {
"superClass": "java.lang.RuntimeException",
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 daf3f62dac1..05bc608df27 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
@@ -9,6 +9,7 @@ import java.net.URI;
import java.nio.file.Path;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -24,17 +25,26 @@ import java.util.function.Supplier;
*/
public interface FeedClientBuilder {
+ String PREFERRED_IMPLEMENTATION_PROPERTY = "vespa.feed.client.builder.implementation";
+
/** Creates a builder for a single container endpoint **/
static FeedClientBuilder create(URI endpoint) { return create(Collections.singletonList(endpoint)); }
/** Creates a builder for multiple container endpoints **/
static FeedClientBuilder create(List<URI> endpoints) {
+ String defaultImplementation = "ai.vespa.feed.client.impl.FeedClientBuilderImpl";
+ String preferredImplementation = System.getProperty(PREFERRED_IMPLEMENTATION_PROPERTY, defaultImplementation);
Iterator<FeedClientBuilder> iterator = ServiceLoader.load(FeedClientBuilder.class).iterator();
if (iterator.hasNext()) {
- return iterator.next().setEndpointUris(endpoints);
+ List<FeedClientBuilder> builders = new ArrayList<>();
+ iterator.forEachRemaining(builders::add);
+ return builders.stream()
+ .filter(builder -> preferredImplementation.equals(builder.getClass().getName()))
+ .findFirst()
+ .orElse(builders.get(0));
} else {
try {
- Class<?> aClass = Class.forName("ai.vespa.feed.client.impl.FeedClientBuilderImpl");
+ Class<?> aClass = Class.forName(preferredImplementation);
for (Constructor<?> constructor : aClass.getConstructors()) {
if (constructor.getParameterTypes().length==0) {
return ((FeedClientBuilder)constructor.newInstance()).setEndpointUris(endpoints);