...
Code Block | ||
---|---|---|
| ||
public interface ConfigProvider extends Configurable, Closeable { // Configure this class with the initialization parameters void configure(Map<String, ?> configs); // Look up the data at the given path. ConfigData get(String path); // Look up the data with the given keys at the given path. ConfigData get(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 path, Set<String> keys, ConfigChangeCallback callback); // Inverse of subscribe void unsubscribe(String path, Set<String> key); // Close all subscriptions and clean up all resources void close(); } public class ConfigData { private long ttl; private Map<String, String> data; public ConfigData(long ttl, Map<String, String> data) { this.ttl = ttl; this.data = data; } public ConfigData(Map<String, String> data) { this(Long.MAX_VALUE, data); } public long ttl() { return ttl; } public Map<String, String> data() { return data; } } public interface ConfigChangeCallback { // A delayMs of 0 indicates an immediate change; a positive delayMs indicates // that a future change is anticipated (such as a lease duration) void onChange(String path, Map<String, String> values, int delayMs); } |
Also a helper class will be added that can provide variable substitutions using ConfigProvider
instances. Here is an example skeleton.
...