zookeeper客户端读取子节点的信息
2017-10-23 16:18
459 查看
在zookeeper目录下启动zookeeper客户端:./zkCli.sh(在bin目录下)
用 ls /命令来显示该节点下所有的子节点,get /MsgBusMonitor显示该节点下的所有详细信息。
用 ls /命令来显示该节点下所有的子节点,get /MsgBusMonitor显示该节点下的所有详细信息。
Object[][] result = null; //连接服务器的IP地址和端口号 String connectString = "10.0.0.100:2181"; //超时时间 int sessionTimeout = 5000; try { zk = new ZooKeeper(connectString, sessionTimeout, new Watcher() { @Override public void process(WatchedEvent event) { //不做操作 } }); // 获取任务实例example,task_schedule是子节点 List<String> example = zk.getChildren("/task_schedule", true); List<String> list = null; int number = 0;int allCount = 0; for (int j = 0; j < example.size(); j++) { List<String> runNode = zk.getChildren("/task_schedule/" + example.get(j), true); boolean numberFlag = true; if (runNode != null || !runNode.equals("")) {// 节点存在的时候 for (int i = 0; i < runNode.size(); i++) { number++; numberFlag = false; } } if(numberFlag==true){ allCount++; } } result = new Object[number+allCount][3 4000 ]; int a = 0; for (int j = 0; j < example.size(); j++) { boolean flag = true; // 获取运行节点runNode List<String> runNode = zk.getChildren("/task_schedule/" + example.get(j), true); if (runNode != null || !runNode.equals("")) {// 节点存在的时候 for (int i = 0; i < runNode.size(); i++) { byte[] data = zk.getData("/task_schedule/" + example.get(j) + "/" + runNode.get(i), null, null); result[a][0] = example.get(j); result[a][1] = runNode.get(i); if(Character.isDigit(new String(data).charAt(0))){ result[a][2] = new String(data); }else{ result[a][2] = "任务获取失败"; } a++; flag = false; } } if (flag == true) { result[a][0] = example.get(j); result[a][1] = ""; result[a][2] = ""; a++; } } } catch (KeeperException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
相关文章推荐
- 客户端分段读取服务端的socket信息 客户端连接多台socket服务端
- Zookeeper客户端基本操作java实现——创建连接、创建节点、添加修改节点内容、获取子节点、获取节点数据、删除节点
- Android客户端读取PHP服务器的图片等信息,并用ListView列出来,实现缓存功能。
- kafka在zookeeper上的节点信息和查看方式
- Webservice_10_Stax的基本操作(XPath方式读取xml,用XMLStreamReader创建Xml,用Transformer更新节点信息)
- Zookeeper实例原生API--无权限信息的Zookeeper会话访问有权限信息的节点
- 使用JSP读取客户端信息
- ZooKeeper客户端 zkCli.sh 节点的增删改查
- doc解析xml读取节点信息
- flume-1.6.0(3节点)安装与配置(数据读取涉及到snappy、自定义flume拦截器、flume采集节点和flume客户端)(升级)
- java读取zookeeper中的配置文件信息
- ZooKeeper之Java客户端API使用—读取数据。
- Zookeeper实例原生API--使用错误权限信息的ZooKeeper会话访问含权限信息的数据节点
- 使用JSP读取客户端信息
- 使用JSP读取客户端信息
- 在Linux DeviceTree添加dtsi文件并在驱动中读取节点信息写入sys文件系统
- 读取XML文件节点下面的数据信息
- Zookeeper(五)Java客户端节点操作
- storm读取kafka集群各个集群节点信息
- zookeeper客户端创建节点数据