Examples of ZooKeeperIface


Examples of com.facebook.zookeeper.ZooKeeperIface

      // ephemeral nodes in order to remove a parent persistent node)
      return;
    }
    if (keepSet.contains(path.toString())) {
      try {
        ZooKeeperIface zk = getZk();

        byte[] data = zk.getData(path.toString(), false, null);

        if (data != null &&
          keyword.equals(ZkUtil.bytesToString(data))
          ) {
          zk.setData(path.toString(), new byte[0], -1);
        }

        List<String> children = zk.getChildren(path.toString(), null);
        for (String child : children) {
          internalPrunePersistent(path.appendChild(child), keyword, keepSet);
        }
      } catch (KeeperException.NoNodeException e) {
        // If the node disappears while scanning it, then just ignore
View Full Code Here

Examples of com.facebook.zookeeper.ZooKeeperIface

    }
  }

  private void deleteSubtree(ZkGenericPath path, String keyword)
    throws InterruptedException, KeeperException {
    ZooKeeperIface zk = getZk();
    try {
      if (!isEphemeral(path.toString())) {
        // Only set freeze on non-ephemerals since ephemerals cant have children
        zk.setData(
          path.toString(),
          ZkUtil.stringToBytes(keyword),
          -1
        );
      }

      while (true) {
        List<String> children = zk.getChildren(path.toString(), null);
        for (String child : children) {
          deleteSubtree(path.appendChild(child), keyword);
        }
        try {
          zk.delete(path.toString(), -1);
          break;
        } catch (KeeperException.NotEmptyException e) {
          // Repeat since children were re-added
        }
      }
View Full Code Here

Examples of com.facebook.zookeeper.ZooKeeperIface

    }
  }

  private boolean isEphemeral(String pathStr)
    throws InterruptedException, KeeperException {
    ZooKeeperIface zk = getZk();
    Stat stat = new Stat();
    zk.getData(pathStr, null, stat);
    return stat.getEphemeralOwner() != 0;
  }
View Full Code Here

Examples of com.facebook.zookeeper.ZooKeeperIface

    candidate.cycle();
  }

  @Override
  public String getLeader() throws InterruptedException, KeeperException { // TODO: add some way to watch for leader addition
    ZooKeeperIface zk = zkConnectionManager.getClient();
    List<String> candidateNames = getCandidateNames(zk);
    long leaderSeqNo = Long.MAX_VALUE;
    String leader = null;
    for (String candidateName : candidateNames) {
      long candidateSeqNo = pathFormat.extractSeqNo(candidateName);
View Full Code Here

Examples of com.facebook.zookeeper.ZooKeeperIface

      this.candidatePayload = candidatePayload;
    }

    public synchronized void enter()
      throws InterruptedException, KeeperException {
      ZooKeeperIface zk = zkConnectionManager.getClient();
      internalEnter(zk);
    }
View Full Code Here

Examples of com.facebook.zookeeper.ZooKeeperIface

      LOG.info("entering election for path " + candidatePath);
    }

    public synchronized void withdraw()
      throws InterruptedException, KeeperException {
      ZooKeeperIface zk = zkConnectionManager.getClient();
      internalWithdraw(zk);
    }
View Full Code Here

Examples of com.facebook.zookeeper.ZooKeeperIface

      }
    }

    public synchronized void cycle()
      throws InterruptedException, KeeperException {
      ZooKeeperIface zk = zkConnectionManager.getClient();
      internalWithdraw(zk);
      internalEnter(zk);
    }
View Full Code Here

Examples of com.facebook.zookeeper.ZooKeeperIface

          case NodeChildrenChanged:
          case NodeCreated:
          case NodeDataChanged:
            // Some irrelevant node event triggered the watch, need to re-set it
            try {
              ZooKeeperIface zk = zkConnectionManager.getClient();
              if (!setWatchIfNodeExists(zk, candidatePath, this)) {
                leaderElectionCallback.removed();
              }
            } catch (Exception e) {
              leaderElectionCallback.error(e);
View Full Code Here

Examples of com.facebook.zookeeper.ZooKeeperIface

          @Override
          public void run() {
            if (event.getType() != Event.EventType.None) {
              // Check for changes in predecessor and re-set watch if necessary.
              try {
                ZooKeeperIface zk = zkConnectionManager.getClient();
                monitor(zk);
              } catch (Exception e) {
                leaderElectionCallback.error(e);
              }
            }
View Full Code Here

Examples of com.facebook.zookeeper.ZooKeeperIface

    candidate.cycle();
  }

  @Override
  public String getLeader() throws InterruptedException, KeeperException { // TODO: add some way to watch for leader addition
    ZooKeeperIface zk = zkConnectionManager.getClient();
    List<String> candidateNames = getCandidateNames(zk);
    long leaderSeqNo = Long.MAX_VALUE;
    String leader = null;
    for (String candidateName : candidateNames) {
      long candidateSeqNo = pathFormat.extractSeqNo(candidateName);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.