use of com.netflix.config.WatchedUpdateResult in project archaius by Netflix.
the class ZooKeeperConfigurationSource method start.
/**
* Adds a listener to the pathChildrenCache, initializes the cache, then starts the cache-management background thread
*
* @throws Exception
*/
public void start() throws Exception {
// create the watcher for future configuration updatess
pathChildrenCache.getListenable().addListener(new PathChildrenCacheListener() {
public void childEvent(CuratorFramework aClient, PathChildrenCacheEvent event) throws Exception {
Type eventType = event.getType();
ChildData data = event.getData();
String path = null;
if (data != null) {
path = data.getPath();
// scrub configRootPath out of the key name
String key = removeRootPath(path);
byte[] value = data.getData();
String stringValue = new String(value, charset);
logger.debug("received update to pathName [{}], eventType [{}]", path, eventType);
logger.debug("key [{}], and value [{}]", key, stringValue);
// fire event to all listeners
Map<String, Object> added = null;
Map<String, Object> changed = null;
Map<String, Object> deleted = null;
if (eventType == Type.CHILD_ADDED) {
added = new HashMap<String, Object>(1);
added.put(key, stringValue);
} else if (eventType == Type.CHILD_UPDATED) {
changed = new HashMap<String, Object>(1);
changed.put(key, stringValue);
} else if (eventType == Type.CHILD_REMOVED) {
deleted = new HashMap<String, Object>(1);
deleted.put(key, stringValue);
}
WatchedUpdateResult result = WatchedUpdateResult.createIncremental(added, changed, deleted);
fireEvent(result);
}
}
});
// passing true to trigger an initial rebuild upon starting. (blocking call)
pathChildrenCache.start(true);
}
use of com.netflix.config.WatchedUpdateResult in project archaius by Netflix.
the class ZooKeeperConfigurationSourceTest method setZkProperty.
private static void setZkProperty(String key, String value) throws Exception {
// update the underlying zk property and assert that the new value is picked up
final CountDownLatch updateLatch = new CountDownLatch(1);
zkConfigSource.addUpdateListener(new WatchedUpdateListener() {
public void updateConfiguration(WatchedUpdateResult result) {
updateLatch.countDown();
}
});
zkConfigSource.setZkProperty(key, value);
updateLatch.await();
}
Aggregations