Package org.apache.zookeeper.data

Examples of org.apache.zookeeper.data.Stat


      this.store.inform(Constants.ZK_ERROR);
    }
  }
 
  public void watch(String prefix) {
    Stat s = new Stat();
    String info;
    try {
      info = new String(this.zk.getData(prefix, true, s));
      this.store.check(prefix, info);
    } catch (Exception e) {
View Full Code Here


    return tree;
  }
 
  private void getChildren(String path, HashMap<String, String> tree){
    try {
      Stat s = new Stat();
      String value = new String(this.zk.getData(path, false, s));
      value = "version:" + s.getVersion() + "\r\n" + value;     
      tree.put(path, value);
     
      List<String> list = this.zk.getChildren(path, false);
      Iterator<String> i = list.iterator();
      while (i.hasNext()) {
View Full Code Here

    zk.create("/iserviceTest/node1/node1", "node1-node1-node1".getBytes(), acls, CreateMode.PERSISTENT);
    return zk;
  }
 
  public void clearUpZk(ZooKeeper zk) throws Exception {
    Stat s = new Stat();
    zk.getData("/iserviceTest/node1/node1", false, s);
    zk.delete("/iserviceTest/node1/node1", s.getVersion());
   
    zk.getData("/iserviceTest/node1", false, s);
    zk.delete("/iserviceTest/node1", s.getVersion());
   
    zk.getData("/iserviceTest", false, s);
    zk.delete("/iserviceTest", s.getVersion());
  }
View Full Code Here

      tableDescriptor.setEnabled(isEnabled(useCache, cluster, table));
    }
  }

  private byte[] getData(String path) throws KeeperException, InterruptedException {
    Stat stat = _zk.exists(path, false);
    if (stat == null) {
      LOG.debug("Tried to fetch path [{0}] and path is missing", path);
      return null;
    }
    byte[] data = _zk.getData(path, false, stat);
View Full Code Here

    List<String> clusterList = getClusterList(useCache);
    for (String cluster : clusterList) {
      long s = System.nanoTime();
      try {
        checkIfOpen();
        Stat stat = _zk.exists(ZookeeperPathConstants.getTablePath(cluster, table), false);
        if (stat != null) {
          // _tableToClusterCache.put(table, cluster);
          return cluster;
        }
      } catch (KeeperException e) {
View Full Code Here

            retryOrThrow(retryCounter, e, "setData");
            break;
          case BADVERSION:
            // try to verify whether the previous setData success or not
            try{
              Stat stat = new Stat();
              byte[] revData = zk.getData(path, false, stat);
              int idLength = Bytes.toInt(revData, ID_LENGTH_SIZE);
              int dataLength = revData.length-ID_LENGTH_SIZE-idLength;
              int dataOffset = ID_LENGTH_SIZE+idLength;
             
View Full Code Here

    List<String> nodes = zk.getChildren(parent, false);
    List<String> matching = filterByPrefix(nodes, nodePrefix);
    for (String node : matching) {
      String nodePath = parent + "/" + node;
      Stat stat = zk.exists(nodePath, false);
      if (stat != null) {
        return nodePath;
      }
    }
    return null;
View Full Code Here

   * @throws KeeperException if unexpected zookeeper exception
   */
  public static boolean watchAndCheckExists(ZooKeeperWatcher zkw, String znode)
  throws KeeperException {
    try {
      Stat s = zkw.getRecoverableZooKeeper().exists(znode, zkw);
      boolean exists = s != null ? true : false;
      if (exists) {
        LOG.debug(zkw.prefix("Set watcher on existing znode " + znode));
      } else {
        LOG.debug(zkw.prefix(znode+" does not exist. Watcher is set."));
View Full Code Here

   * @throws 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) {
View Full Code Here

   * @throws 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);
View Full Code Here

TOP

Related Classes of org.apache.zookeeper.data.Stat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.