diff options
author | gjoranv <gv@verizonmedia.com> | 2020-08-28 16:36:38 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2020-08-28 16:36:38 +0200 |
commit | 3a7ae7bfd3087a4f0011e2d6138aa09eee554bc3 (patch) | |
tree | ffc30791d55f9ffa12847992d7b12094fda076b4 /container-di | |
parent | 61e3586ef1f5050038f1bcb72a9a1f4ee6ba44c8 (diff) |
Remove code duplication by letting getConfigs call getConfigsOnce
- This was probably always the intention, and I'm not sure why it
wasn't done earlier.
Diffstat (limited to 'container-di')
-rw-r--r-- | container-di/src/main/java/com/yahoo/container/di/ConfigRetriever.java | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/container-di/src/main/java/com/yahoo/container/di/ConfigRetriever.java b/container-di/src/main/java/com/yahoo/container/di/ConfigRetriever.java index d8350ec2f6b..f892fe410a8 100644 --- a/container-di/src/main/java/com/yahoo/container/di/ConfigRetriever.java +++ b/container-di/src/main/java/com/yahoo/container/di/ConfigRetriever.java @@ -45,36 +45,24 @@ public final class ConfigRetriever { this.componentSubscriber = subscribe.apply(componentSubscriberKeys); } - /** - * Loop forever until we get config - */ public ConfigSnapshot getConfigs(Set<ConfigKey<? extends ConfigInstance>> componentConfigKeys, long leastGeneration, boolean restartOnRedeploy) { + // Loop until we get config. while (true) { - if (!Sets.intersection(componentConfigKeys, bootstrapKeys).isEmpty()) - throw new IllegalArgumentException("Component config keys [" + componentConfigKeys + - "] overlaps with bootstrap config keys [" + bootstrapKeys + "]"); - - log.log(FINE, "getConfigs: " + componentConfigKeys); - Set<ConfigKey<? extends ConfigInstance>> allKeys = new HashSet<>(componentConfigKeys); - allKeys.addAll(bootstrapKeys); - setupComponentSubscriber(allKeys); - - Optional<ConfigSnapshot> maybeSnapshot = getConfigsOptional(leastGeneration, restartOnRedeploy); + Optional<ConfigSnapshot> maybeSnapshot = getConfigsOnce(componentConfigKeys, leastGeneration, restartOnRedeploy); if (maybeSnapshot.isPresent()) { - ConfigSnapshot snapshot = maybeSnapshot.get(); - resetComponentSubscriberIfBootstrap(snapshot); - return snapshot; + var configSnapshot = maybeSnapshot.get(); + resetComponentSubscriberIfBootstrap(configSnapshot); + return configSnapshot; } } } - public ConfigSnapshot getConfigs(Set<ConfigKey<? extends ConfigInstance>> componentConfigKeys, long leastGeneration) { + ConfigSnapshot getConfigs(Set<ConfigKey<? extends ConfigInstance>> componentConfigKeys, long leastGeneration) { return getConfigs(componentConfigKeys, leastGeneration, false); } - // TODO: duplicate code, let getConfigs call this. Optional<ConfigSnapshot> getConfigsOnce(Set<ConfigKey<? extends ConfigInstance>> componentConfigKeys, long leastGeneration, boolean restartOnRedeploy) { @@ -88,9 +76,7 @@ public final class ConfigRetriever { allKeys.addAll(bootstrapKeys); setupComponentSubscriber(allKeys); - Optional<ConfigSnapshot> maybeSnapshot = getConfigsOptional(leastGeneration, restartOnRedeploy); - maybeSnapshot.ifPresent(this::resetComponentSubscriberIfBootstrap); - return maybeSnapshot; + return getConfigsOptional(leastGeneration, restartOnRedeploy); } private Optional<ConfigSnapshot> getConfigsOptional(long leastGeneration, boolean restartOnRedeploy) { |