简介

curator的TreeCache允许对某个路径的数据和路径变更以及其下所有子孙节点的数据和路径变更进行监听。

官方文档:http://curator.apache.org/curator-recipes/tree-cache.html

javaDoc:http://curator.apache.org/apidocs/org/apache/curator/framework/recipes/cache/TreeCache.html

代码示例

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.curator.retry.ExponentialBackoffRetry; public class TreeCacheDemo {
private static CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181", new ExponentialBackoffRetry(3000, 1));
private static String path = "/treeCache/test/001";
static {
client.start();
} public static void main(String[] args) throws Exception {
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
TreeCache cache = new TreeCache(client, path);
cache.getListenable().addListener((curatorFramework, treeCacheEvent) -> System.out.println(treeCacheEvent.toString()));
cache.start();
client.setData().forPath(path, "lay".getBytes());
client.create().forPath(path + "/child");
client.setData().forPath(path + "/child", "marry".getBytes());
client.delete().forPath(path + "/child");
client.delete().forPath(path);
Thread.sleep(4000);
cache.close();
Thread.sleep(50000);
client.close();
}
}

二十一、curator recipes之TreeCache的更多相关文章

  1. 十二、curator recipes之双重屏障DoubleBarrier

    简介 curator实现了单个屏障barrier和双重屏障DoubleBarrier,单个屏障就是在一个进程里面设置了屏障,并等待其它进程去移除这个屏障,否则一直阻塞.双重屏障就是设置了两道屏障,两个 ...

  2. 无废话ExtJs 入门教程二十一[继承:Extend]

    无废话ExtJs 入门教程二十一[继承:Extend] extjs技术交流,欢迎加群(201926085) 在开发中,我们在使用视图组件时,经常要设置宽度,高度,标题等属性.而这些属性可以通过“继承” ...

  3. Bootstrap <基础二十一>徽章(Badges)

    Bootstrap 徽章(Badges).徽章与标签相似,主要的区别在于徽章的边角更加圆滑. 徽章(Badges)主要用于突出显示新的或未读的项.如需使用徽章,只需要把 <span class= ...

  4. 【圣诞特献】Web 前端开发精华文章推荐【系列二十一】

    <Web 前端开发精华文章推荐>2013年第九期(总第二十一期)和大家见面了.梦想天空博客关注 前端开发 技术,分享各种增强网站用户体验的 jQuery 插件,展示前沿的 HTML5 和  ...

  5. Citrix 服务器虚拟化之二十一 桌面虚拟化之部署Provisioning Services

    Citrix 服务器虚拟化之二十一  桌面虚拟化之部署Provisioning Services Provisioning Services 是Citrix 出品的一系列虚拟化产品中最核心的一个组件, ...

  6. 二十一、contextMap中放的常用数据

    二十一.contextMap中放的常用数据 request:请求范围的数据.即ServletRequest中的那个Map parameters:请求参数的数据.即request.getParamete ...

  7. 牢记!SQL Server数据库开发的二十一条注意点

    如果你正在负责一个基于SQL Server的项目,或者你刚刚接触SQL  Server,你都有可能要面临一些数据库性能的问题,这篇文章会为你提供一些有用的指导(其中大多数也可以用于其它的DBMS). ...

  8. 转:二十一、详细解析Java中抽象类和接口的区别

    转:二十一.详细解析Java中抽象类和接口的区别 http://blog.csdn.net/liujun13579/article/details/7737670 在Java语言中, abstract ...

  9. COJ 0979 WZJ的数据结构(负二十一)

    WZJ的数据结构(负二十一) 难度级别:C: 运行时间限制:5000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你实现一个数据结构,完成这样的功能: 给你一个 ...

随机推荐

  1. mvc 读写txt文档

    -----------------写入内容---------------- string userfile = "UserData.txt"; StreamWriter sw = ...

  2. sql-省市区

    insert into Area (codeid,parentid,cityName) values(11,0,'北京');insert into Area (codeid,parentid,city ...

  3. Map 综述(三):彻头彻尾理解 ConcurrentHashMap

    https://blog.csdn.net/justloveyou_/article/details/72783008

  4. fedora 国内源

    wget http://mirrors.163.com/.help/fedora-163.repowget http://mirrors.163.com/.help/fedora-updates-16 ...

  5. WIKI常用的表格设计模板

    域名服务器管理表格     数据库管理表格     软件路径说明表格   开发测试环境虚拟机表格        

  6. Android 打开系统设置界面及相应的系统界面

    方法 1 :startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); 方法 2:Intent intent = new Intent(&quo ...

  7. Matlab 基础

    命令行(Command Line) 1. help  格式:help  命令 2. cd 配合 Tab 使用 pwd: print current working directory,打印当前工作路径 ...

  8. Lingo 做线性规划 - Marketing Applications

    Reference: <An Introduction to Management Science Quantitative Approaches to Decision Making, Rev ...

  9. (转)Python 字符串

    原文:http://www.runoob.com/python/python-strings.html

  10. Linux下超级命令htop的学习使用

    top作为日常管理工作中最常用也是最重要的Linux系统监控工具之一,可以动态观察系统进程状况.但其缺点就是只支持键盘操作,显示也单调.作为刚才Windows转到Linux的我来说,现在有了一个更好的 ...