public static Cancellable watchChildren(final ZKClient zkClient, String path, ChildrenCallback callback) { final AtomicBoolean cancelled = new AtomicBoolean(false); watchChanges(new Operation<NodeChildren>() { @Override public ZKClient getZKClient() { return zkClient; } @Override public OperationFuture<NodeChildren> exec(String path, Watcher watcher) { return zkClient.getChildren(path, watcher); } }, path, callback, cancelled); return new Cancellable() { @Override public void cancel() { cancelled.set(true); } }; }
public static Cancellable watchChildren(final ZKClient zkClient, String path, ChildrenCallback callback) { final AtomicBoolean cancelled = new AtomicBoolean(false); watchChanges(new Operation<NodeChildren>() { @Override public ZKClient getZKClient() { return zkClient; } @Override public OperationFuture<NodeChildren> exec(String path, Watcher watcher) { return zkClient.getChildren(path, watcher); } }, path, callback, cancelled); return new Cancellable() { @Override public void cancel() { cancelled.set(true); } }; }
/** * Watch for data changes of the given path. The callback will be triggered whenever changes has been * detected. Note that the callback won't see every single changes, as that's not the guarantee of ZooKeeper. * If the node doesn't exists, it will watch for its creation then starts watching for data changes. * When the node is deleted afterwards, * * @param zkClient The {@link ZKClient} for the operation * @param path Path to watch * @param callback Callback to be invoked when data changes is detected. * @return A {@link Cancellable} to cancel the watch. */ public static Cancellable watchData(final ZKClient zkClient, final String path, final DataCallback callback) { final AtomicBoolean cancelled = new AtomicBoolean(false); watchChanges(new Operation<NodeData>() { @Override public ZKClient getZKClient() { return zkClient; } @Override public OperationFuture<NodeData> exec(String path, Watcher watcher) { return zkClient.getData(path, watcher); } }, path, callback, cancelled); return new Cancellable() { @Override public void cancel() { cancelled.set(true); } }; }
/** * Watch for data changes of the given path. The callback will be triggered whenever changes has been * detected. Note that the callback won't see every single changes, as that's not the guarantee of ZooKeeper. * If the node doesn't exists, it will watch for its creation then starts watching for data changes. * When the node is deleted afterwards, * * @param zkClient The {@link ZKClient} for the operation * @param path Path to watch * @param callback Callback to be invoked when data changes is detected. * @return A {@link Cancellable} to cancel the watch. */ public static Cancellable watchData(final ZKClient zkClient, final String path, final DataCallback callback) { final AtomicBoolean cancelled = new AtomicBoolean(false); watchChanges(new Operation<NodeData>() { @Override public ZKClient getZKClient() { return zkClient; } @Override public OperationFuture<NodeData> exec(String path, Watcher watcher) { return zkClient.getData(path, watcher); } }, path, callback, cancelled); return new Cancellable() { @Override public void cancel() { cancelled.set(true); } }; }