private void loggingFallback(FallbackKey fallbackKey, ConfigOption<?> configOption) { if (fallbackKey.isDeprecated()) { LOG.warn("Config uses deprecated configuration key '{}' instead of proper key '{}'", fallbackKey.getKey(), configOption.key()); } else { LOG.info("Config uses fallback configuration key '{}' instead of key '{}'", fallbackKey.getKey(), configOption.key()); } }
/** * Removes given config option from the configuration. * * @param configOption config option to remove * @param <T> Type of the config option * @return true is config has been removed, false otherwise */ public <T> boolean removeConfig(ConfigOption<T> configOption){ synchronized (this.confData){ // try the current key Object oldValue = this.confData.remove(configOption.key()); if (oldValue == null){ for (FallbackKey fallbackKey : configOption.fallbackKeys()){ oldValue = this.confData.remove(fallbackKey.getKey()); if (oldValue != null){ loggingFallback(fallbackKey, configOption); return true; } } return false; } return true; } }
private static <T> ConfigOption<T> prefixOption(ConfigOption<T> option, String prefix) { String key = prefix + option.key(); List<FallbackKey> deprecatedKeys; if (option.hasFallbackKeys()) { deprecatedKeys = new ArrayList<>(); for (FallbackKey dk : option.fallbackKeys()) { deprecatedKeys.add(createDeprecatedKey(prefix + dk.getKey())); } } else { deprecatedKeys = Collections.emptyList(); } FallbackKey[] deprecated = deprecatedKeys.toArray(new FallbackKey[0]); return new ConfigOption<>(key, option.description(), option.defaultValue(), deprecated); } }
/** * Checks whether there is an entry for the given config option. * * @param configOption The configuration option * * @return <tt>true</tt> if a valid (current or deprecated) key of the config option is stored, * <tt>false</tt> otherwise */ @PublicEvolving public boolean contains(ConfigOption<?> configOption) { synchronized (this.confData){ // first try the current key if (this.confData.containsKey(configOption.key())) { return true; } else if (configOption.hasFallbackKeys()) { // try the fallback keys for (FallbackKey fallbackKey : configOption.fallbackKeys()) { if (this.confData.containsKey(fallbackKey.getKey())) { loggingFallback(fallbackKey, configOption); return true; } } } return false; } }
private Object getRawValueFromOption(ConfigOption<?> configOption) { // first try the current key Object o = getRawValue(configOption.key()); if (o != null) { // found a value for the current proper key return o; } else if (configOption.hasFallbackKeys()) { // try the deprecated keys for (FallbackKey fallbackKey : configOption.fallbackKeys()) { Object oo = getRawValue(fallbackKey.getKey()); if (oo != null) { loggingFallback(fallbackKey, configOption); return oo; } } } return null; }