aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-feed-client-api/src/main/java/ai
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/src/main/java/ai
parent5a35f284c78f8f6c834013614a977f63536b5c4e (diff)
Support preferred implementation
Diffstat (limited to 'vespa-feed-client-api/src/main/java/ai')
-rw-r--r--vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java14
1 files changed, 12 insertions, 2 deletions
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);