gpt4 book ai didi

org.apache.twill.zookeeper.ZKClient.getData()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 01:44:49 25 4
gpt4 key购买 nike

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

ZKClient.getData介绍

[英]Gets the data stored in the given path. Same as calling #getData(String,org.apache.zookeeper.Watcher).
[中]

代码示例

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

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

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

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

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

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

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

@Override
public OperationFuture<NodeData> getData(String path, @Nullable Watcher watcher) {
 return delegate.getData(path, watcher);
}

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

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

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

@Override
public OperationFuture<NodeData> getData(String path, @Nullable Watcher watcher) {
 return delegate.getData(path, watcher);
}

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

/**
 * Starts watching for the max. of smaller node.
 */
private void watchNode(final String nodePath, Watcher watcher) {
 OperationFuture<NodeData> watchFuture = zkClient.getData(nodePath, watcher);
 Futures.addCallback(watchFuture, new FutureCallback<NodeData>() {
  @Override
  public void onSuccess(NodeData nodeData) {
   if (state != State.CANCELLED) {
    becomeFollower();
   }
  }
  @Override
  public void onFailure(Throwable t) {
   // On any kind of failure, just rerun the election.
   LOG.debug("Exception while setting watch on node {}. Retry.", nodePath, t);
   runElection();
  }
 }, executor);
}

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

private void getResource(String path, final FutureCallback<T> resourceCallback) {
 OperationFuture<NodeData> future = zookeeper.getData(path, watcher);
 Futures.addCallback(future, new FutureCallback<NodeData>() {
  @Override
  public void onSuccess(NodeData result) {
   T resource = null;
   try {
    resource = codec.decode(result.getData());
    resourceCallback.onSuccess(resource);
   } catch (IOException ioe) {
    resourceCallback.onFailure(ioe);
   }
  }
  @Override
  public void onFailure(Throwable t) {
   resourceCallback.onFailure(t);
  }
 });
}

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

/**
 * Starts watching for the max. of smaller node.
 */
private void watchNode(final String nodePath, Watcher watcher) {
 OperationFuture<NodeData> watchFuture = zkClient.getData(nodePath, watcher);
 Futures.addCallback(watchFuture, new FutureCallback<NodeData>() {
  @Override
  public void onSuccess(NodeData nodeData) {
   if (state != State.CANCELLED) {
    becomeFollower();
   }
  }
  @Override
  public void onFailure(Throwable t) {
   // On any kind of failure, just rerun the election.
   LOG.debug("Exception while setting watch on node {}. Retry.", nodePath, t);
   runElection();
  }
 }, executor);
}

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

/**
 * Acts as {@link ZKClient#getData(String, Watcher)} if node exists.
 * Otherwise sets {@code null} in returned future.
 */
public static ListenableFuture<NodeData> getDataOrNull(final ZKClient zkClient,
                            final String path,
                            @Nullable Watcher watcher) {
 return ignoreError(zkClient.getData(path, watcher), KeeperException.NoNodeException.class);
}

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

/**
 * Fetches the {@link ResourceRequirement} for the given resource.
 *
 * @param resourceName Name of the resource.
 * @return A {@link ListenableFuture} that will be completed when the requirement is fetch. A {@code null} result
 *         will be set into the future if no such requirement exists. The future will fail if failed to fetch
 *         the requirement due to error other than requirement not exists.
 *         Calling {@link ListenableFuture#cancel(boolean)} has no effect.
 */
public ListenableFuture<ResourceRequirement> fetchRequirement(String resourceName) {
 String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName;
 return Futures.transform(
  ZKOperations.ignoreError(zkClient.getData(zkPath), KeeperException.NoNodeException.class, null),
  NODE_DATA_TO_REQUIREMENT
 );
}

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

/**
 * Fetches the {@link ResourceRequirement} for the given resource.
 *
 * @param resourceName Name of the resource.
 * @return A {@link ListenableFuture} that will be completed when the requirement is fetch. A {@code null} result
 *         will be set into the future if no such requirement exists. The future will fail if failed to fetch
 *         the requirement due to error other than requirement not exists.
 *         Calling {@link ListenableFuture#cancel(boolean)} has no effect.
 */
public ListenableFuture<ResourceRequirement> fetchRequirement(String resourceName) {
 String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName;
 return Futures.transform(
  ZKOperations.ignoreError(zkClient.getData(zkPath), KeeperException.NoNodeException.class, null),
  NODE_DATA_TO_REQUIREMENT
 );
}

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

protected final void watchInstanceNode() {
 if (!shouldProcessZKEvent()) {
  return;
 }
 Futures.addCallback(zkClient.getData(getInstancePath(), new Watcher() {
  @Override
  public void process(WatchedEvent event) {
   if (!shouldProcessZKEvent()) {
    return;
   }
   switch (event.getType()) {
    case NodeDataChanged:
     watchInstanceNode();
     break;
    case NodeDeleted:
     instanceNodeFailed(KeeperException.create(KeeperException.Code.NONODE, getInstancePath()));
     break;
    default:
     LOG.info("Ignore ZK event for instance node: {}", event);
   }
  }
 }), instanceNodeDataCallback, Threads.SAME_THREAD_EXECUTOR);
}

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

protected final void watchInstanceNode() {
 if (!shouldProcessZKEvent()) {
  return;
 }
 Futures.addCallback(zkClient.getData(getInstancePath(), new Watcher() {
  @Override
  public void process(WatchedEvent event) {
   if (!shouldProcessZKEvent()) {
    return;
   }
   switch (event.getType()) {
    case NodeDataChanged:
     watchInstanceNode();
     break;
    case NodeDeleted:
     instanceNodeFailed(KeeperException.create(KeeperException.Code.NONODE, getInstancePath()));
     break;
    default:
     LOG.info("Ignore ZK event for instance node: {}", event);
   }
  }
 }), instanceNodeDataCallback, Threads.SAME_THREAD_EXECUTOR);
}

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

@Override
 public void updated(NodeChildren nodeChildren) {
  List<String> nodes = nodeChildren.getChildren();
  final Map<String, ListenableFuture<NodeData>> nodeAndDataFutures = Maps.newHashMap();
  List<OperationFuture<NodeData>> dataFutures = Lists.newArrayList();
  for (String node : nodes) {
   OperationFuture<NodeData> dataFuture = zkClient.getData(getNodePath(node));
   dataFutures.add(dataFuture);
   nodeAndDataFutures.put(node, dataFuture);
  }
  final ListenableFuture<List<NodeData>> fetchFuture = Futures.successfulAsList(dataFutures);
  fetchFuture.addListener(new Runnable() {
   @Override
   public void run() {
    ImmutableMap.Builder<String, T> builder = ImmutableMap.builder();
    for (Map.Entry<String, ListenableFuture<NodeData>> nodeAndData : nodeAndDataFutures.entrySet()) {
     T value = serializer.deserialize(Futures.getUnchecked(nodeAndData.getValue()).getData());
     builder.put(nodeAndData.getKey(), value);
    }
    currentView.set(builder.build());
    updateWaitingForElements();
   }
  }, Threads.SAME_THREAD_EXECUTOR);
 }
});

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

@Override
public OperationFuture<NodeData> getData(String path, @Nullable Watcher watcher) {
 return relayFuture(delegate.getData(getNamespacedPath(path), watcher), this.<NodeData>createFuture(path));
}

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

@Override
public OperationFuture<NodeData> getData(String path, @Nullable Watcher watcher) {
 return relayFuture(delegate.getData(getNamespacedPath(path), watcher), this.<NodeData>createFuture(path));
}

代码示例来源: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: caskdata/coopr

@Override
 public void updated(NodeChildren nodeChildren) {
  List<String> nodes = nodeChildren.getChildren();
  List<OperationFuture<NodeData>> dataFutures = Lists.newArrayList();
  for (String node : nodes) {
   dataFutures.add(zkClient.getData(getNodePath(node)));
  }
  final ListenableFuture<List<NodeData>> fetchFuture = Futures.successfulAsList(dataFutures);
  fetchFuture.addListener(new Runnable() {
   @Override
   public void run() {
    ImmutableList.Builder<T> builder = ImmutableList.builder();
    // fetchFuture is set by this time
    List<NodeData> nodesData = Futures.getUnchecked(fetchFuture);
    for (NodeData nodeData : nodesData) {
     builder.add(serializer.deserialize(nodeData.getData()));
    }
    currentView.set(builder.build());
   }
  }, Threads.SAME_THREAD_EXECUTOR);
 }
});

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

@Override
public boolean remove(Object o) {
 List<T> current = Lists.newArrayList(currentView.get());
 boolean removed = current.remove(o);
 if (removed) {
  currentView.set(ImmutableList.<T>builder().addAll(current).build());
 }
 // Hint: we can try to make removal more efficient if we keep map<nodeName->object> internally, or at least try to
 //       remove only when in-mem collection removed smth, but then we may face races...
 NodeChildren children = Futures.getUnchecked(ZKClientExt.getChildrenOrNull(zkClient, ""));
 if (children == null) {
  return false;
 }
 List<String> nodes = children.getChildren();
 for (String node : nodes) {
  byte[] data = Futures.getUnchecked(zkClient.getData(getNodePath(node))).getData();
  if (o.equals(serializer.deserialize(data))) {
   return Futures.getUnchecked(ZKClientExt.delete(zkClient, getNodePath(node), true)) != null;
  }
 }
 return removed;
}

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