Java 在Zookeeper节点上调用getChildren时忽略锁定节点

Java 在Zookeeper节点上调用getChildren时忽略锁定节点,java,apache-zookeeper,apache-curator,Java,Apache Zookeeper,Apache Curator,当我使用curator在Zookeeper节点上调用getChildren()时,有没有办法忽略表示锁的子节点 我想读取所有子节点及其特定节点的数据。因此,我首先调用getChildren()并遍历返回的列表,然后对每个这样的子级调用getData()。为了避免子进程在这两者之间发生变化,我首先需要一个进程间互斥。不幸的是,子对象列表也包含此互斥对象 InterProcessMutex mutex = new InterProcessMutex(client, parentNodePath);

当我使用curator在Zookeeper节点上调用getChildren()时,有没有办法忽略表示锁的子节点

我想读取所有子节点及其特定节点的数据。因此,我首先调用getChildren()并遍历返回的列表,然后对每个这样的子级调用getData()。为了避免子进程在这两者之间发生变化,我首先需要一个进程间互斥。不幸的是,子对象列表也包含此互斥对象

InterProcessMutex mutex = new InterProcessMutex(client, parentNodePath);

mutex.acquire();

try {
  List<String> children = client.getChildren().forPath(parentNodePath);

  for (String child : children) {
    // do something
    // ignore the lock-node
  }

} finally {
  mutex.release();
}
InterProcessMutex mutex=新的InterProcessMutex(客户端,parentNodePath);
mutex.acquire();
试一试{
List children=client.getChildren().forPath(parentNodePath);
for(字符串子项:子项){
//做点什么
//忽略锁定节点
}
}最后{
mutex.release();
}

有更聪明的方法吗?或者忽略锁节点?

为锁节点使用不同的基,这样实际数据就不会与锁数据混合。锁不必知道它们锁定的是什么,所以不需要为锁机制提供相同的父基

InterProcessMutex mutex = new InterProcessMutex(client, "/lock-base/lock-");
然后像你做的那样做剩下的事情

mutex.acquire();

try {
  List<String> children = client.getChildren().forPath(parentNodePath);

  for (String child : children) {
    // do something
    // no need to worry about lock nodes
  }

} finally {
  mutex.release();
}
mutex.acquire();
试一试{
List children=client.getChildren().forPath(parentNodePath);
for(字符串子项:子项){
//做点什么
//无需担心锁节点
}
}最后{
mutex.release();
}

只要确保所有试图访问parentNodePath的应用程序都使用相同的锁节点库,就可以了。

无论如何,即使我手动筛选出锁子节点,这也不起作用。在使用不同的客户端创建节点1-2次后,这会挂起。也许我遇到了一个无休止的循环,因为以这种方式获取和释放锁会触发所有其他客户机上的getChildren观察器,这些客户机也会尝试获取互斥体等等。当我移除互斥时,一切都按预期进行。