throws KeeperException { try { Stat s = zkw.getRecoverableZooKeeper().exists(znode, zkw); boolean exists = s != null ? true : false; if (exists) {
/** * Check if the specified node exists. Sets no watches. * * @param zkw * zk reference * @param znode * path of node to watch * @return version of the node if it exists, -1 if does not exist * @throws org.apache.zookeeper.KeeperException * if unexpected zookeeper exception */ public static int checkExists(ZooKeeperWatcher zkw, String znode) throws KeeperException { try { Stat s = zkw.getRecoverableZooKeeper().exists(znode, null); return s != null ? s.getVersion() : -1; } catch (KeeperException e) { LOG.warn(zkw.prefix("Unable to set watcher on znode (" + znode + ")"), e); zkw.keeperException(e); return -1; } catch (InterruptedException e) { LOG.warn(zkw.prefix("Unable to set watcher on znode (" + znode + ")"), e); zkw.interruptedException(e); return -1; } }
RecoverableZooKeeper zk = zkw.getRecoverableZooKeeper(); waitForZKConnectionIfAuthenticating(zkw); if (zk.exists(znode, false) == null) { zk.create(znode, new byte[0], createACL(zkw, znode), CreateMode.PERSISTENT); } catch (KeeperException.NoAuthException nee) { try { if (null == zkw.getRecoverableZooKeeper().exists(znode, false)) {
/** * Get the number of children of the specified node. * * If the node does not exist or has no children, returns 0. * * Sets no watches at all. * * @param zkw * zk reference * @param znode * path of node to count children of * @return number of children of specified node, 0 if none or parent does not * exist * @throws org.apache.zookeeper.KeeperException * if unexpected zookeeper exception */ public static int getNumberOfChildren(ZooKeeperWatcher zkw, String znode) throws KeeperException { try { Stat stat = zkw.getRecoverableZooKeeper().exists(znode, null); return stat == null ? 0 : stat.getNumChildren(); } catch (KeeperException e) { LOG.warn(zkw.prefix("Unable to get children of node " + znode)); zkw.keeperException(e); } catch (InterruptedException e) { zkw.interruptedException(e); } return 0; }
zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode), CreateMode.PERSISTENT); return zkw.getRecoverableZooKeeper().exists(znode, zkw).getVersion(); } catch (InterruptedException e) { zkw.interruptedException(e);
} catch (KeeperException.NodeExistsException nee) { try { zkw.getRecoverableZooKeeper().exists(znode, zkw); } catch (InterruptedException e) { zkw.interruptedException(e);
Stat stats = zkw.getRecoverableZooKeeper().exists(path, false); LOG.info("EPHEMERAL NODE BEFORE SERVER ABORT, path=" + path + ", stats=" + stats);