Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Netflix/ribbon into feature/scope…
Browse files Browse the repository at this point in the history
…d_property

# Conflicts:
#	ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java
  • Loading branch information
elandau committed May 17, 2019
2 parents 38dce08 + f0b74aa commit 4e6f0cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.netflix.client.config;

import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;

/**
Expand Down Expand Up @@ -82,6 +83,9 @@ default void forEach(BiConsumer<IClientConfigKey<?>, Object> consumer) {
@Deprecated
Object getProperty(IClientConfigKey key, Object defaultVal);

/**
* @deprecated use {@link #getIfSet(IClientConfigKey)}
*/
@Deprecated
boolean containsProperty(IClientConfigKey key);

Expand Down Expand Up @@ -130,6 +134,16 @@ default <T> T getOrDefault(IClientConfigKey<T> key) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private <T> Optional<T> resolveFinalProperty(IClientConfigKey<T> key) {
return value;
}

return resolveDefaultProperty(key);
return getIfSet(key);
}

private <T> Optional<T> resolverScopedProperty(IClientConfigKey<T> key) {
Expand All @@ -250,10 +250,11 @@ private <T> Optional<T> resolverScopedProperty(IClientConfigKey<T> key) {
return value;
}

return resolveDefaultProperty(key);
return getIfSet(key);
}

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();
Expand Down

0 comments on commit 4e6f0cf

Please sign in to comment.