use of org.apache.curator.framework.recipes.cache.TreeCache in project elastic-job by dangdangdotcom.
the class ZookeeperRegistryCenter method get.
@Override
public String get(final String key) {
TreeCache cache = findTreeCache(key);
if (null == cache) {
return getDirectly(key);
}
ChildData resultInCache = cache.getCurrentData(key);
if (null != resultInCache) {
return null == resultInCache.getData() ? null : new String(resultInCache.getData(), Charsets.UTF_8);
}
return getDirectly(key);
}
use of org.apache.curator.framework.recipes.cache.TreeCache in project elastic-job by dangdangdotcom.
the class MonitorService method dumpDirectly.
private void dumpDirectly(final String path, final List<String> result) {
for (String each : regCenter.getChildrenKeys(path)) {
String zkPath = path + "/" + each;
String zkValue = regCenter.get(zkPath);
if (null == zkValue) {
zkValue = "";
}
TreeCache treeCache = (TreeCache) regCenter.getRawCache("/" + jobName);
ChildData treeCacheData = treeCache.getCurrentData(zkPath);
String treeCachePath = null == treeCacheData ? "" : treeCacheData.getPath();
String treeCacheValue = null == treeCacheData ? "" : new String(treeCacheData.getData());
if (zkValue.equals(treeCacheValue) && zkPath.equals(treeCachePath)) {
result.add(Joiner.on(" | ").join(zkPath, zkValue));
} else {
result.add(Joiner.on(" | ").join(zkPath, zkValue, treeCachePath, treeCacheValue));
}
dumpDirectly(zkPath, result);
}
}
use of org.apache.curator.framework.recipes.cache.TreeCache in project elastic-job by dangdangdotcom.
the class JobNodeStorage method addDataListener.
/**
* 注册数据监听器.
*
* @param listener 数据监听器
*/
public void addDataListener(final TreeCacheListener listener) {
TreeCache cache = (TreeCache) regCenter.getRawCache("/" + jobName);
cache.getListenable().addListener(listener);
}
use of org.apache.curator.framework.recipes.cache.TreeCache in project elastic-job by dangdangdotcom.
the class CloudJobConfigurationListener method getCache.
private TreeCache getCache() {
TreeCache result = (TreeCache) regCenter.getRawCache(CloudJobConfigurationNode.ROOT);
if (null != result) {
return result;
}
regCenter.addCacheData(CloudJobConfigurationNode.ROOT);
return (TreeCache) regCenter.getRawCache(CloudJobConfigurationNode.ROOT);
}
use of org.apache.curator.framework.recipes.cache.TreeCache in project elastic-job by dangdangdotcom.
the class JobNodeStorageTest method assertAddDataListener.
@Test
public void assertAddDataListener() {
TreeCache treeCache = mock(TreeCache.class);
@SuppressWarnings("unchecked") Listenable<TreeCacheListener> listeners = mock(Listenable.class);
TreeCacheListener listener = mock(TreeCacheListener.class);
when(treeCache.getListenable()).thenReturn(listeners);
when(regCenter.getRawCache("/test_job")).thenReturn(treeCache);
jobNodeStorage.addDataListener(listener);
verify(listeners).addListener(listener);
}
Aggregations