9.使用GetData,Children实现对ZNode的监控
public class DataWatcher: IWatcher
{
private ZooKeeper _zookeeper = null;
Action<WatchedEvent, string> _action = null; public DataWatcher(ZooKeeper zookeeper, Action<WatchedEvent, string> action)
{
_zookeeper = zookeeper;
_action = action;
} public void Process(WatchedEvent @event)
{
try
{
//Console.WriteLine("path={0},state={1},type={2}", @event.Path, @event.State, @event.Type);
//通过getdata获取内容
var content = Encoding.UTF8.GetString(_zookeeper.GetData(@event.Path, this, null));
if (_action != null)
{
_action(@event, content);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
Console.WriteLine("欢迎来到zookeeper.net 9 ");
try
{
var bytes = zookeeper.GetData("/google", new DataWatcher(zookeeper, (e, data) =>
{
//data 是返回的内容
Console.WriteLine("path={0},state={1},type={2},data={3}", e.Path, e.State, e.Type, data);
}), null);
}
catch (KeeperException ex)
{
throw new Exception(ex.Message);
}
public class ChildrenWatcher : IWatcher
{
private ZooKeeper _zookeeper = null;
Action<WatchedEvent, IEnumerable<string>> _action = null; public ChildrenWatcher(ZooKeeper zookeeper, Action<WatchedEvent, IEnumerable<string>> action)
{
_zookeeper = zookeeper;
_action = action;
} public void Process(WatchedEvent @event)
{
try
{
//通过getdata获取内容
var list = _zookeeper.GetChildren(@event.Path, this, null);
if (_action != null)
{
_action(@event, list);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
} }
try
{
var list_t = zookeeper.GetChildren("/google", new ChildrenWatcher(zookeeper, (e, data) =>
{
Console.WriteLine("path={0},state={1},type={2},data={3}", e.Path, e.State, e.Type, string.Join(",", data));
}), null); }
catch (KeeperException ex)
{
throw new Exception(ex.Message);
}
执行创建,删除后的效果


9.使用GetData,Children实现对ZNode的监控的更多相关文章
- zabbix实现对tomcat的监控
zabbix实现对tomcat的监控 工作原理 比如:当Zabbix-Server需要知道java应用程序的某项性能的时候,会启动自身的一个Zabbix-JavaPollers进程去连接Zabbix- ...
- 基于DevExpress实现对PDF、Word、Excel文档的预览及操作处理
http://www.cnblogs.com/wuhuacong/p/4175266.html 在一般的管理系统模块里面,越来越多的设计到一些常用文档的上传保存操作,其中如PDF.Word.Excel ...
- C#代码实现对HTTP POST参数进行排序
private static string GetSortedParas(Dictionary<string, string> dic) { dic = dic.OrderBy(key = ...
- 在VS2015中用C++创建DLL并用C#调用且同时实现对DLL的调试
from:http://m.blog.csdn.net/article/details?id=51075023 在VS2015中先创建C#项目,然后再创建要编写的动态库DLL项目,这样做的好处是整个解 ...
- 【JAVA使用XPath、DOM4J解析XML文件,实现对XML文件的CRUD操作】
一.简介 1.使用XPath可以快速精确定位指定的节点,以实现对XML文件的CRUD操作. 2.去网上下载一个“XPath帮助文档”,以便于查看语法等详细信息,最好是那种有很多实例的那种. 3.学习X ...
- Java Web学习系列——Maven Web项目中集成使用Spring、MyBatis实现对MySQL的数据访问
本篇内容还是建立在上一篇Java Web学习系列——Maven Web项目中集成使用Spring基础之上,对之前的Maven Web项目进行升级改造,实现对MySQL的数据访问. 添加依赖Jar包 这 ...
- struts2视频学习笔记 22-23(基于XML配置方式实现对action的所有方法及部分方法进行校验)
课时22 基于XML配置方式实现对action的所有方法进行校验 使用基于XML配置方式实现输入校验时,Action也需要继承ActionSupport,并且提供校验文件,校验文件和action类 ...
- 用 Python 脚本实现对 Linux 服务器的监控
目前 Linux 下有一些使用 Python 语言编写的 Linux 系统监控工具 比如 inotify-sync(文件系统安全监控软件).glances(资源监控工具)在实际工作中,Linux 系统 ...
- 在应用程序中实现对NandFlash的操作
以TC58NVG2S3ETA00 为例: 下面是它的一些物理参数: 图一 图二 图三 图四 图五 图6-0 图6-1 说明一下,在图6-1中中间的那个布局表可以看做是实际的NandFlash一页数据的 ...
随机推荐
- 彻底解密C++宽字符(一)
彻底解密C++宽字符(一) 转:http://club.topsage.com/thread-2227977-1-1.html 1.从char到wchar_t “这个问题比你想象中复杂” 从字符到整数 ...
- 黄聪:中国大陆的所有IP段,中国电信所有IP段、中国铁通所有IP段、中国网通所有IP段。
中国大陆的所有IP段,中国电信所有IP段.中国铁通所有IP段.中国网通所有IP段. 中国大陆的所有IP段: 47.153.128.0 47.154.255.25558.14.0.0 58.25.255 ...
- Jython:java调用python文件之第三方包路径问题
本文转载自:http://blog.csdn.net/ztf312/article/details/51338060 本方法解决python代码的可移植性,不需要在新机器上配置python环境,只通过 ...
- mysql5.7.12/13在安装新实例时报错:InnoDB: auto-extending data file ./ibdata1 is of a different size 640 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero
.bin/mysqld --initialize-insecure --basedir=xxx --datadir=xxx 然后 .bin/mysqld_safe --defaults-file=xx ...
- java之RestTemplate的访问应用
一.REST即表述性状态传递(英文:Representational State Transfer,简称REST)是Roy Fielding博士在2000年他的博士论文中提出来的一种软件架构风格.它是 ...
- DAG最长路径
1.DAG最长路径(不记录路径) int dfs1(int s) { )return dis[s]; ; i < G[s].size(); ++i) { int to = G[s][i]; di ...
- 使用Javamail发送邮件Util
maven: <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artif ...
- C# user32.dll
#region User32.dll 函数 /// <summary> /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备 ...
- 一次使用 Redis 优化查询性能的实践
因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,一次使用 Redis 优化查询性能的实践 应用背景 有一个应用需要上传一组ID到 ...
- selenium webdriver ——执行javascript代码
在代码中import org.openqa.selenium.JavascriptExecutor;就可以使用executeScript.executeAsyncScript这两个方法了 execut ...