gpt4 book ai didi

co.cask.cdap.common.zookeeper.ZKExtOperations类的使用及代码示例

转载 作者:知者 更新时间:2024-03-16 15:59:31 26 4
gpt4 key购买 nike

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

ZKExtOperations介绍

[英]Collection of common zk operations. NOTE: When this class is matured, we could move this into twill ZKOperations.
[中]常见zk操作的集合。注意:当这个类成熟时,我们可以将其转移到twill操作中。

代码示例

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

/**
 * Update the content of the given node. If the node doesn't exist, it will try to create the node. Same as calling
 *
 * {@link #updateOrCreate(ZKClient, String, Function, Codec, List)
 * updateOrCreate(zkClient, path, modifier, codec, null)}
 *
 * @see #updateOrCreate(ZKClient, String, Function, Codec, java.util.List)
 */
public static <V> ListenableFuture<V> updateOrCreate(ZKClient zkClient, String path,
                           Function<V, V> modifier, Codec<V> codec) {
 return updateOrCreate(zkClient, path, modifier, codec, null);
}

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

/**
 * Attempts to create a persistent node with the given content. If creation failed because the node already
 * exists ({@link KeeperException.NodeExistsException}), the node will be set with the given content.
 * This method is suitable for cases where the node expected to be non-existed.
 *
 * @param zkClient The ZKClient to perform the operations.
 * @param path The path in ZK.
 * @param dataSupplier The supplier to provide the content to be set to the node. The supplier may get invoked
 *                     multiple times when the actual data is needed for creating or setting the content of
 *                     the given node. The supplier can be invoked from the caller thread as well as the
 *                     zookeeper event callback thread.
 * @param codec A {@link Codec} for serializing the data into byte array.
 * @param maxFailure Maximum number of times to try to create/set the content.
 * @param acls The access control list to set on the node, if it is created.
 * @param <T> Type of the data.
 * @return A {@link ListenableFuture} that will be completed when node is created or data is set. The future will
 *         fail if failed to create and to set the data. Calling {@link ListenableFuture#cancel(boolean)} has
 *         no effect.
 */
public static <T> ListenableFuture<T> createOrSet(ZKClient zkClient, String path, Supplier<T> dataSupplier,
                         Codec<T> codec, int maxFailure, List<ACL> acls) {
 return createOrSetWithRetry(true, zkClient, path, dataSupplier, codec, acls, maxFailure);
}

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

/**
 * Submits the given {@link ResourceRequirement} for allocation.
 *
 * @param requirement The requirement to be submitted.
 * @return A {@link ListenableFuture} that will be completed when submission is completed and it'll carry the
 *         submitted requirement as result. The future will fail if failed to submit the requirement. Calling
 *         {@link ListenableFuture#cancel(boolean)} has no effect.
 */
public ListenableFuture<ResourceRequirement> submitRequirement(ResourceRequirement requirement) {
 String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + requirement.getName();
 return ZKExtOperations.createOrSet(zkClient, zkPath, Suppliers.ofInstance(requirement),
                   CoordinationConstants.RESOURCE_REQUIREMENT_CODEC,
                   CoordinationConstants.MAX_ZK_FAILURE_RETRY);
}

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

@Override
public ListenableFuture<T> set(String name, T property) {
 return ZKExtOperations.setOrCreate(zkClient, getPath(name), Suppliers.ofInstance(property),
                   codec, MAX_ZK_FAILURE_RETRIES);
}

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

final Codec<T> codec, @Nullable final Iterable<ACL> acls) {
final SettableFuture<T> resultFuture = SettableFuture.create();
final Supplier<ListenableFuture<T>> futureSupplier = createFutureSupplier(dataSupplier);
try {
  ? create(zkClient, path, futureSupplier, codec, acls, SettableFuture.<T>create())
  : setData(zkClient, path, dataSupplier, codec, SettableFuture.<T>create());

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

doCreateOrSet(createFirst, zkClient, path, dataSupplier, codec, acls),
new FutureCallback<T>() {
 @Override

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

ListenableFuture<V> createFuture = create(zkClient, path, new Supplier<ListenableFuture<V>>() {
 @Override
 public ListenableFuture<V> get() {

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

/**
 * Submits the given {@link ResourceRequirement} for allocation.
 *
 * @param requirement The requirement to be submitted.
 * @return A {@link ListenableFuture} that will be completed when submission is completed and it'll carry the
 *         submitted requirement as result. The future will fail if failed to submit the requirement. Calling
 *         {@link ListenableFuture#cancel(boolean)} has no effect.
 */
public ListenableFuture<ResourceRequirement> submitRequirement(ResourceRequirement requirement) {
 String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + requirement.getName();
 return ZKExtOperations.createOrSet(zkClient, zkPath, Suppliers.ofInstance(requirement),
                   CoordinationConstants.RESOURCE_REQUIREMENT_CODEC,
                   CoordinationConstants.MAX_ZK_FAILURE_RETRY);
}

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

@Override
public ListenableFuture<T> set(String name, T property) {
 return ZKExtOperations.setOrCreate(zkClient, getPath(name), Suppliers.ofInstance(property),
                   codec, MAX_ZK_FAILURE_RETRIES);
}

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

final Codec<T> codec, @Nullable final Iterable<ACL> acls) {
final SettableFuture<T> resultFuture = SettableFuture.create();
final Supplier<ListenableFuture<T>> futureSupplier = createFutureSupplier(dataSupplier);
try {
  ? create(zkClient, path, futureSupplier, codec, acls, SettableFuture.<T>create())
  : setData(zkClient, path, dataSupplier, codec, SettableFuture.<T>create());

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

doCreateOrSet(createFirst, zkClient, path, dataSupplier, codec, acls),
new FutureCallback<T>() {
 @Override

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

ListenableFuture<V> createFuture = create(zkClient, path, new Supplier<ListenableFuture<V>>() {
 @Override
 public ListenableFuture<V> get() {

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

@Override
public void store(final ProgramId serviceId, final RouteConfig routeConfig) {
 Supplier<RouteConfig> supplier = Suppliers.ofInstance(routeConfig);
 SettableFuture<RouteConfig> oldConfigFuture = routeConfigMap.get(serviceId);
 Future<RouteConfig> future = ZKExtOperations.createOrSet(zkClient, getZKPath(serviceId), supplier,
                              ROUTE_CONFIG_CODEC, 10);
 try {
  future.get(ZK_TIMEOUT_SECS, TimeUnit.SECONDS);
  SettableFuture<RouteConfig> newFuture = SettableFuture.create();
  newFuture.set(routeConfig);
  if (oldConfigFuture != null) {
   routeConfigMap.replace(serviceId, oldConfigFuture, newFuture);
  } else {
   routeConfigMap.putIfAbsent(serviceId, newFuture);
  }
 } catch (ExecutionException | InterruptedException | TimeoutException ex) {
  throw Throwables.propagate(ex);
 }
}

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

/**
 * Update the content of the given node. If the node doesn't exist, it will try to create the node. Same as calling
 *
 * {@link #updateOrCreate(ZKClient, String, AsyncFunction, Codec, List)
 * updateOrCreate(zkClient, path, modifier, codec, null)}
 *
 * @see #updateOrCreate(ZKClient, String, AsyncFunction, Codec, List)
 */
public static <V> ListenableFuture<V> updateOrCreate(ZKClient zkClient, String path,
                           AsyncFunction<V, V> modifier, Codec<V> codec) {
 return updateOrCreate(zkClient, path, modifier, codec, null);
}

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

Suppliers.ofInstance(assignmentName));
Futures.addCallback(
 ZKExtOperations.setOrCreate(zkClient, zkPath, dataSupplier, CoordinationConstants.RESOURCE_ASSIGNMENT_CODEC,
               CoordinationConstants.MAX_ZK_FAILURE_RETRY),
 new FutureCallback<ResourceAssignment>() {

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

/**
 * Attempts to create a persistent node with the given content. If creation failed because the node already
 * exists ({@link KeeperException.NodeExistsException}), the node will be set with the given content.
 * This method is suitable for cases where the node expected to be non-existed.
 *
 * @param zkClient The ZKClient to perform the operations.
 * @param path The path in ZK.
 * @param dataSupplier The supplier to provide the content to be set to the node. The supplier may get invoked
 *                     multiple times when the actual data is needed for creating or setting the content of
 *                     the given node. The supplier can be invoked from the caller thread as well as the
 *                     zookeeper event callback thread.
 * @param codec A {@link Codec} for serializing the data into byte array.
 * @param maxFailure Maximum number of times to try to create/set the content.
 * @param <T> Type of the data.
 * @return A {@link ListenableFuture} that will be completed when node is created or data is set. The future will
 *         fail if failed to create and to set the data. Calling {@link ListenableFuture#cancel(boolean)} has
 *         no effect.
 */
public static <T> ListenableFuture<T> createOrSet(ZKClient zkClient, String path, Supplier<T> dataSupplier,
                         Codec<T> codec, int maxFailure) {
 return createOrSetWithRetry(true, zkClient, path, dataSupplier, codec, null, maxFailure);
}

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

@Override
public void store(final ProgramId serviceId, final RouteConfig routeConfig) {
 Supplier<RouteConfig> supplier = Suppliers.ofInstance(routeConfig);
 SettableFuture<RouteConfig> oldConfigFuture = routeConfigMap.get(serviceId);
 Future<RouteConfig> future = ZKExtOperations.createOrSet(zkClient, getZKPath(serviceId), supplier,
                              ROUTE_CONFIG_CODEC, 10);
 try {
  future.get(ZK_TIMEOUT_SECS, TimeUnit.SECONDS);
  SettableFuture<RouteConfig> newFuture = SettableFuture.create();
  newFuture.set(routeConfig);
  if (oldConfigFuture != null) {
   routeConfigMap.replace(serviceId, oldConfigFuture, newFuture);
  } else {
   routeConfigMap.putIfAbsent(serviceId, newFuture);
  }
 } catch (ExecutionException | InterruptedException | TimeoutException ex) {
  throw Throwables.propagate(ex);
 }
}

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

/**
 * Update the content of the given node. If the node doesn't exist, it will try to create the node. Same as calling
 *
 * {@link #updateOrCreate(ZKClient, String, AsyncFunction, Codec, List)
 * updateOrCreate(zkClient, path, modifier, codec, null)}
 *
 * @see #updateOrCreate(ZKClient, String, AsyncFunction, Codec, List)
 */
public static <V> ListenableFuture<V> updateOrCreate(ZKClient zkClient, String path,
                           AsyncFunction<V, V> modifier, Codec<V> codec) {
 return updateOrCreate(zkClient, path, modifier, codec, null);
}

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

Suppliers.ofInstance(assignmentName));
Futures.addCallback(
 ZKExtOperations.setOrCreate(zkClient, zkPath, dataSupplier, CoordinationConstants.RESOURCE_ASSIGNMENT_CODEC,
               CoordinationConstants.MAX_ZK_FAILURE_RETRY),
 new FutureCallback<ResourceAssignment>() {

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

/**
 * Attempts to create a persistent node with the given content. If creation failed because the node already
 * exists ({@link KeeperException.NodeExistsException}), the node will be set with the given content.
 * This method is suitable for cases where the node expected to be non-existed.
 *
 * @param zkClient The ZKClient to perform the operations.
 * @param path The path in ZK.
 * @param dataSupplier The supplier to provide the content to be set to the node. The supplier may get invoked
 *                     multiple times when the actual data is needed for creating or setting the content of
 *                     the given node. The supplier can be invoked from the caller thread as well as the
 *                     zookeeper event callback thread.
 * @param codec A {@link Codec} for serializing the data into byte array.
 * @param maxFailure Maximum number of times to try to create/set the content.
 * @param acls The access control list to set on the node, if it is created.
 * @param <T> Type of the data.
 * @return A {@link ListenableFuture} that will be completed when node is created or data is set. The future will
 *         fail if failed to create and to set the data. Calling {@link ListenableFuture#cancel(boolean)} has
 *         no effect.
 */
public static <T> ListenableFuture<T> createOrSet(ZKClient zkClient, String path, Supplier<T> dataSupplier,
                         Codec<T> codec, int maxFailure, List<ACL> acls) {
 return createOrSetWithRetry(true, zkClient, path, dataSupplier, codec, acls, maxFailure);
}

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