Skip to content

Commit

Permalink
add post
Browse files Browse the repository at this point in the history
  • Loading branch information
llohellohe committed Jan 2, 2014
1 parent f29d1d3 commit c2d2ead
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 1999-2010 Alibaba.com All right reserved. This software is the
* confidential and proprietary information of Alibaba.com ("Confidential
* Information"). You shall not disclose such Confidential Information and shall
* use it only in accordance with the terms of the license agreement you entered
* into with Alibaba.com.
*/
package yangqi.zookeeper.example.masterworker;

import java.io.IOException;
import java.util.List;

import org.apache.zookeeper.AsyncCallback.ChildrenCallback;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.ZooKeeper;

public class ChildrenCallbackMonitor {

/**
* @param args
* @throws IOException
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException, InterruptedException {
final ZooKeeper zookeeper = new ZooKeeper("localhost:2181", 2000, null);

final ChildrenCallback callback = new ChildrenCallback() {

@Override
public void processResult(int rc, String path, Object ctx, List<String> children) {
System.out.println(children);

}

};

Watcher watcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
System.out.println("Event is " + event);
if (event.getType() == EventType.NodeChildrenChanged) {
System.out.println("Changed " + event);
zookeeper.getChildren("/workers", this, callback, null);
}
}
};

zookeeper.getChildren("/workers", watcher, callback, null);


Thread.sleep(200000);

}

}

0 comments on commit c2d2ead

Please sign in to comment.