From ae6eaa77738ec0ba96a3b22cb144573ef9b29c93 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Tue, 18 Feb 2020 14:20:26 +0100 Subject: Remove map, there is always just one config source set and one requester --- .../vespa/config/proxy/RpcConfigSourceClient.java | 38 ++++++---------------- .../config/proxy/UpstreamConfigSubscriber.java | 15 ++++----- 2 files changed, 17 insertions(+), 36 deletions(-) (limited to 'config-proxy') diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java index ee843088086..e8fc5a94645 100644 --- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java +++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/RpcConfigSourceClient.java @@ -11,13 +11,15 @@ import com.yahoo.jrt.Supervisor; import com.yahoo.jrt.Target; import com.yahoo.jrt.Transport; import com.yahoo.log.LogLevel; -import com.yahoo.vespa.config.*; +import com.yahoo.vespa.config.ConfigCacheKey; +import com.yahoo.vespa.config.JRTConnectionPool; +import com.yahoo.vespa.config.RawConfig; +import com.yahoo.vespa.config.TimingValues; import com.yahoo.vespa.config.protocol.JRTServerConfigRequest; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.concurrent.DelayQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -42,7 +44,7 @@ class RpcConfigSourceClient implements ConfigSourceClient { private final TimingValues timingValues; private final ExecutorService exec; - private final Map requesterPool; + private final JRTConfigRequester requester; RpcConfigSourceClient(RpcServer rpcServer, @@ -57,20 +59,7 @@ class RpcConfigSourceClient implements ConfigSourceClient { this.timingValues = timingValues; checkConfigSources(); exec = Executors.newCachedThreadPool(new DaemonThreadFactory("subscriber-")); - requesterPool = createRequesterPool(configSourceSet, timingValues); - } - - /** - * Creates a requester (connection) pool of one entry, to be used each time this {@link RpcConfigSourceClient} is used - * @param ccs a {@link ConfigSourceSet} - * @param timingValues a {@link TimingValues} - * @return requester map - */ - private Map createRequesterPool(ConfigSourceSet ccs, TimingValues timingValues) { - Map ret = new HashMap<>(); - if (ccs.getSources().isEmpty()) return ret; // unit test, just skip creating any requester - ret.put(ccs, new JRTConfigRequester(new JRTConnectionPool(ccs), timingValues)); - return ret; + requester = new JRTConfigRequester(new JRTConnectionPool(configSourceSet), timingValues); } /** @@ -153,7 +142,7 @@ class RpcConfigSourceClient implements ConfigSourceClient { } else { log.log(LogLevel.DEBUG, () -> "Could not find good config in cache, creating subscriber for: " + configCacheKey); UpstreamConfigSubscriber subscriber = new UpstreamConfigSubscriber(input, this, configSourceSet, - timingValues, requesterPool, memoryCache); + timingValues, requester, memoryCache); try { subscriber.subscribe(); activeSubscribers.put(configCacheKey, subscriber); @@ -183,25 +172,18 @@ class RpcConfigSourceClient implements ConfigSourceClient { activeSubscribers.clear(); } exec.shutdown(); - for (JRTConfigRequester requester : requesterPool.values()) { - requester.close(); - } + requester.close(); } @Override public String getActiveSourceConnection() { - if (requesterPool.get(configSourceSet) != null) { - return requesterPool.get(configSourceSet).getConnectionPool().getCurrent().getAddress(); - } else { - return ""; - } + return requester.getConnectionPool().getCurrent().getAddress(); } @Override public List getSourceConnections() { ArrayList ret = new ArrayList<>(); - final JRTConfigRequester jrtConfigRequester = requesterPool.get(configSourceSet); - if (jrtConfigRequester != null) { + if (configSourceSet != null) { ret.addAll(configSourceSet.getSources()); } return ret; diff --git a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriber.java b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriber.java index f8df16cb3d2..d8a8c5ce941 100644 --- a/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriber.java +++ b/config-proxy/src/main/java/com/yahoo/vespa/config/proxy/UpstreamConfigSubscriber.java @@ -1,16 +1,15 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.proxy; -import com.yahoo.config.subscription.ConfigSource; import com.yahoo.config.subscription.ConfigSourceSet; import com.yahoo.config.subscription.impl.GenericConfigHandle; import com.yahoo.config.subscription.impl.GenericConfigSubscriber; import com.yahoo.config.subscription.impl.JRTConfigRequester; import com.yahoo.log.LogLevel; import com.yahoo.vespa.config.ConfigKey; -import com.yahoo.yolean.Exceptions; import com.yahoo.vespa.config.RawConfig; import com.yahoo.vespa.config.TimingValues; +import com.yahoo.yolean.Exceptions; import java.util.Map; import java.util.logging.Logger; @@ -24,26 +23,26 @@ public class UpstreamConfigSubscriber implements Subscriber { private final RawConfig config; private final ConfigSourceClient configSourceClient; - private final ConfigSource configSourceSet; + private final ConfigSourceSet configSourceSet; private final TimingValues timingValues; - private final Map requesterPool; + private final JRTConfigRequester requester; private final MemoryCache memoryCache; private GenericConfigSubscriber subscriber; private GenericConfigHandle handle; - UpstreamConfigSubscriber(RawConfig config, ConfigSourceClient configSourceClient, ConfigSource configSourceSet, - TimingValues timingValues, Map requesterPool, + UpstreamConfigSubscriber(RawConfig config, ConfigSourceClient configSourceClient, ConfigSourceSet configSourceSet, + TimingValues timingValues, JRTConfigRequester requester, MemoryCache memoryCache) { this.config = config; this.configSourceClient = configSourceClient; this.configSourceSet = configSourceSet; this.timingValues = timingValues; - this.requesterPool = requesterPool; + this.requester = requester; this.memoryCache = memoryCache; } void subscribe() { - subscriber = new GenericConfigSubscriber(requesterPool); + subscriber = new GenericConfigSubscriber(Map.of(configSourceSet, requester)); ConfigKey key = config.getKey(); handle = subscriber.subscribe(new ConfigKey<>(key.getName(), key.getConfigId(), key.getNamespace()), config.getDefContent(), configSourceSet, timingValues); -- cgit v1.2.3