Client configuration APIs and shared utilities for Netflix's Ribbon IPC library, providing core interfaces for load balancing, fault tolerance, and service discovery capabilities in cloud environments.
—
Comprehensive configuration system providing type-safe property access, dynamic reloading, and hierarchical property resolution for client applications. The system supports runtime configuration changes and provides typed access to all configuration parameters.
Main interface defining client configuration used by various APIs.
/**
* Main interface defining client configuration used by various APIs
*/
public interface IClientConfig {
/**
* Gets client name
* @return the name of this client configuration
*/
String getClientName();
/**
* Gets namespace
* @return the namespace for this configuration
*/
String getNameSpace();
/**
* Sets namespace
* @param nameSpace the namespace to set
*/
void setNameSpace(String nameSpace);
/**
* Loads properties for client
* @param clientName the client name to load properties for
*/
void loadProperties(String clientName);
/**
* Loads default values
*/
void loadDefaultValues();
/**
* Gets all properties
* @return map of all configuration properties
* @deprecated Use typed access methods instead
*/
@Deprecated
Map<String, Object> getProperties();
/**
* Gets typed property value
* @param key the configuration key
* @return the value for the key, or default if not set
*/
<T> T get(IClientConfigKey<T> key);
/**
* Gets value or default
* @param key the configuration key
* @return the value for the key, or the key's default value
*/
<T> T getOrDefault(IClientConfigKey<T> key);
/**
* Gets value if explicitly set
* @param key the configuration key
* @return Optional containing the value if explicitly set, empty otherwise
*/
<T> Optional<T> getIfSet(IClientConfigKey<T> key);
/**
* Gets value with fallback
* @param key the configuration key
* @param defaultValue fallback value if key is not set
* @return the value for the key, or defaultValue if not set
*/
<T> T get(IClientConfigKey<T> key, T defaultValue);
/**
* Sets typed property
* @param key the configuration key
* @param value the value to set
* @return this configuration instance for chaining
*/
<T> IClientConfig set(IClientConfigKey<T> key, T value);
/**
* Gets global dynamic property
* @param key the configuration key
* @return Property that reflects global configuration changes
*/
<T> Property<T> getGlobalProperty(IClientConfigKey<T> key);
/**
* Gets scoped dynamic property
* @param key the configuration key
* @return Property that reflects client-scoped configuration changes
*/
<T> Property<T> getDynamicProperty(IClientConfigKey<T> key);
/**
* Resolves VIP addresses
* @return resolved VIP addresses
*/
String resolveDeploymentContextbasedVipAddresses();
}Defines common client configuration keys with type safety.
/**
* Defines common client configuration keys with type safety
*/
public abstract class CommonClientConfigKey<T> implements IClientConfigKey<T> {
// Namespace constant
public static final String DEFAULT_NAME_SPACE = "ribbon";
// Core application properties
public static final IClientConfigKey<String> AppName;
public static final IClientConfigKey<String> Version;
public static final IClientConfigKey<Integer> Port;
public static final IClientConfigKey<Integer> SecurePort;
public static final IClientConfigKey<String> VipAddress;
public static final IClientConfigKey<Boolean> ForceClientPortConfiguration;
// Connection and timeout settings
public static final IClientConfigKey<Integer> ConnectTimeout;
public static final IClientConfigKey<Integer> ReadTimeout;
public static final IClientConfigKey<Integer> MaxAutoRetries;
public static final IClientConfigKey<Integer> MaxAutoRetriesNextServer;
public static final IClientConfigKey<Boolean> OkToRetryOnAllOperations;
public static final IClientConfigKey<Boolean> RequestSpecificRetryOn;
// Connection pool and HTTP settings
public static final IClientConfigKey<Integer> MaxConnectionsPerHost;
public static final IClientConfigKey<Integer> MaxTotalConnections;
public static final IClientConfigKey<Boolean> EnableConnectionPool;
public static final IClientConfigKey<Integer> PoolMaxThreads;
public static final IClientConfigKey<Integer> PoolMinThreads;
public static final IClientConfigKey<Integer> PoolKeepAliveTime;
public static final IClientConfigKey<String> PoolKeepAliveTimeUnits;
// Security and SSL
public static final IClientConfigKey<Boolean> IsSecure;
public static final IClientConfigKey<String> KeyStore;
public static final IClientConfigKey<String> KeyStorePassword;
public static final IClientConfigKey<String> TrustStore;
public static final IClientConfigKey<String> TrustStorePassword;
// Load balancer and server list properties
public static final IClientConfigKey<String> NFLoadBalancerClassName;
public static final IClientConfigKey<String> NFLoadBalancerRuleClassName;
public static final IClientConfigKey<String> NFLoadBalancerPingClassName;
public static final IClientConfigKey<String> ServerListClassName;
public static final IClientConfigKey<String> ServerListUpdaterClassName;
// Circuit breaker and health check settings
public static final IClientConfigKey<Integer> CircuitBreakerRequestVolumeThreshold;
public static final IClientConfigKey<Integer> CircuitBreakerSleepWindowInMilliseconds;
public static final IClientConfigKey<Integer> CircuitBreakerErrorThresholdPercentage;
public static final IClientConfigKey<Boolean> CircuitBreakerForceOpen;
public static final IClientConfigKey<Boolean> CircuitBreakerForceClosed;
// Prime connections and performance
public static final IClientConfigKey<Boolean> EnablePrimeConnections;
public static final IClientConfigKey<String> PrimeConnectionsClassName;
public static final IClientConfigKey<Integer> MaxRetriesPerServerPrimeConnection;
public static final IClientConfigKey<Integer> MaxTotalTimeToPrimeConnections;
public static final IClientConfigKey<Float> MinPrimeConnectionsRatio;
public static final IClientConfigKey<String> PrimeConnectionsURI;
// Note: CommonClientConfigKey defines 75+ configuration keys in total.
// The above shows the most commonly used keys. Use keys() method to get all available keys.
/**
* Protected constructor for creating configuration keys
* @param configKey the string key
*/
protected CommonClientConfigKey(String configKey);
/**
* Protected constructor with default value
* @param configKey the string key
* @param defaultValue the default value for this key
*/
protected CommonClientConfigKey(String configKey, T defaultValue);
/**
* Returns the key type
* @return the Class representing the value type
*/
public Class<T> type();
/**
* Returns the key string
* @return the string representation of this key
*/
public String key();
/**
* Returns the default value
* @return the default value for this key
*/
public T defaultValue();
/**
* Returns all defined keys
* @return Set of all configuration keys
*/
public static Set<IClientConfigKey> keys();
/**
* Returns key by name
* @param name the key name
* @return the configuration key with the given name
*/
public static IClientConfigKey valueOf(String name);
}Dynamic configuration property interface with change notifications.
/**
* Ribbon-specific encapsulation of a dynamic configuration property
*/
public interface Property<T> {
/**
* Registers change listener
* @param consumer function to call when property value changes
*/
void onChange(Consumer<T> consumer);
/**
* Gets current value
* @return Optional containing current value, or empty if not set
*/
Optional<T> get();
/**
* Gets current value or default
* @return current value, or default value if not set
*/
T getOrDefault();
/**
* Creates fallback property
* @param fallback property to use if this property is not set
* @return new Property that falls back to the given property
*/
default Property<T> fallbackWith(Property<T> fallback);
/**
* Creates static property
* @param value the static value
* @return Property that always returns the given value
*/
static <T> Property<T> of(T value);
}Base implementation supporting runtime property reloading with optimization.
/**
* Base implementation supporting runtime property reloading with optimization
*/
public abstract class ReloadableClientConfig implements IClientConfig {
/**
* Protected constructor
* @param resolver the property resolver to use
*/
protected ReloadableClientConfig(PropertyResolver resolver);
/**
* Refreshes all properties from underlying storage
*/
public final void reload();
/**
* Gets client name
* @return the client name
*/
public final String getClientName();
/**
* Gets namespace
* @return the namespace
*/
public String getNameSpace();
/**
* Sets namespace
* @param nameSpace the namespace to set
*/
public final void setNameSpace(String nameSpace);
/**
* Loads properties for client
* @param clientName the client name
*/
public void loadProperties(String clientName);
/**
* Iterates all properties
* @param consumer function to call for each property
*/
public void forEach(BiConsumer<IClientConfigKey<?>, Object> consumer);
/**
* Gets prefix-mapped property
* @param key the configuration key
* @return Property mapped with client-specific prefix
*/
public <T> Property<T> getPrefixMappedProperty(IClientConfigKey<T> key);
/**
* Applies configuration override
* @param override configuration to override with
* @return this configuration with overrides applied
*/
public IClientConfig applyOverride(IClientConfig override);
/**
* Gets number of property refreshes
* @return count of how many times properties have been refreshed
*/
public long getRefreshCount();
}Factory interface for creating client configurations.
/**
* Factory interface for creating client configurations
*/
public interface ClientConfigFactory {
/**
* Default factory instance
*/
ClientConfigFactory DEFAULT = findDefaultConfigFactory();
/**
* Creates a new client configuration
* @return new IClientConfig instance
*/
IClientConfig newConfig();
/**
* Returns factory priority (default: 0)
* @return priority value for factory selection
*/
default int getPriority();
/**
* Finds the default configuration factory
* @return the default ClientConfigFactory implementation
*/
static ClientConfigFactory findDefaultConfigFactory();
}Usage Examples:
import com.netflix.client.config.*;
// Create and configure a client
IClientConfig config = ClientConfigFactory.DEFAULT.newConfig();
config.loadProperties("my-service-client");
// Set connection timeouts
config.set(CommonClientConfigKey.ConnectTimeout, 5000); // 5 seconds
config.set(CommonClientConfigKey.ReadTimeout, 10000); // 10 seconds
// Configure retry behavior
config.set(CommonClientConfigKey.MaxAutoRetries, 3);
config.set(CommonClientConfigKey.MaxAutoRetriesNextServer, 1);
config.set(CommonClientConfigKey.OkToRetryOnAllOperations, false);
// Configure circuit breaker
config.set(CommonClientConfigKey.CircuitBreakerRequestVolumeThreshold, 20);
config.set(CommonClientConfigKey.CircuitBreakerSleepWindowInMilliseconds, 5000);
config.set(CommonClientConfigKey.CircuitBreakerErrorThresholdPercentage, 50);
// Use dynamic properties for runtime configuration changes
Property<Integer> timeoutProperty = config.getDynamicProperty(CommonClientConfigKey.ConnectTimeout);
timeoutProperty.onChange(newTimeout -> {
System.out.println("Connect timeout changed to: " + newTimeout + "ms");
});
// Get values with fallbacks
int connectTimeout = config.getOrDefault(CommonClientConfigKey.ConnectTimeout);
Optional<String> appName = config.getIfSet(CommonClientConfigKey.AppName);
// Client-specific configuration with namespace
config.setNameSpace("my-service");
config.loadProperties("user-service-client");// Custom configuration key
public class MyConfigKey extends CommonClientConfigKey<String> {
public static final IClientConfigKey<String> CustomProperty =
new MyConfigKey("my.custom.property", "default-value");
private MyConfigKey(String key, String defaultValue) {
super(key, defaultValue);
}
}
// Using fallback properties
Property<Integer> primary = config.getDynamicProperty(CommonClientConfigKey.ConnectTimeout);
Property<Integer> fallback = Property.of(5000); // static fallback
Property<Integer> combined = primary.fallbackWith(fallback);
// Configuration inheritance and overrides
IClientConfig baseConfig = ClientConfigFactory.DEFAULT.newConfig();
baseConfig.set(CommonClientConfigKey.ConnectTimeout, 5000);
IClientConfig serviceSpecificConfig = ClientConfigFactory.DEFAULT.newConfig();
serviceSpecificConfig.set(CommonClientConfigKey.ReadTimeout, 15000);
IClientConfig finalConfig = baseConfig.applyOverride(serviceSpecificConfig);Install with Tessl CLI
npx tessl i tessl/maven-com-netflix-ribbon--ribbon-core