Example usage for org.apache.zookeeper WatchedEvent getWrapper

List of usage examples for org.apache.zookeeper WatchedEvent getWrapper

Introduction

In this page you can find the example usage for org.apache.zookeeper WatchedEvent getWrapper.

Prototype

public WatcherEvent getWrapper() 

Source Link

Document

Convert WatchedEvent to type that can be sent over network

Usage

From source file:com.discovery.darchrow.ZookeeperClientTest.java

License:Open Source License

public static void main(String[] args) throws Exception {
    // ?//from  w  w  w . j a v a  2  s.co m
    ZooKeeper zk = new ZooKeeper("localhost:2181", 30000, new Watcher() {
        // ?
        public void process(WatchedEvent event) {
            System.out.println("?:" + event.getState() + ":" + event.getType() + ":" + event.getWrapper()
                    + ":" + event.getPath());
        }
    });
    // ktv???????
    zk.create(ROOT, "root-ktv".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    // ??KTV ,       PERSISTENT_SEQUENTIAL  0000000000 ?
    zk.create(ROOT + "/?KTV", "?KTV".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT_SEQUENTIAL);

    // ?,       EPHEMERAL session 
    zk.create(ROOT + "/KTV", "KTV".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);

    // ???EPHEMERAL_SEQUENTIAL  session ?
    zk.create(ROOT + "/KTV-", "KTV-".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.EPHEMERAL_SEQUENTIAL);

    // ? ? ktv
    List<String> ktvs = zk.getChildren(ROOT, true);
    System.out.println(Arrays.toString(ktvs.toArray()));
    for (String node : ktvs) {
        // 
        zk.delete(ROOT + "/" + node, -1);
    }
    // ?
    zk.delete(ROOT, -1);
    zk.close();
}