Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
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, ConfigChangeCallback callback);
 
    // Remove all subscriptions
    void unsubscribeAll();
 
    // Close all subscriptions and clean up all resources
    void close();
}
 
public class ConfigData {
 
    private long ttl;
    private Map<String, String> data;
 
    public ConfigData(Map<String, String> data, long ttl) {
        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 {
   
    void onChange(String path, ConfigData data);
}
 

...