/** * Delete the specified node with the specified version. Sets no watches. * Throws all exceptions. */ public static boolean deleteNode(ZooKeeperWatcher zkw, String node, int version) throws KeeperException { try { zkw.getRecoverableZooKeeper().delete(node, version); return true; } catch (KeeperException.BadVersionException bve) { return false; } catch (InterruptedException ie) { zkw.interruptedException(ie); return false; } }
/** * Deletes the specified node. Fails silent if the node does not exist. * * @param zkw * @param node * @throws org.apache.zookeeper.KeeperException */ public static void deleteNodeFailSilent(ZooKeeperWatcher zkw, String node) throws KeeperException { try { zkw.getRecoverableZooKeeper().delete(node, -1); } catch (KeeperException.NoNodeException nne) { } catch (InterruptedException ie) { zkw.interruptedException(ie); } }
/** * Delete the specified node and all of it's children. * <p> * If the node does not exist, just returns. * <p> * Sets no watches. Throws all exceptions besides dealing with deletion of * children. */ public static void deleteNodeRecursively(ZooKeeperWatcher zkw, String node) throws KeeperException { try { List<String> children = ZKUtil.listChildrenNoWatch(zkw, node); // the node is already deleted, so we just finish if (children == null) return; if (!children.isEmpty()) { for (String child : children) { deleteNodeRecursively(zkw, joinZNode(node, child)); } } zkw.getRecoverableZooKeeper().delete(node, -1); } catch (InterruptedException ie) { zkw.interruptedException(ie); } }