/** * Close this client object. Once the client is closed, its session becomes invalid. All the ephemeral nodes in the * ZooKeeper server associated with the session will be removed. The watches left on those nodes (and on their * parents) will be triggered. * * @throws InterruptedException * in case of InterruptedException from {@code ZooKeeper#close()}; */ public void close() throws InterruptedException { getZooKeeper().close(); }
@Override public Stat execute() throws KeeperException, InterruptedException { return getZooKeeper().exists(path, watch); } });
@Override public Stat execute() throws KeeperException, InterruptedException { return getZooKeeper().exists(path, watcher); } });
@Override public byte[] execute() throws KeeperException, InterruptedException { return getZooKeeper().getData(path, watcher, stat); } });
@Override public byte[] execute() throws KeeperException, InterruptedException { return getZooKeeper().getData(path, watch, stat); } });
@Override public List<String> execute() throws KeeperException, InterruptedException { List<String> childList = getZooKeeper().getChildren(path, watch); /* Sort children according to the sequence number, if desired */ if(childComparator != null) { Collections.sort(childList, childComparator); } // remove guava dependency to avoid making core depending on two many libs. if(fullPath) { List<String> fullChildList = new ArrayList<String>(); for(String child: childList) { fullChildList.add(path + GuaguaConstants.ZOOKEEPER_SEPARATOR + child); } return fullChildList; } return childList; } });
@Override public List<String> execute() throws KeeperException, InterruptedException { List<String> childList = getZooKeeper().getChildren(path, watch); /* Sort children according to the sequence number, if desired */ if(sequenceSorted) { Collections.sort(childList, sequenceComparator); } if(fullPath) { List<String> fullChildList = new ArrayList<String>(); for(String child: childList) { fullChildList.add(path + GuaguaConstants.ZOOKEEPER_SEPARATOR + child); } return fullChildList; } return childList; } });
@Override public String execute() throws KeeperException, InterruptedException { if(!recursive) { return getZooKeeper().create(path, data, acl, createMode); } try { return getZooKeeper().create(path, data, acl, createMode); } catch (KeeperException.NoNodeException e) { LOG.warn("createExt: Cannot directly create node {} because of NoNodeException.", path); } int pos = path.indexOf(GuaguaConstants.ZOOKEEPER_SEPARATOR, 1); for(; pos != -1; pos = path.indexOf(GuaguaConstants.ZOOKEEPER_SEPARATOR, pos + 1)) { String subPath = path.substring(0, pos); try { // set intermediate path to PERSISTENT, because other EPHEMERAL or SEQUENTIAL znode should be // attached to PERSISTENT znode. getZooKeeper().create(subPath, null, acl, CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException e) { LOG.warn("createExt: Znode {} already exists", subPath); } } return getZooKeeper().create(path, data, acl, createMode); } });
@Override public List<String> execute() throws KeeperException, InterruptedException { List<String> childList = getZooKeeper().getChildren(path, watch); /* Sort children according to the sequence number, if desired */ if(sequenceSorted) { Collections.sort(childList, sequenceComparator); } List<String> result = new ArrayList<String>(); for(String child: childList) { String realPath = fullPath ? (path + GuaguaConstants.ZOOKEEPER_SEPARATOR + child) : child; if(filter == null || !filter.filter(realPath)) { result.add(realPath); } } return result; } });
@Override public Void execute() throws KeeperException, InterruptedException { if(!recursive) { getZooKeeper().delete(path, version); return null; } try { getZooKeeper().delete(path, version); return null; } catch (KeeperException.NotEmptyException e) { LOG.warn("deleteExt: Cannot directly remove node {}", path); } List<String> childList = getZooKeeper().getChildren(path, false); for(String child: childList) { deleteExt(path + GuaguaConstants.ZOOKEEPER_SEPARATOR + child, -1, true); } getZooKeeper().delete(path, version); return null; } });
} catch (KeeperException.NodeExistsException e) { LOG.warn("createOrSet: Node exists on path {}", path); setStat = getZooKeeper().setData(path, data, version);