/** * Reports the ZooKeeper session client. * * <p> This may potentially wait forever: no timeout. </p> * * @return the ZooKeeper session client. */ public ZooKeeper getZKClient() { return getZKClient(0.0); }
/** * See {@link ZooKeeper#exists(String, Watcher)}. * * @param path of a node. * @param watcher triggered by a successful operation that sets data on the node or * creates/deletes the node. * @return the stat of the node. * @throws KeeperException on ZooKeeper errors. * Connection related errors are handled by retrying the operations. */ public Stat exists(File path, Watcher watcher) throws KeeperException { while (true) { try { return getZKClient().exists(path.toString(), watcher); } catch (InterruptedException ie) { throw new RuntimeInterruptedException(ie); } catch (ConnectionLossException ke) { LOG.debug("ZooKeeper connection lost.", ke); } catch (SessionExpiredException see) { LOG.debug("ZooKeeper session expired.", see); } catch (SessionMovedException sme) { LOG.debug("ZooKeeper session moved.", sme); } Time.sleep(ZOOKEEPER_RETRY_DELAY); LOG.debug("Retrying exists({}).", path); } }
/** * See {@link ZooKeeper#exists(String, boolean)}. * * @param path of a node. * @return the stat of the node; null if the node does not exist. * @throws KeeperException on ZooKeeper errors. * Connection related errors are handled by retrying the operations. */ public Stat exists(File path) throws KeeperException { while (true) { try { return getZKClient().exists(path.toString(), false); } catch (InterruptedException ie) { throw new RuntimeInterruptedException(ie); } catch (ConnectionLossException ke) { LOG.debug("ZooKeeper connection lost.", ke); } catch (SessionExpiredException see) { LOG.debug("ZooKeeper session expired.", see); } catch (SessionMovedException sme) { LOG.debug("ZooKeeper session moved.", sme); } Time.sleep(ZOOKEEPER_RETRY_DELAY); LOG.debug("Retrying exists({}).", path); } }
/** * See {@link ZooKeeper#getChildren(String, Watcher, Stat)}. * * @param path of a parent node. * @param watcher to trigger upon parent node deletion or creation/deletion of a child node. * @param stat of the provided parent node. * @return an unordered array of the parent node's children. * @throws KeeperException on ZooKeeper errors. * Connection related errors are handled by retrying the operations. */ public List<String> getChildren(File path, Watcher watcher, Stat stat) throws KeeperException { while (true) { try { return getZKClient().getChildren(path.toString(), watcher, stat); } catch (InterruptedException ie) { throw new RuntimeInterruptedException(ie); } catch (ConnectionLossException ke) { LOG.debug("ZooKeeper connection lost.", ke); } catch (SessionExpiredException see) { LOG.debug("ZooKeeper session expired.", see); } catch (SessionMovedException sme) { LOG.debug("ZooKeeper session moved.", sme); } Time.sleep(ZOOKEEPER_RETRY_DELAY); LOG.debug("Retrying getChildren({}).", path); } }
/** * See {@link ZooKeeper#getData(String, Watcher, Stat)}. * * @param path of a node. * @param watcher triggered by a successful operation that sets data on the node or * deletes the node. * @param stat of the node. * @return the data contained within the node. * @throws KeeperException on ZooKeeper errors. * Connection related errors are handled by retrying the operations. */ public byte[] getData(File path, Watcher watcher, Stat stat) throws KeeperException { while (true) { try { return getZKClient().getData(path.toString(), watcher, stat); } catch (InterruptedException ie) { throw new RuntimeInterruptedException(ie); } catch (ConnectionLossException ke) { LOG.debug("ZooKeeper connection lost.", ke); } catch (SessionExpiredException see) { LOG.debug("ZooKeeper session expired.", see); } catch (SessionMovedException sme) { LOG.debug("ZooKeeper session moved.", sme); } Time.sleep(ZOOKEEPER_RETRY_DELAY); LOG.debug("Retrying getData({}).", path); } }
return new File(getZKClient().create(path.toString(), data, acl, createMode)); } catch (InterruptedException ie) { throw new RuntimeInterruptedException(ie);
/** * See {@link ZooKeeper#delete(String, int)}. * * @param path of the node to delete. * @param version of the node to delete. * @throws KeeperException on ZooKeeper errors. * Connection related errors are handled by retrying the operations. */ public void delete(File path, int version) throws KeeperException { while (true) { try { getZKClient().delete(path.toString(), version); return; } catch (InterruptedException ie) { throw new RuntimeInterruptedException(ie); } catch (ConnectionLossException ke) { LOG.debug("ZooKeeper connection lost.", ke); } catch (SessionExpiredException see) { LOG.debug("ZooKeeper session expired.", see); } catch (SessionMovedException sme) { LOG.debug("ZooKeeper session moved.", sme); } Time.sleep(ZOOKEEPER_RETRY_DELAY); LOG.debug("Retrying delete({}, {}).", path, version); } }
/** * See {@link ZooKeeper#setData(String, byte[], int)}. * * @param path of a node. * @param data to set. * @param version of the node. * @return the stat of the node. * @throws KeeperException on ZooKeeper errors. * Connection related errors are handled by retrying the operations. */ public Stat setData(File path, byte[] data, int version) throws KeeperException { while (true) { try { return getZKClient().setData(path.toString(), data, version); } catch (InterruptedException ie) { throw new RuntimeInterruptedException(ie); } catch (ConnectionLossException ke) { LOG.debug("ZooKeeper connection lost.", ke); LOG.debug("Retrying setData({}, {}, {}).", path, Bytes.toStringBinary(data), version); } catch (SessionExpiredException see) { LOG.debug("ZooKeeper session expired.", see); } catch (SessionMovedException sme) { LOG.debug("ZooKeeper session moved.", sme); } Time.sleep(ZOOKEEPER_RETRY_DELAY); } }