gpt4 book ai didi

org.apache.bookkeeper.util.ZkUtils.asyncCreateFullPathOptimistic()方法的使用及代码示例

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

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

ZkUtils.asyncCreateFullPathOptimistic介绍

[英]Asynchronously create zookeeper path recursively and optimistically.
[中]以递归和乐观的方式异步创建zookeeper路径。

代码示例

代码示例来源:origin: twitter/distributedlog

private void createDefaultAccessControlEntryIfNeeded(final Promise<ZKAccessControl> promise) {
  ZooKeeper zk;
  try {
    zk = zkc.get();
  } catch (ZooKeeperClient.ZooKeeperConnectionException e) {
    promise.setException(e);
    return;
  } catch (InterruptedException e) {
    promise.setException(e);
    return;
  }
  ZkUtils.asyncCreateFullPathOptimistic(zk, zkRootPath, new byte[0], zkc.getDefaultACL(),
      CreateMode.PERSISTENT, new AsyncCallback.StringCallback() {
    @Override
    public void processResult(int rc, String path, Object ctx, String name) {
      if (KeeperException.Code.OK.intValue() == rc) {
        logger.info("Created zk path {} for default ACL.", zkRootPath);
        fetchDefaultAccessControlEntry(promise);
      } else {
        promise.setException(KeeperException.create(KeeperException.Code.get(rc)));
      }
    }
  }, null);
}

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

private void createLongLedgerIdPathAndGenerateLongLedgerId(final GenericCallback<Long> cb, String createPath) {
  ZkUtils.asyncCreateFullPathOptimistic(zk, ledgerIdGenPath, new byte[0], Ids.OPEN_ACL_UNSAFE,
      CreateMode.PERSISTENT, new StringCallback() {
        @Override
        public void processResult(int rc, String path, Object ctx, String name) {
          try {
            setLedgerIdGenPathStatus(HighOrderLedgerIdGenPathStatus.PRESENT);
            generateLongLedgerId(cb);
          } catch (KeeperException e) {
            LOG.error("Failed to create long ledger ID path", e);
            setLedgerIdGenPathStatus(HighOrderLedgerIdGenPathStatus.UNKNOWN);
            cb.operationComplete(BKException.Code.ZKException, null);
          } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            LOG.error("Failed to create long ledger ID path", e);
            setLedgerIdGenPathStatus(HighOrderLedgerIdGenPathStatus.UNKNOWN);
            cb.operationComplete(BKException.Code.InterruptedException, null);
          } catch (IOException e) {
            LOG.error("Failed to create long ledger ID path", e);
            setLedgerIdGenPathStatus(HighOrderLedgerIdGenPathStatus.UNKNOWN);
            cb.operationComplete(BKException.Code.IllegalOpException, null);
          }
        }
      }, null);
}

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

public static void generateLedgerIdImpl(final GenericCallback<Long> cb, ZooKeeper zk, String ledgerPrefix,
    List<ACL> zkAcls) {
  ZkUtils.asyncCreateFullPathOptimistic(zk, ledgerPrefix, new byte[0], zkAcls,
      CreateMode.EPHEMERAL_SEQUENTIAL,
      new StringCallback() {

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

private void createDefaultAccessControlEntryIfNeeded(final CompletableFuture<ZKAccessControl> promise) {
  ZooKeeper zk;
  try {
    zk = zkc.get();
  } catch (ZooKeeperClient.ZooKeeperConnectionException e) {
    promise.completeExceptionally(e);
    return;
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    promise.completeExceptionally(e);
    return;
  }
  ZkUtils.asyncCreateFullPathOptimistic(zk, zkRootPath, new byte[0], zkc.getDefaultACL(),
      CreateMode.PERSISTENT, new AsyncCallback.StringCallback() {
    @Override
    public void processResult(int rc, String path, Object ctx, String name) {
      if (KeeperException.Code.OK.intValue() == rc) {
        logger.info("Created zk path {} for default ACL.", zkRootPath);
        fetchDefaultAccessControlEntry(promise);
      } else {
        promise.completeExceptionally(KeeperException.create(KeeperException.Code.get(rc)));
      }
    }
  }, null);
}

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

@Override
  public void processResult(int rc, String path, Object ctx, String name) {
    if (rc != Code.NONODE.intValue()) {
      callback.processResult(rc, path, ctx, name);
      return;
    }
    // Since I got a nonode, it means that my parents don't exist
    // create mode is persistent since ephemeral nodes can't be
    // parents
    String parent = new File(originalPath).getParent().replace("\\", "/");
    asyncCreateFullPathOptimistic(zk, parent, new byte[0], acl,
        CreateMode.PERSISTENT, new StringCallback() {
          @Override
          public void processResult(int rc, String path, Object ctx, String name) {
            if (rc == Code.OK.intValue() || rc == Code.NODEEXISTS.intValue()) {
              // succeeded in creating the parent, now
              // create the original path
              asyncCreateFullPathOptimistic(zk, originalPath, data,
                  acl, createMode, callback, ctx);
            } else {
              callback.processResult(rc, path, ctx, name);
            }
          }
        }, ctx);
  }
}, ctx);

代码示例来源:origin: org.apache.pulsar/pulsar-broker

@NotNull
private CompletableFuture<LocatorEntry> createSchemaLocator(String id, SchemaStorageFormat.SchemaLocator locator) {
  CompletableFuture<LocatorEntry> future = new CompletableFuture<>();
  ZkUtils.asyncCreateFullPathOptimistic(zooKeeper, id, locator.toByteArray(), Acl,
      CreateMode.PERSISTENT, (rc, path, ctx, name) -> {
        Code code = Code.get(rc);
        if (code != Code.OK) {
          future.completeExceptionally(KeeperException.create(code));
        } else {
          // Newly created z-node will have version 0
          future.complete(new LocatorEntry(locator, 0));
        }
      }, null);
  return future;
}

代码示例来源:origin: org.apache.pulsar/pulsar-broker

ZkUtils.asyncCreateFullPathOptimistic(localZkCache.getZooKeeper(), namespaceBundleZNode, znodeContent,
    Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, (rc, path, ctx, name) -> {
      if (rc == KeeperException.Code.OK.intValue()) {

代码示例来源:origin: com.yahoo.pulsar/pulsar-broker

ZkUtils.asyncCreateFullPathOptimistic(localZkCache.getZooKeeper(), namespaceBundleZNode, znodeContent,
    Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, (rc, path, ctx, name) -> {
      if (rc == KeeperException.Code.OK.intValue()) {

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger rc = new AtomicInteger(Code.OK.intValue());
asyncCreateFullPathOptimistic(zkc, path, data, acl, createMode,
               new StringCallback() {
                 @Override

代码示例来源:origin: org.apache.pulsar/pulsar-broker

ZkUtils.asyncCreateFullPathOptimistic(cache.getZooKeeper(), path, content, Ids.OPEN_ACL_UNSAFE,
    CreateMode.PERSISTENT, (rc, path1, ctx, name) -> {
      if (rc == KeeperException.Code.OK.intValue()

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

ZkUtils.asyncCreateFullPathOptimistic(zk, ledgerPath, data, zkAcls,
                   CreateMode.PERSISTENT, scb, null);
return promise;

代码示例来源:origin: com.yahoo.pulsar/pulsar-broker

ZkUtils.asyncCreateFullPathOptimistic(cache.getZooKeeper(), path, content, Ids.OPEN_ACL_UNSAFE,
    CreateMode.PERSISTENT, (rc, path1, ctx, name) -> {
      if (rc == KeeperException.Code.OK.intValue()

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

private void tryMarkLedgerUnderreplicatedAsync(final String znode,
                        final Collection<String> missingReplicas,
                        final List<ACL> zkAcls,
                        final CompletableFuture<Void> finalFuture) {
  final UnderreplicatedLedgerFormat.Builder builder = UnderreplicatedLedgerFormat.newBuilder();
  if (conf.getStoreSystemTimeAsLedgerUnderreplicatedMarkTime()) {
    builder.setCtime(System.currentTimeMillis());
  }
  missingReplicas.forEach(builder::addReplica);
  final byte[] urLedgerData = TextFormat.printToString(builder.build()).getBytes(UTF_8);
  ZkUtils.asyncCreateFullPathOptimistic(
    zkc, znode, urLedgerData, zkAcls, CreateMode.PERSISTENT,
    (rc, path, ctx, name) -> {
      if (Code.OK.intValue() == rc) {
        FutureUtils.complete(finalFuture, null);
      } else if (Code.NODEEXISTS.intValue() == rc) {
        // we need to handle the case where the ledger has been marked as underreplicated
        handleLedgerUnderreplicatedAlreadyMarked(znode, missingReplicas, zkAcls, finalFuture);
      } else {
        FutureUtils.completeExceptionally(finalFuture, KeeperException.create(Code.get(rc)));
      }
    }, null);
}

代码示例来源:origin: com.yahoo.pulsar/managed-ledger

@Override
public void getManagedLedgerInfo(final String ledgerName, final MetaStoreCallback<ManagedLedgerInfo> callback) {
  // Try to get the content or create an empty node
  zk.getData(prefix + ledgerName, false, (rc, path, ctx, readData, stat) -> executor.submit(safeRun(() -> {
    if (rc == Code.OK.intValue()) {
      try {
        ManagedLedgerInfo info = parseManagedLedgerInfo(readData);
        info = updateMLInfoTimestamp(info);
        callback.operationComplete(info, new ZKStat(stat));
      } catch (ParseException | InvalidProtocolBufferException e) {
        callback.operationFailed(new MetaStoreException(e));
      }
    } else if (rc == Code.NONODE.intValue()) {
      log.info("Creating '{}{}'", prefix, ledgerName);
      StringCallback createcb = (rc1, path1, ctx1, name) -> {
        if (rc1 == Code.OK.intValue()) {
          ManagedLedgerInfo info = ManagedLedgerInfo.getDefaultInstance();
          callback.operationComplete(info, new ZKStat());
        } else {
          callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc1))));
        }
      };
      ZkUtils.asyncCreateFullPathOptimistic(zk, prefix + ledgerName, new byte[0], Acl, CreateMode.PERSISTENT,
          createcb, null);
    } else {
      callback.operationFailed(new MetaStoreException(KeeperException.create(Code.get(rc))));
    }
  })), null);
}

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