package book.chapter05;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooDefs.Ids;
import org.omg.CosNaming.IstringHelper;
public class Zookeeper_GetChildren_API_ASync_Usage2 implements Watcher {
private static CountDownLatch connectedSemaphore = new CountDownLatch(1);
private static ZooKeeper zk=null;
public void process(WatchedEvent event) {
System.out.println("Receive watched event: " + event);
if (KeeperState.SyncConnected == event.getState()) {
if(EventType.None==event.getType()&&null==event.getPath()){
connectedSemaphore.countDown();
}else if(event.getType()==EventType.NodeChildrenChanged){
try {
System.out.println("ReGet Child: "+zk.getChildren(event.getPath(),true));
} catch (KeeperException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String[] args) throws Exception{
String path="/zk-book";
zk = new ZooKeeper("127.0.0.1:2181", 5000, new Zookeeper_GetChildren_API_ASync_Usage2());
connectedSemaphore.await();
zk.create(path, "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create(path+"/c1", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
zk.getChildren(path, true,new IChildren2Callback(),null);
zk.create(path+"/c2", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
Thread.sleep(Integer.MAX_VALUE);
}
}
class IChildren2Callback implements AsyncCallback.Children2Callback{
public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
System.out.println("Get Children znode result: [response code: "+rc+", param path: "+",ctx: "+ctx+",children list: "+children+",stat: "+stat);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
读书笔记:从Paxos到Zookeeper分布式一致性原理与实践的代码和学习的测试代码.zip (53个子文件)
读书笔记:从Paxos到Zookeeper分布式一致性原理与实践的代码和学习的测试代码
zookeeperbook
.classpath 996B
.settings
org.eclipse.jdt.core.prefs 238B
org.eclipse.core.resources.prefs 115B
org.eclipse.m2e.core.prefs 86B
pom.xml 2KB
src
test
java
com
matrix
zookeeperbook
AppTest.java 652B
main
java
book
chapter05
NodeCache_Sample.java 1KB
AuthSample_Delete.java 1KB
GetData_API_Sync_Usage.java 2KB
Create_Curator_Session_Sample.java 574B
Recipes_DistAtomicInt.java 1020B
Exist_API_ASync_Usage.java 2KB
Recipes_MasterSelect.java 1KB
Get_Data_Sample.java 966B
Recipes_CyclicBarrier.java 853B
Get_Curator_Data_Sample.java 961B
Recipes_Barrier.java 1KB
Create_Node_Sample.java 275B
Create_Session_Sample_Fluent.java 615B
SetData_API_Sync_Usage.java 1KB
Zookeeper_Constructor_Usage_Simple.java 934B
Create_Session_Sample.java 281B
Create_Curator_Node_Sample.java 691B
Recipes_Lock.java 1KB
PathChildrenCache_Sample.java 2KB
Zookeeper_Create_API_ASync_Usage.java 2KB
GetData_API_ASync_Usage2.java 2KB
Set_Curator_Data_Simple.java 1KB
AuthSample_Get2.java 893B
Zookeeper_Constrctor_Usage_With_SID_PASSWD.java 1KB
Create_Node_Background_Sample.java 2KB
Get_Children_Sample.java 942B
Del_Data_Sample.java 912B
Zookeeper_Create_API_Sync_Usage.java 1KB
Zookeeper_GetChildren_API_Sync_Usage.java 2KB
Zookeeper_GetChildren_API_ASync_Usage2.java 2KB
Recipes_NoLock.java 680B
AuthSample_Get.java 504B
AuthSample.java 495B
SetData_API_ASync_Usage.java 1KB
.git
index 5KB
HEAD 23B
refs
heads
master 41B
tags
remotes
origin
master 41B
objects
pack
pack-12c3f9f3c112bdccf2989c6bf6553a689ee09506.idx 4KB
pack-12c3f9f3c112bdccf2989c6bf6553a689ee09506.pack 21KB
info
FETCH_HEAD 124B
logs
HEAD 130B
refs
heads
master 130B
remotes
origin
master 144B
hooks
config 261B
branches
.project 542B
.gitignore 49B
共 53 条
- 1
资源评论
baidu_16992441
- 粉丝: 311
- 资源: 1041
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于javaweb的网上拍卖系统,采用Spring + SpringMvc+Mysql + Hibernate+ JSP技术
- polygon-mumbai
- Chrome代理 switchyOmega
- GVC-全球价值链参与地位指数,基于ICIO表,(Wang等 2017a)计算方法
- 易语言ADS指纹浏览器管理工具
- 易语言奇易模块5.3.6
- cad定制家具平面图工具-(FG)门板覆盖柜体
- asp.net 原生js代码及HTML实现多文件分片上传功能(自定义上传文件大小、文件上传类型)
- whl@pip install pyaudio ERROR: Failed building wheel for pyaudio
- Constantsfd密钥和权限集合.kt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功