如何观看znodes的子znode?

时间:2017-09-20 07:53:38

标签: apache apache-zookeeper apache-curator

我使用策展人对Zookeeper进行编程。我想观看zonde的子znode。我的代码如下:

CuratorFramework frameWork = CuratorFrameworkFactory.builder()
            .retryPolicy(new RetryNTimes(3, 1000))
            .connectString("127.0.0.1:2181").build();
frameWork.start();

CuratorWatcher watcher = new CuratorWatcher () {

            @Override
            public void process(WatchedEvent event) throws Exception
            {
                System.out.println("event :" + event);
            }

        };

frameWork.getChildren()usingWatcher(观察者).forPath( “/ AA”)。 frameWork.setData()。forPath(“/ aa / dd”,“asdfd”.getBytes());

当调用“/ aa / dd”的setdata时,我希望触发观察者。但是失败了,有没有人有想法?

1 个答案:

答案 0 :(得分:0)

策展人有一个配方可以做到这一点。请参阅TreeCache:http://curator.apache.org/curator-recipes/tree-cache.html