...
Code Block | ||
---|---|---|
| ||
public interface ConfigProvider extends Configurable, Closeable {
// Configure this class with the initialization parameters
void configure(Map<String, ?> configs);
// Lookup up the data at the given path.
ConfigData get(ConfigContext ctx, String path);
// Lookup up the data with the given keys at the given path.
ConfigData get(ConfigContext ctx, String path, Set<String> keys);
// The ConfigProvider is responsible for making this callback whenever the key changes.
// Some ConfigProviders may want to have a background thread with a configurable update interval.
void subscribe(String key, ConfigurationChangeCallback callback);
// Inverse of subscribe
void unsubscribe(String key);
// Close all subscriptions and clean up all resources
void close();
}
public interface ConfigurationChangeCallback {
void onChange(String key, String value);
}
public interface ConfigContext {
// The name of the client
String name();
// Schedule a reload, possibly for secrets rotation
void scheduleConfigReload(long delayMs);
}
public class ConfigData {
private Map<String, String> metadata;
private Map<String, String> data;
public ConfigData(Map<String, String> metadata, Map<String, String> data) {
this.metadata = metadata;
this.data = data;
}
public Map<String, String> metadata() {
return metadata;
}
public Map<String, String> data() {
return data;
}
} |
...