gpt4 book ai didi

org.lilyproject.util.zookeeper.ZooKeeperItf类的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 21:00:49 26 4
gpt4 key购买 nike

本文整理了Java中org.lilyproject.util.zookeeper.ZooKeeperItf类的一些代码示例,展示了ZooKeeperItf类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperItf类的具体详情如下:
包路径:org.lilyproject.util.zookeeper.ZooKeeperItf
类名称:ZooKeeperItf

ZooKeeperItf介绍

[英]An interface for ZooKeeper.
[中]ZooKeeper的界面。

代码示例

代码示例来源:origin: NGDATA/lilyproject

@Override
public List<String> getChildren(String path, Watcher watcher, Stat stat) throws KeeperException,
    InterruptedException {
  return wrapped.getChildren(path, watcher, stat);
}

代码示例来源:origin: NGDATA/lilyproject

@Override
public void addDefaultWatcher(Watcher watcher) {
  wrapped.addDefaultWatcher(watcher);
}

代码示例来源:origin: NGDATA/lilyproject

@Override
  public Stat execute() throws KeeperException, InterruptedException {
    return zk.exists(childPath, false);
  }
});

代码示例来源:origin: NGDATA/lilyproject

@Override
  public Boolean execute() throws KeeperException, InterruptedException {
    byte[] currentData = zk.getData(path, false, new Stat());
    if (!Arrays.equals(currentData, data)) {
      zk.setData(path, data, -1);
    }
    return null;
  }
});

代码示例来源:origin: NGDATA/lilyproject

@Override
  public Boolean execute() throws KeeperException, InterruptedException {
    if (zk.exists(subPath.toString(), false) == null) {
      try {
        zk.create(subPath.toString(), newData, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        return true;
      } catch (KeeperException.NodeExistsException e) {
        return false;
      }
    }
    return false;
  }
});

代码示例来源:origin: NGDATA/lilyproject

List<String> children = zk.getChildren(electionPath, watcher);
Stat stat = zk.exists(electionPath + "/" + leader, false);
if (stat.getEphemeralOwner() == zk.getSessionId() && !elected) {
  elected = true;
  log.info("Elected as leader for the position of " + position);

代码示例来源:origin: NGDATA/lilyproject

@Override
public byte[] getData(String path, Watcher watcher, Stat stat) throws KeeperException, InterruptedException {
  return wrapped.getData(path, watcher, stat);
}

代码示例来源:origin: NGDATA/lilyproject

retry = false;
try {
  currentServers.addAll(zk.getChildren(nodesPath, true));
} catch (KeeperException.NoNodeException e) {
  Stat stat = zk.exists(nodesPath, true);
  if (stat == null) {
    if (log.isInfoEnabled()) {

代码示例来源:origin: NGDATA/lilyproject

/**
 * Updates data on a zookeeper node.
 *
 * <p>
 * The supplied data is used for the last node in the path. The path must
 * already exist. It is not checked if the data is changed or not. This will
 * cause the version of the node to be increased.
 * <p>
 * This operation is retried until it succeeds.
 */
public static void update(final ZooKeeperItf zk, final String path, final byte[] data, final int version)
    throws InterruptedException, KeeperException {
  zk.retryOperation(new ZooKeeperOperation<Boolean>() {
    @Override
    public Boolean execute() throws KeeperException, InterruptedException {
      zk.setData(path, data, version);
      return null;
    }
  });
}

代码示例来源:origin: NGDATA/lilyproject

@Override
  public Boolean execute() throws KeeperException, InterruptedException {
    Stat stat = zk.exists(path, false);
    if (stat != null) {
      try {
        zk.delete(path, stat.getVersion());
      } catch (KeeperException.NoNodeException nne) {
        // This is ok, the node is already gone
      }
      // We don't catch BadVersion or NotEmpty as these are probably signs that there is something
      // unexpected going on with the node that is to be deleted
    }
    return true;
  }
});

代码示例来源:origin: NGDATA/lilyproject

@Override
  public String execute() throws KeeperException, InterruptedException {
    return zk.create(electionPath + "/n_", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);
  }
});

代码示例来源:origin: NGDATA/lilyproject

public void close() {
  zk.removeDefaultWatcher(zkWatcher);
  closed = true;
}

代码示例来源:origin: NGDATA/lilyproject

@Override
  public Boolean execute() throws KeeperException, InterruptedException {
    zk.setData(path, data, version);
    return null;
  }
});

代码示例来源:origin: NGDATA/lilyproject

@Override
public void close() throws IOException {
  this.isClosed = true;
  zk.removeDefaultWatcher(watcher);
  schemaCache.close();
  synchronized (this) {
    for (ServerNode node : servers) {
      node.close();
    }
    servers.clear();
  }
  if (managedZk && zk != null) {
    zk.close();
  }
  // Close pools related to the Configuration objects managed by this LilyClient instance
  for (Configuration config : hbaseConnections.getConfigurations()) {
    LocalHTable.closePool(config);
  }
  // Close HBase connections created by [only] this LilyClient instance.
  // This will almost always contain only one connection, if not we would need a more
  // advanced connection mgmt so that these connections don't stay open for the lifetime
  // of LilyClient.
  Closer.close(hbaseConnections);
}

代码示例来源:origin: NGDATA/lilyproject

if (zk.isCurrentThreadEventThread()) {
  throw new RuntimeException("ZkLock should not be used from within the ZooKeeper event thread.");
  zk.retryOperation(new ZooKeeperOperation<String>() {
    @Override
    public String execute() throws KeeperException, InterruptedException {
    List<ZkLockNode> children = parseChildren(zk.retryOperation(new ZooKeeperOperation<List<String>>() {
      @Override
      public List<String> execute() throws KeeperException, InterruptedException {
        Stat stat = zk.retryOperation(new ZooKeeperOperation<Stat>() {
          @Override
          public Stat execute() throws KeeperException, InterruptedException {
        if (stat != null && stat.getEphemeralOwner() == zk.getSessionId()) {
          if (myLockName != null) {
            zk.retryOperation(new ZooKeeperOperation<Object>() {
              @Override
              public Object execute() throws KeeperException, InterruptedException {
    final MyWatcher watcher = new MyWatcher(pathToWatch, condition);
    Stat stat = zk.retryOperation(new ZooKeeperOperation<Stat>() {
      @Override
      public Stat execute() throws KeeperException, InterruptedException {

代码示例来源:origin: NGDATA/lilyproject

/**
 * Verifies that the specified lockId is the owner of the lock.
 */
public static boolean ownsLock(final ZooKeeperItf zk, final String lockId) throws ZkLockException {
  if (zk.isCurrentThreadEventThread()) {
    throw new RuntimeException("ZkLock should not be used from within the ZooKeeper event thread.");
  }
  try {
    int lastSlashPos = lockId.lastIndexOf('/');
    final String lockPath = lockId.substring(0, lastSlashPos);
    String lockName = lockId.substring(lastSlashPos + 1);
    List<String> children = zk.retryOperation(new ZooKeeperOperation<List<String>>() {
      @Override
      public List<String> execute() throws KeeperException, InterruptedException {
        return zk.getChildren(lockPath, null);
      }
    });
    if (children.isEmpty()) {
      return false;
    }
    SortedSet<String> sortedChildren = new TreeSet<String>(children);
    return sortedChildren.first().equals(lockName);
  } catch (Throwable t) {
    throw new ZkLockException("Error checking lock, path: " + lockId, t);
  }
}

代码示例来源:origin: NGDATA/lilyproject

@Override
  public Object execute() throws KeeperException, InterruptedException {
    zk.delete(lockId, -1);
    return null;
  }
});

代码示例来源:origin: NGDATA/lilyproject

@Override
public void close() {
  wrapped.close();
}

代码示例来源:origin: NGDATA/lilyproject

@Override
public byte[] getData(String path, boolean watch, Stat stat) throws KeeperException, InterruptedException {
  return wrapped.getData(path, watch, stat);
}

代码示例来源:origin: NGDATA/lilyproject

/**
 * Deletes a path (non-recursively) in ZooKeeper, if it exists.
 * <p>
 * If the path doesn't exist, the delete will fail silently. The delete operation is retried until it succeeds, or
 * until it fails with a non-recoverable error.
 * <p>
 * If the path has children, the operation will fail with the underlying {@link NotEmptyException}.
 *
 * @param zk Handle to the ZooKeeper where the delete will occur
 * @param path The path to be deleted
 */
public static void deleteNode(final ZooKeeperItf zk, final String path) throws InterruptedException,
    KeeperException {
  zk.retryOperation(new ZooKeeperOperation<Boolean>() {
    @Override
    public Boolean execute() throws KeeperException, InterruptedException {
      Stat stat = zk.exists(path, false);
      if (stat != null) {
        try {
          zk.delete(path, stat.getVersion());
        } catch (KeeperException.NoNodeException nne) {
          // This is ok, the node is already gone
        }
        // We don't catch BadVersion or NotEmpty as these are probably signs that there is something
        // unexpected going on with the node that is to be deleted
      }
      return true;
    }
  });
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com