diff options
author | Harald Musum <musum@yahooinc.com> | 2021-09-06 08:32:31 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2021-09-06 08:32:31 +0200 |
commit | a1d3c3e20074c6a3487b1043d4d1be57706f6d80 (patch) | |
tree | ce0fbeeb5f5123cd6aa1b16a4353b725929b3f04 /config | |
parent | e3fb6d00126de2eebdaa5c509eb6106ab871d1f7 (diff) |
Reforman, no functional changes
Diffstat (limited to 'config')
5 files changed, 57 insertions, 42 deletions
diff --git a/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSetSubscription.java b/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSetSubscription.java index d3a1bfb50a9..be71f230934 100644 --- a/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSetSubscription.java +++ b/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSetSubscription.java @@ -1,4 +1,4 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.subscription.impl; import com.yahoo.config.ConfigInstance; @@ -11,6 +11,7 @@ import java.lang.reflect.Constructor; /** * Subscription on a programmatically built set of configs + * * @author Vegard Havdal */ public class ConfigSetSubscription<T extends ConfigInstance> extends ConfigSubscription<T> { @@ -20,11 +21,11 @@ public class ConfigSetSubscription<T extends ConfigInstance> extends ConfigSubsc ConfigSetSubscription(ConfigKey<T> key, ConfigSubscriber subscriber, ConfigSource cset) { super(key, subscriber); - if (!(cset instanceof ConfigSet)) throw new IllegalArgumentException("Source is not a ConfigSet: "+cset); - this.set=(ConfigSet) cset; + if (!(cset instanceof ConfigSet)) throw new IllegalArgumentException("Source is not a ConfigSet: " + cset); + this.set = (ConfigSet) cset; subKey = new ConfigKey<>(configClass, key.getConfigId()); if (!set.contains(subKey)) { - throw new IllegalArgumentException("The given ConfigSet "+set+" does not contain a config for "+subKey); + throw new IllegalArgumentException("The given ConfigSet " + set + " does not contain a config for " + subKey); } setGeneration(0L); } diff --git a/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSubscription.java b/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSubscription.java index 9c535d7114f..3c7a8e794d3 100644 --- a/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSubscription.java +++ b/config/src/main/java/com/yahoo/config/subscription/impl/ConfigSubscription.java @@ -1,10 +1,6 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.subscription.impl; -import java.io.File; -import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Logger; - import com.yahoo.config.ConfigInstance; import com.yahoo.config.subscription.ConfigSet; import com.yahoo.config.subscription.ConfigSource; @@ -18,6 +14,10 @@ import com.yahoo.vespa.config.ConfigKey; import com.yahoo.vespa.config.TimingValues; import com.yahoo.vespa.config.protocol.DefContent; +import java.io.File; +import java.util.concurrent.atomic.AtomicReference; +import java.util.logging.Logger; + /** * Represents one active subscription to one config * @@ -61,9 +61,12 @@ public abstract class ConfigSubscription<T extends ConfigInstance> { this(false, 0L, false, false, null); } - private ConfigState<T> createUnchanged() { return new ConfigState<>(generation, config); } + private ConfigState<T> createUnchanged() { return new ConfigState<>(generation, config); } + public boolean isConfigChanged() { return configChanged; } + public boolean isGenerationChanged() { return generationChanged; } + public Long getGeneration() { return generation; } public boolean applyOnRestart() { return applyOnRestart; } @@ -86,7 +89,7 @@ public abstract class ConfigSubscription<T extends ConfigInstance> { /** * Initializes one subscription * - * @param key a {@link ConfigKey} + * @param key a {@link ConfigKey} * @param subscriber the subscriber for this subscription */ ConfigSubscription(ConfigKey<T> key, ConfigSubscriber subscriber) { @@ -96,11 +99,10 @@ public abstract class ConfigSubscription<T extends ConfigInstance> { this.config.set(new ConfigState<>()); } - /** * Correct type of ConfigSubscription instance based on type of source or form of config id * - * @param key a {@link ConfigKey} + * @param key a {@link ConfigKey} * @param subscriber the subscriber for this subscription * @return a subclass of a ConfigsSubscription */ @@ -113,19 +115,19 @@ public abstract class ConfigSubscription<T extends ConfigInstance> { if (source instanceof JarSource || configId.startsWith("jar:")) return getJarSub(key, subscriber, source); if (source instanceof ConfigSet) return new ConfigSetSubscription<>(key, subscriber, source); if (source instanceof ConfigSourceSet) return new JRTConfigSubscription<>(key, subscriber, source, timingValues); - throw new IllegalArgumentException("Unknown source type: "+source); + throw new IllegalArgumentException("Unknown source type: " + source); } private static <T extends ConfigInstance> JarConfigSubscription<T> getJarSub( ConfigKey<T> key, ConfigSubscriber subscriber, ConfigSource source) { String jarName; - String path="config/"; + String path = "config/"; if (source instanceof JarSource) { JarSource js = (JarSource) source; - jarName=js.getJarFile().getName(); - if (js.getPath()!=null) path=js.getPath(); + jarName = js.getJarFile().getName(); + if (js.getPath() != null) path = js.getPath(); } else { - jarName=key.getConfigId().replace("jar:", "").replaceFirst("\\!/.*", ""); + jarName = key.getConfigId().replace("jar:", "").replaceFirst("\\!/.*", ""); if (key.getConfigId().contains("!/")) path = key.getConfigId().replaceFirst(".*\\!/", ""); } return new JarConfigSubscription<>(key, subscriber, jarName, path); @@ -133,20 +135,27 @@ public abstract class ConfigSubscription<T extends ConfigInstance> { private static <T extends ConfigInstance> ConfigSubscription<T> getFileSub( ConfigKey<T> key, ConfigSubscriber subscriber, ConfigSource source) { - File file = ((source instanceof FileSource))?((FileSource)source).getFile():new File(key.getConfigId().replace("file:", "")); + File file = ((source instanceof FileSource)) + ? ((FileSource) source).getFile() + : new File(key.getConfigId().replace("file:", "")); return new FileConfigSubscription<>(key, subscriber, file); } - private static <T extends ConfigInstance> ConfigSubscription<T> getRawSub( - ConfigKey<T> key, ConfigSubscriber subscriber, ConfigSource source) { - String payload = ((source instanceof RawSource)?((RawSource)source).payload:key.getConfigId().replace("raw:", "")); - return new RawConfigSubscription<>(key, subscriber,payload); + private static <T extends ConfigInstance> ConfigSubscription<T> getRawSub(ConfigKey<T> key, + ConfigSubscriber subscriber, + ConfigSource source) { + String payload = ((source instanceof RawSource) + ? ((RawSource) source).payload + : key.getConfigId().replace("raw:", "")); + return new RawConfigSubscription<>(key, subscriber, payload); } - private static <T extends ConfigInstance> ConfigSubscription<T> getDirFileSub(ConfigKey<T> key, ConfigSubscriber subscriber, ConfigSource source) { + private static <T extends ConfigInstance> ConfigSubscription<T> getDirFileSub(ConfigKey<T> key, + ConfigSubscriber subscriber, + ConfigSource source) { String dir = key.getConfigId().replace("dir:", ""); if (source instanceof DirSource) { - dir = ((DirSource)source).getDir().toString(); + dir = ((DirSource) source).getDir().toString(); } if (!dir.endsWith(File.separator)) dir = dir + File.separator; String name = getConfigFilename(key); @@ -174,7 +183,7 @@ public abstract class ConfigSubscription<T extends ConfigInstance> { */ public boolean isConfigChangedAndReset(Long requiredGen) { ConfigState<T> prev = config.get(); - while ( prev.getGeneration().equals(requiredGen) && !config.compareAndSet(prev, prev.createUnchanged())) { + while (prev.getGeneration().equals(requiredGen) && !config.compareAndSet(prev, prev.createUnchanged())) { prev = config.get(); } // A false positive is a lot better than a false negative @@ -185,7 +194,9 @@ public abstract class ConfigSubscription<T extends ConfigInstance> { this.config.set(new ConfigState<>(true, generation, applyOnRestart, true, config)); } - /** Used by {@link FileConfigSubscription} and {@link ConfigSetSubscription} */ + /** + * Used by {@link FileConfigSubscription} and {@link ConfigSetSubscription} + */ protected void setConfigIncGen(T config) { ConfigState<T> prev = this.config.get(); this.config.set(new ConfigState<>(true, prev.getGeneration() + 1, prev.applyOnRestart(), true, config)); @@ -211,13 +222,13 @@ public abstract class ConfigSubscription<T extends ConfigInstance> { * * @return the ConfigInstance (the config) of this subscription */ - public ConfigState<T> getConfigState() { return config.get(); } /** * The class of the subscription's desired {@link ConfigInstance} + * * @return the config class */ public Class<T> getConfigClass() { @@ -251,7 +262,7 @@ public abstract class ConfigSubscription<T extends ConfigInstance> { * * @param timeout in milliseconds * @return false if timed out, true if generation or config or {@link #exception} changed. If true, the {@link #config} field will be set also. - * has changed + * has changed */ public abstract boolean nextConfig(long timeout); @@ -311,6 +322,7 @@ public abstract class ConfigSubscription<T extends ConfigInstance> { /** * Force this into the given generation, used in testing + * * @param generation a config generation */ public void reload(long generation) { diff --git a/config/src/main/java/com/yahoo/config/subscription/impl/FileConfigSubscription.java b/config/src/main/java/com/yahoo/config/subscription/impl/FileConfigSubscription.java index ce375f9fdbf..3282bc81e55 100644 --- a/config/src/main/java/com/yahoo/config/subscription/impl/FileConfigSubscription.java +++ b/config/src/main/java/com/yahoo/config/subscription/impl/FileConfigSubscription.java @@ -1,4 +1,4 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.subscription.impl; import com.yahoo.config.ConfigInstance; @@ -29,14 +29,14 @@ public class FileConfigSubscription<T extends ConfigInstance> extends ConfigSubs FileConfigSubscription(ConfigKey<T> key, ConfigSubscriber subscriber, File f) { super(key, subscriber); setGeneration(0L); - file=f; + file = f; if (!file.exists() && !file.isFile()) - throw new IllegalArgumentException("Not a file: "+file); + throw new IllegalArgumentException("Not a file: " + file); } @Override public boolean nextConfig(long timeout) { - if (!file.exists() && !file.isFile()) throw new IllegalArgumentException("Not a file: "+file); + if (!file.exists() && !file.isFile()) throw new IllegalArgumentException("Not a file: " + file); if (checkReloaded()) { log.log(FINE, () -> "User forced config reload at " + System.currentTimeMillis()); // User forced reload @@ -46,7 +46,7 @@ public class FileConfigSubscription<T extends ConfigInstance> extends ConfigSubs log.log(FINE, () -> "Config: " + configState.getConfig().toString()); return true; } - if (file.lastModified()!=ts) { + if (file.lastModified() != ts) { setConfigIncGen(updateConfig()); return true; } @@ -60,7 +60,7 @@ public class FileConfigSubscription<T extends ConfigInstance> extends ConfigSubs } private T updateConfig() { - ts=file.lastModified(); + ts = file.lastModified(); try { ConfigPayload payload = new CfgConfigPayloadBuilder().deserialize(Arrays.asList(IOUtils.readFile(file).split("\n"))); return payload.toInstance(configClass, key.getConfigId()); diff --git a/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java b/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java index d3562a47ea1..853bc4dfc00 100644 --- a/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java +++ b/config/src/main/java/com/yahoo/config/subscription/impl/JRTConfigRequester.java @@ -68,7 +68,9 @@ public class JRTConfigRequester implements RequestWaiter { this.timingValues = timingValues; } - /** Only for testing */ + /** + * Only for testing + */ public JRTConfigRequester(ConnectionPool connectionPool, TimingValues timingValues) { this(null, new ScheduledThreadPoolExecutor(1), connectionPool, timingValues); } @@ -90,12 +92,12 @@ public class JRTConfigRequester implements RequestWaiter { private <T extends ConfigInstance> void doRequest(JRTConfigSubscription<T> sub, JRTClientConfigRequest req) { Connection connection = connectionPool.getCurrent(); req.getRequest().setContext(new RequestContext(sub, req, connection)); - if ( ! req.validateParameters()) throw new ConfigurationRuntimeException("Error in parameters for config request: " + req); + if (!req.validateParameters()) throw new ConfigurationRuntimeException("Error in parameters for config request: " + req); double jrtClientTimeout = getClientTimeout(req); log.log(FINE, () -> "Requesting config for " + sub + " on connection " + connection - + " with client timeout " + jrtClientTimeout + - (log.isLoggable(FINEST) ? (",defcontent=" + req.getDefContent().asString()) : "")); + + " with client timeout " + jrtClientTimeout + + (log.isLoggable(FINEST) ? (",defcontent=" + req.getDefContent().asString()) : "")); connection.invokeAsync(req.getRequest(), jrtClientTimeout, this); } @@ -177,7 +179,7 @@ public class JRTConfigRequester implements RequestWaiter { boolean fatalFailures, TimingValues timingValues, boolean configured) { - long delay = (configured ? timingValues.getConfiguredErrorDelay(): timingValues.getUnconfiguredDelay()); + long delay = configured ? timingValues.getConfiguredErrorDelay() : timingValues.getUnconfiguredDelay(); switch (errorType) { case TRANSIENT: @@ -199,7 +201,7 @@ public class JRTConfigRequester implements RequestWaiter { Connection connection) { fatalFailures = false; log.log(INFO, "Connection to " + connection.getAddress() + - " failed or timed out, clients will keep existing config, will keep trying."); + " failed or timed out, clients will keep existing config, will keep trying."); scheduleNextRequest(jrtReq, sub, delay, calculateErrorTimeout()); } diff --git a/config/src/main/java/com/yahoo/vespa/config/RawConfig.java b/config/src/main/java/com/yahoo/vespa/config/RawConfig.java index 1c28d4c5e05..366387f46af 100755 --- a/config/src/main/java/com/yahoo/vespa/config/RawConfig.java +++ b/config/src/main/java/com/yahoo/vespa/config/RawConfig.java @@ -140,7 +140,7 @@ public class RawConfig extends ConfigInstance { * @return true if this config is equal to the config in the given request. */ public boolean hasEqualConfig(JRTServerConfigRequest req) { - return (getConfigMd5().equals(req.getRequestConfigMd5())); + return getConfigMd5().equals(req.getRequestConfigMd5()); } /** |