forked from llohellohe/zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f29d1d3
commit c2d2ead
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/yangqi/zookeeper/example/masterworker/ChildrenCallbackMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} |