本文整理汇总了Java中org.apache.zookeeper.ZKUtil类的典型用法代码示例。如果您正苦于以下问题:Java ZKUtil类的具体用法?Java ZKUtil怎么用?Java ZKUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ZKUtil类属于org.apache.zookeeper包,在下文中一共展示了ZKUtil类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearParentZNode
import org.apache.zookeeper.ZKUtil; //导入依赖的package包/类
/**
* Clear all of the state held within the parent ZNode.
* This recursively deletes everything within the znode as well as the
* parent znode itself. It should only be used when it's certain that
* no electors are currently participating in the election.
*/
public synchronized void clearParentZNode()
throws IOException, InterruptedException {
Preconditions.checkState(!wantToBeInElection,
"clearParentZNode() may not be called while in the election");
try {
LOG.info("Recursively deleting " + znodeWorkingDir + " from ZK...");
zkDoWithRetries(new ZKAction<Void>() {
@Override
public Void run() throws KeeperException, InterruptedException {
ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
return null;
}
});
} catch (KeeperException e) {
throw new IOException("Couldn't clear parent znode " + znodeWorkingDir,
e);
}
LOG.info("Successfully deleted " + znodeWorkingDir + " from ZK.");
}
示例2: deleteLog
import org.apache.zookeeper.ZKUtil; //导入依赖的package包/类
public void deleteLog() throws IOException {
lock.checkOwnershipAndReacquire();
FutureUtils.result(purgeLogSegmentsOlderThanTxnId(-1));
try {
Utils.closeQuietly(lock);
zooKeeperClient.get().exists(logMetadata.getLogSegmentsPath(), false);
zooKeeperClient.get().exists(logMetadata.getMaxTxIdPath(), false);
if (logMetadata.getLogRootPath().toLowerCase().contains("distributedlog")) {
ZKUtil.deleteRecursive(zooKeeperClient.get(), logMetadata.getLogRootPath());
} else {
LOG.warn("Skip deletion of unrecognized ZK Path {}", logMetadata.getLogRootPath());
}
} catch (InterruptedException ie) {
LOG.error("Interrupted while deleting log znodes", ie);
throw new DLInterruptedException("Interrupted while deleting " + logMetadata.getLogRootPath(), ie);
} catch (KeeperException ke) {
LOG.error("Error deleting" + logMetadata.getLogRootPath() + " in zookeeper", ke);
}
}
示例3: close
import org.apache.zookeeper.ZKUtil; //导入依赖的package包/类
/**
* Disconnects from ZooKeeper
*
* @param p_delete
* if true alle ZooKeeper nodes are deleted
* @throws ZooKeeperException
* if ZooKeeper could not accessed
*/
public synchronized void close(final boolean p_delete) throws ZooKeeperException {
if (m_zookeeper != null) {
try {
if (p_delete) {
ZKUtil.deleteRecursive(m_zookeeper, m_path);
}
m_zookeeper.close();
} catch (final InterruptedException | KeeperException e) {
throw new ZooKeeperException("Could not access ZooKeeper", e);
}
m_zookeeper = null;
}
}
示例4: exec
import org.apache.zookeeper.ZKUtil; //导入依赖的package包/类
@Override
public boolean exec() throws KeeperException,
InterruptedException {
printDeprecatedWarning();
String path = args[1];
ZKUtil.deleteRecursive(zk, path);
return false;
}
示例5: delete
import org.apache.zookeeper.ZKUtil; //导入依赖的package包/类
/**
* Delete all the partitions of the specified log
*
* @throws IOException if the deletion fails
*/
@Override
public void delete() throws IOException {
BKLogWriteHandler ledgerHandler = createWriteHandler(true);
try {
ledgerHandler.deleteLog();
} finally {
Utils.closeQuietly(ledgerHandler);
}
// Delete the ZK path associated with the log stream
String zkPath = getZKPath();
// Safety check when we are using the shared zookeeper
if (zkPath.toLowerCase().contains("distributedlog")) {
try {
LOG.info("Delete the path associated with the log {}, ZK Path {}", name, zkPath);
ZKUtil.deleteRecursive(writerZKC.get(), zkPath);
} catch (InterruptedException ie) {
LOG.error("Interrupted while accessing ZK", ie);
throw new DLInterruptedException("Error initializing zk", ie);
} catch (KeeperException ke) {
LOG.error("Error accessing entry in zookeeper", ke);
throw new IOException("Error initializing zk", ke);
}
} else {
LOG.warn("Skip deletion of unrecognized ZK Path {}", zkPath);
}
}
示例6: rdelete
import org.apache.zookeeper.ZKUtil; //导入依赖的package包/类
@Override
public void rdelete(String path) throws RegistryException {
checkConnected();
try {
PathUtils.validatePath(path);
List<String> tree = ZKUtil.listSubTreeBFS(zkClient, realPath(path));
for (int i = tree.size() - 1; i >= 0 ; --i) {
//Delete the leaves first and eventually get rid of the root
zkClient.delete(tree.get(i), -1); //Delete all versions of the node with -1.
}
} catch (InterruptedException | KeeperException e) {
throw new RegistryException(ErrorCode.Unknown, e) ;
}
}
示例7: findDencendantRealPaths
import org.apache.zookeeper.ZKUtil; //导入依赖的package包/类
public List<String> findDencendantRealPaths(String path) throws RegistryException {
checkConnected();
try {
PathUtils.validatePath(realPath(path));
return ZKUtil.listSubTreeBFS(zkClient, realPath(path));
} catch (InterruptedException | KeeperException e) {
throw new RegistryException(ErrorCode.Unknown, e) ;
}
}
示例8: rcopy
import org.apache.zookeeper.ZKUtil; //导入依赖的package包/类
public void rcopy(String path, String toPath) throws RegistryException {
try {
PathUtils.validatePath(path);
List<String> tree = ZKUtil.listSubTreeBFS(zkClient, realPath(path));
for (int i = 0; i < tree.size(); i++) {
String selPath = tree.get(i);
String selToPath = selPath.replace(path, toPath);
byte[] data = zkClient.getData(selPath, false, new Stat()) ;
zkClient.create(selToPath, data, DEFAULT_ACL, toCreateMode(NodeCreateMode.PERSISTENT)) ;
}
} catch (InterruptedException | KeeperException e) {
throw new RegistryException(ErrorCode.Unknown, e) ;
}
}
示例9: deleteZkNode
import org.apache.zookeeper.ZKUtil; //导入依赖的package包/类
@Test
public void deleteZkNode() throws Exception {
ZKUtil.deleteRecursive(zk.getZookeeperClient().getZooKeeper(), "/resa");
}