开发者

How to implement mutex or object monitor in ZooKeeper?

I want to implement simple class using ZooKeeper

    public class ResourceMonitor implements Watcher {
    String name = "/zk_test3";
    ZooKeeper zk;

    public ResourceMonitor() throws IOException {
        zk = new ZooKeeper("localhost:8000", 3000, this);
    }

    public void waitAndGet() {

    }

    public void release() {
        //remove children
    }

    public void process(WatchedEvent event) {
        System.out.println("ResourceMonitor:" + event.toStri开发者_如何转开发ng());
    }
}

I'm new to ZooKeeper and didn't find such example in ZooKeeper receipts.


You can find example of distributed lock implementation at github. Also you can take a look at curator zookeeper client which has implementations of common zk reciepts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜