当前位置: 首页>>代码示例>>Java>>正文


Java ZKUtil类代码示例

本文整理汇总了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.");
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:28,代码来源:ActiveStandbyElector.java

示例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);
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:21,代码来源:BKLogWriteHandler.java

示例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;
    }
}
 
开发者ID:hhu-bsinfo,项目名称:dxram,代码行数:22,代码来源:ZooKeeperHandler.java

示例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;
}
 
开发者ID:sereca,项目名称:SecureKeeper,代码行数:10,代码来源:DeleteAllCommand.java

示例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);
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:33,代码来源:BKDistributedLogManager.java

示例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) ;
  }
}
 
开发者ID:DemandCube,项目名称:Scribengin,代码行数:15,代码来源:RegistryImpl.java

示例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) ;
  }
}
 
开发者ID:DemandCube,项目名称:Scribengin,代码行数:10,代码来源:RegistryImpl.java

示例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) ;
  }
}
 
开发者ID:DemandCube,项目名称:Scribengin,代码行数:15,代码来源:RegistryImpl.java

示例9: deleteZkNode

import org.apache.zookeeper.ZKUtil; //导入依赖的package包/类
@Test
public void deleteZkNode() throws Exception {
    ZKUtil.deleteRecursive(zk.getZookeeperClient().getZooKeeper(), "/resa");
}
 
开发者ID:ADSC-Resa,项目名称:resa,代码行数:5,代码来源:MigrateSimulateForCH.java


注:本文中的org.apache.zookeeper.ZKUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。