/** * Start watching a node, optionnaly waiting for it to be created * * @param zk * @param nodePath * @param waitForCreation * @throws KeeperException * @throws InterruptedException */ protected WatchedNode(final ZooKeeperPlus zk, final String nodePath, boolean waitForCreation) throws KeeperException, InterruptedException { this.zk = zk; this.nodePath = nodePath; // Immediately try to load the data, if it fails, then optionally wait try { watchForData(); } catch (KeeperException.NoNodeException e) { if (waitForCreation) { NodeCreationBarrier.block(zk, nodePath); watchForData(); } else { watchForCreation(); } } }
// Will block until specified node is created or connection is lost public void block() throws InterruptedException, KeeperException { block(0); }