public class ZooKeeperConfigurationSource
extends java.lang.Object
implements com.netflix.config.WatchedConfigurationSource, java.io.Closeable
WatchedConfigurationSource for ZooKeeper using Curator.
This implementation requires the path to the ZK root parent node that contains
the hierarchy of configuration properties.
An example is /<my-app>/config
Properties are direct ZK child nodes of the root parent ZK node.
An example ZK child property node is /<my-app>/config/com.fluxcapacitor.my.property
The value is stored in the ZK child property node and can be updated at any time.
All servers will receive a ZK Watcher callback and automatically update their value
similar to other dynamic configuration sources (ie. DynamoDB, etc.)| Constructor and Description |
|---|
ZooKeeperConfigurationSource(org.apache.curator.framework.CuratorFramework client,
java.lang.String configRootPath)
Creates the pathChildrenCache using the CuratorFramework client and ZK root path node for the config
|
| Modifier and Type | Method and Description |
|---|---|
void |
addUpdateListener(com.netflix.config.WatchedUpdateListener l) |
void |
close() |
protected void |
fireEvent(com.netflix.config.WatchedUpdateResult result) |
java.util.Map<java.lang.String,java.lang.Object> |
getCurrentData() |
void |
removeUpdateListener(com.netflix.config.WatchedUpdateListener l) |
void |
start()
Adds a listener to the pathChildrenCache, initializes the cache, then starts the cache-management background thread
|
public ZooKeeperConfigurationSource(org.apache.curator.framework.CuratorFramework client,
java.lang.String configRootPath)
client - configRootPath - to ZK root parent node for the rest of the configuration properties (ie. /<my-app>/config)public void start()
throws java.lang.Exception
java.lang.Exceptionpublic java.util.Map<java.lang.String,java.lang.Object> getCurrentData()
throws java.lang.Exception
getCurrentData in interface com.netflix.config.WatchedConfigurationSourcejava.lang.Exceptionpublic void addUpdateListener(com.netflix.config.WatchedUpdateListener l)
addUpdateListener in interface com.netflix.config.WatchedConfigurationSourcepublic void removeUpdateListener(com.netflix.config.WatchedUpdateListener l)
removeUpdateListener in interface com.netflix.config.WatchedConfigurationSourceprotected void fireEvent(com.netflix.config.WatchedUpdateResult result)
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseable