未验证 提交 039f6108 编写于 作者: E elandau 提交者: GitHub

Merge pull request #415 from elandau/feature/getIfSet

config: Method to get config if it's set without reading properties
......@@ -18,6 +18,7 @@
package com.netflix.client.config;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;
/**
......@@ -82,6 +83,9 @@ public interface IClientConfig {
@Deprecated
Object getProperty(IClientConfigKey key, Object defaultVal);
/**
* @deprecated use {@link #getIfSet(IClientConfigKey)}
*/
@Deprecated
boolean containsProperty(IClientConfigKey key);
......@@ -130,6 +134,16 @@ public interface IClientConfig {
return get(key, key.defaultValue());
}
/**
* Return a typed property if and only if it was explicitly set, skipping configuration loading.
* @param key
* @param <T>
* @return
*/
default <T> Optional<T> getIfSet(IClientConfigKey<T> key) {
return Optional.ofNullable(get(key));
}
/**
* @return Return a global dynamic property not scoped to the specific client. The property will be looked up as is using the
* key without any client name or namespace prefix
......
......@@ -240,7 +240,7 @@ public abstract class ReloadableClientConfig implements IClientConfig {
return value;
}
value = resolveDefaultProperty(key);
value = getIfSet(key);
if (value.isPresent()) {
return value;
}
......@@ -248,7 +248,8 @@ public abstract class ReloadableClientConfig implements IClientConfig {
return Optional.empty();
}
protected <T> Optional<T> resolveDefaultProperty(IClientConfigKey<T> key) {
@Override
public <T> Optional<T> getIfSet(IClientConfigKey<T> key) {
return Optional.ofNullable(defaultProperties.get(key.key()))
.map(value -> {
final Class<T> type = key.type();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册