本文整理汇总了Java中org.apache.curator.framework.recipes.cache.TreeCache.getCurrentData方法的典型用法代码示例。如果您正苦于以下问题:Java TreeCache.getCurrentData方法的具体用法?Java TreeCache.getCurrentData怎么用?Java TreeCache.getCurrentData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.framework.recipes.cache.TreeCache
的用法示例。
在下文中一共展示了TreeCache.getCurrentData方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getData
import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
public static Object getData(TreeCache treeCache, String pPath, String encode) throws IOException, KeeperException, InterruptedException {
log.debug("pPath=" + pPath);
ChildData cdata = treeCache.getCurrentData(pPath);
log.debug("cdata=" + cdata);
byte[] data = cdata.getData();
log.debug("data=" + data);
String datas = new String(data, encode);
Object ret = datas;
if (datas != null && !datas.trim().isEmpty()) {
datas = datas.trim();
if (datas.startsWith("{") && datas.endsWith("}")) {
Map<String, Object> map = JsonUtil.toJavaBean(datas, Map.class);
ret = map;
} else if (datas.startsWith("[") && datas.endsWith("]")) {
Collection<Object> ocoll = JsonUtil.toJavaBean(datas, Collection.class);
ret = ocoll;
}
}
log.debug("ret=" + ret);
return ret;
}
示例2: dumpDirectly
import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
private void dumpDirectly(final String path, final List<String> result) {
for (String each : coordinatorRegistryCenter.getChildrenKeys(path)) {
String zkPath = path + "/" + each;
String zkValue = coordinatorRegistryCenter.get(zkPath);
if (null == zkValue) {
zkValue = "";
}
TreeCache treeCache = (TreeCache) coordinatorRegistryCenter.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);
}
}
示例3: dumpDirectly
import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
private void dumpDirectly(final String path, final List<String> result) {
for (String each : coordinatorRegistryCenter.getElasticConfigRegistryCenter().getChildrenKeys(path)) {
String zkPath = path + "/" + each;
String zkValue = coordinatorRegistryCenter.getElasticConfigRegistryCenter().get(zkPath);
if (null == zkValue) {
zkValue = "";
}
TreeCache treeCache = (TreeCache) coordinatorRegistryCenter.getElasticConfigRegistryCenter().getRawCache(
"/" + configProfile.getNode());
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);
}
}
示例4: get
import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@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(), StandardCharsets.UTF_8);
}
return getDirectly(key);
}
示例5: get
import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@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);
}
示例6: get
import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@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(), Charset.forName("UTF-8"));
}
return getDirectly(key);
}
示例7: get
import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@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(),
Charset.forName("UTF-8"));
}
return getDirectly(key);
}
示例8: test_tree_cache
import org.apache.curator.framework.recipes.cache.TreeCache; //导入方法依赖的package包/类
@Test
public void test_tree_cache() throws Exception {
String rootPath = "/namespace-test";
CuratorFramework zk = curator.usingNamespace("namespace-test");
String groupPath = "/group-1";
String s = zk.create().forPath(groupPath,"group-1-data".getBytes());
Assert.assertEquals(groupPath, s);
Stat stat = zk.checkExists().forPath("/group-1");
Assert.assertNotNull(stat);
stat = zk.checkExists().forPath(rootPath);
Assert.assertNull(stat);
final TreeCacheEvent.Type[] saveEventType = new TreeCacheEvent.Type[1];
final long[] saveTime = new long[1];
TreeCache treeCache = new TreeCache(curator, rootPath);
treeCache.start();
ChildData childData = treeCache.getCurrentData("/namespace-test/group-1");
treeCache.getListenable().addListener(new TreeCacheListener() {
@Override
public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
logger.info("event type={}", event.getType());
switch (event.getType()) {
case NODE_ADDED:
saveEventType[0] = TreeCacheEvent.Type.NODE_ADDED;
saveTime[0] = System.currentTimeMillis();
logger.info("child[path={}, date={}] added", event.getData().getPath(), new String(event.getData().getData()));
break;
case NODE_UPDATED:
saveEventType[0] = TreeCacheEvent.Type.NODE_UPDATED;
saveTime[0] = System.currentTimeMillis();
logger.info("child[path={}, date={}] updated", event.getData().getPath(), new String(event.getData().getData()));
break;
case NODE_REMOVED:
saveEventType[0] = TreeCacheEvent.Type.NODE_REMOVED;
saveTime[0] = System.currentTimeMillis();
logger.info("child[path={}, date={}] updated", event.getData().getPath(), new String(event.getData().getData()));
break;
case CONNECTION_SUSPENDED:
break;
case CONNECTION_RECONNECTED:
break;
case CONNECTION_LOST:
break;
case INITIALIZED:
break;
}
}
});
String hostPath = groupPath + "/localhost:8001";
zk.create().forPath(hostPath);
long wtStart = System.currentTimeMillis();
Thread.sleep(300);
// use 15 ms
// System.out.println("listener wait time="+(saveTime[0] - wtStart));
Assert.assertEquals(TreeCacheEvent.Type.NODE_ADDED, saveEventType[0]);
// System.out.println(new String(zk.getData().forPath(hostPath)));
// create three node
String threePath = groupPath + "/hosts/localhost:8001";
zk.create().creatingParentsIfNeeded().forPath(threePath);
zk.setData().forPath(threePath, "{tree}".getBytes());
// test update
zk.setData().forPath(hostPath, "{}".getBytes());
Thread.sleep(300);
Assert.assertEquals(TreeCacheEvent.Type.NODE_UPDATED, saveEventType[0]);
// test set parent node's data
zk.setData().forPath("/group-1", "{grou-data}".getBytes());
Thread.sleep(300);
Assert.assertEquals(TreeCacheEvent.Type.NODE_UPDATED, saveEventType[0]);
}