org.apache.twill.zookeeper.ZKClient类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(197)

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

ZKClient介绍

[英]A ZooKeeper client that provides asynchronous zookeeper operations.
[中]ZooKeeper客户端,提供异步ZooKeeper操作。

代码示例

代码示例来源:origin: org.apache.twill/twill-core

@Override
 public void run() {
  logIfFailed(zkClient.delete(path, version));
 }
};

代码示例来源:origin: org.apache.twill/twill-zookeeper

@Override
public OperationFuture<Stat> exists(String path, @Nullable Watcher watcher) {
 return client.exists(path, watcher);
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

@Override
public OperationFuture<String> create(String path, @Nullable byte[] data,
                   CreateMode createMode, boolean createParent, Iterable<ACL> acl) {
 return delegate.create(path, data, createMode, createParent, acl);
}

代码示例来源:origin: caskdata/coopr

private void initializeCounter(Type type) {
  Stat stat = Futures.getUnchecked(zkClient.exists(type.path));
  if (stat == null) {
   Futures.getUnchecked(zkClient.create(type.path, Longs.toByteArray(startId), CreateMode.PERSISTENT, true));
  }
 }
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

@Override
 public OperationFuture<NodeData> exec(String path, Watcher watcher) {
  return zkClient.getData(path, watcher);
 }
}, path, callback, cancelled);

代码示例来源:origin: org.apache.twill/twill-core

private OperationFuture<String> removeLiveNode() {
 String liveNode = getLiveNodePath();
 LOG.info("Remove live node {}{}", zkClient.getConnectString(), liveNode);
 return ZKOperations.ignoreError(zkClient.delete(liveNode), KeeperException.NoNodeException.class, liveNode);
}

代码示例来源:origin: caskdata/cdap

@Override
 public void onFailure(Throwable t) {
  // Just log
  LOG.error("Failed to getData on ZK node {}{}", zkClient.getConnectString(), path, t);
 }
}), executor);

代码示例来源:origin: org.apache.twill/twill-yarn

@Override
protected void startUp() throws Exception {
 LOG.info("Creating container ZK path: {}{}", zkClient.getConnectString(), path);
 ZKOperations.ignoreError(zkClient.create(path, null, CreateMode.PERSISTENT),
              KeeperException.NodeExistsException.class, null).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}

代码示例来源:origin: apache/twill

@Override
 public OperationFuture<NodeChildren> exec(String path, Watcher watcher) {
  return zkClient.getChildren(path, watcher);
 }
}, path, callback, cancelled);

代码示例来源:origin: org.apache.twill/twill-core

watcherCancellable = zkClient.addConnectionWatcher(new Watcher() {
 private boolean expired = false;
ZKOperations.ignoreError(zkClient.create(getZKPath("messages"), null, CreateMode.PERSISTENT),
             KeeperException.NodeExistsException.class, null).get();

代码示例来源:origin: org.apache.twill/twill-core

/**
 * Update the live node for the service.
 *
 * @return A {@link OperationFuture} that will be completed when the update is done.
 */
protected final OperationFuture<?> updateLiveNode() {
 String liveNodePath = getLiveNodePath();
 LOG.info("Update live node {}{}", zkClient.getConnectString(), liveNodePath);
 return zkClient.setData(liveNodePath, serializeLiveNode());
}

代码示例来源:origin: caskdata/coopr

private long generateId(Type type) {
 idLock.get().lock();
 try {
  NodeData nodeData = Futures.getUnchecked(zkClient.getData(type.path));
  long counterVal = Longs.fromByteArray(nodeData.getData());
  Futures.getUnchecked(zkClient.setData(type.path, Longs.toByteArray(counterVal + incrementBy)));
  return counterVal;
 } finally {
  idLock.get().unlock();
 }
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

@Override
public Cancellable addConnectionWatcher(Watcher watcher) {
 return delegate.addConnectionWatcher(watcher);
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

@Override
public OperationFuture<Stat> setData(String dataPath, byte[] data, int version) {
 return delegate.setData(dataPath, data, version);
}

代码示例来源:origin: cdapio/cdap

public void init() throws InterruptedException {
 this.watcher = new ZKWatcher();
 try {
  LOG.info("Initializing SharedResourceCache.  Checking for parent znode {}", parentZnode);
  if (zookeeper.exists(parentZnode).get() == null) {
   // may be created in parallel by another instance
   // Also the child nodes are secure even without adding any ACLs to parent node.
   ZKOperations.ignoreError(zookeeper.create(parentZnode, null, CreateMode.PERSISTENT),
                KeeperException.NodeExistsException.class, null).get();
  }
 } catch (ExecutionException ee) {
  // recheck if already created
  throw Throwables.propagate(ee.getCause());
 }
 this.resources = reloadAll();
 listeners.notifyUpdate();
}

代码示例来源:origin: apache/twill

@Override
 public OperationFuture<NodeData> exec(String path, Watcher watcher) {
  return zkClient.getData(path, watcher);
 }
}, path, callback, cancelled);

代码示例来源:origin: apache/twill

private OperationFuture<String> removeLiveNode() {
 String liveNode = getLiveNodePath();
 LOG.info("Remove live node {}{}", zkClient.getConnectString(), liveNode);
 return ZKOperations.ignoreError(zkClient.delete(liveNode), KeeperException.NoNodeException.class, liveNode);
}

代码示例来源:origin: co.cask.cdap/cdap-common

@Override
 public void onFailure(Throwable t) {
  // Something very wrong to have exists call failed.
  LOG.error("Failed to call exists on ZK node {}{}",
       zkClient.getConnectString(), CoordinationConstants.REQUIREMENTS_PATH, t);
  doNotifyFailed(t);
 }
}), executor);

代码示例来源:origin: apache/twill

@Override
protected void startUp() throws Exception {
 LOG.info("Creating container ZK path: {}{}", zkClient.getConnectString(), path);
 ZKOperations.ignoreError(zkClient.create(path, null, CreateMode.PERSISTENT),
              KeeperException.NodeExistsException.class, null).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

@Override
 public OperationFuture<NodeChildren> exec(String path, Watcher watcher) {
  return zkClient.getChildren(path, watcher);
 }
}, path, callback, cancelled);

相关文章