org.apache.pulsar.zookeeper.ZooKeeperCache.getDataAsync()方法的使用及代码示例

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

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

ZooKeeperCache.getDataAsync介绍

暂无

代码示例

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

public CompletableFuture<Optional<T>> getAsync(String path) {
  CompletableFuture<Optional<T>> future = new CompletableFuture<>();
  cache.getDataAsync(path, this, this).thenAccept(entry -> {
    future.complete(entry.map(Entry::getKey));
  }).exceptionally(ex -> {
    cache.asyncInvalidate(path);
    future.completeExceptionally(ex);
    return null;
  });
  return future;
}

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

public CompletableFuture<Optional<Entry<T, Stat>>> getWithStatAsync(String path) {
  return cache.getDataAsync(path, this, this).whenComplete((entry, ex) -> {
    if (ex != null) {
      cache.asyncInvalidate(path);
    }
  });
}

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

public <T> CompletableFuture<Optional<T>> getDataAsync(final String path, final Deserializer<T> deserializer) {
  CompletableFuture<Optional<T>> future = new CompletableFuture<>();
  getDataAsync(path, this, deserializer).thenAccept(data -> {
    future.complete(data.map(e -> e.getKey()));
  }).exceptionally(ex -> {
    asyncInvalidate(path);
    if (ex.getCause() instanceof NoNodeException) {
      future.complete(Optional.empty());
    } else {
      future.completeExceptionally(ex.getCause());
    }
    return null;
  });
  return future;
}

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

public <T> CompletableFuture<Optional<Entry<T, Stat>>> getEntryAsync(final String path, final Deserializer<T> deserializer) {
  CompletableFuture<Optional<Entry<T, Stat>>> future = new CompletableFuture<>();
  getDataAsync(path, this, deserializer)
    .thenAccept(future::complete)
    .exceptionally(ex -> {
      asyncInvalidate(path);
      if (ex.getCause() instanceof NoNodeException) {
        future.complete(Optional.empty());
      } else {
        future.completeExceptionally(ex.getCause());
      }
      return null;
    });
  return future;
}

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

protected static CompletableFuture<PartitionedTopicMetadata> fetchPartitionedTopicMetadataAsync(
    PulsarService pulsar, String path) {
  CompletableFuture<PartitionedTopicMetadata> metadataFuture = new CompletableFuture<>();
  try {
    // gets the number of partitions from the zk cache
    pulsar.getGlobalZkCache().getDataAsync(path, new Deserializer<PartitionedTopicMetadata>() {
      @Override
      public PartitionedTopicMetadata deserialize(String key, byte[] content) throws Exception {
        return jsonMapper().readValue(content, PartitionedTopicMetadata.class);
      }
    }).thenAccept(metadata -> {
      // if the partitioned topic is not found in zk, then the topic is not partitioned
      if (metadata.isPresent()) {
        metadataFuture.complete(metadata.get());
      } else {
        metadataFuture.complete(new PartitionedTopicMetadata());
      }
    }).exceptionally(ex -> {
      metadataFuture.completeExceptionally(ex);
      return null;
    });
  } catch (Exception e) {
    metadataFuture.completeExceptionally(e);
  }
  return metadataFuture;
}

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

final Deserializer<T> deserializer) throws Exception {
try {
  return getDataAsync(path, watcher, deserializer).get(cacheTimeOutInSec, TimeUnit.SECONDS);
} catch (ExecutionException e) {
  asyncInvalidate(path);

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

protected CompletableFuture<LookupResult> createLookupResult(String candidateBroker) throws Exception {
  CompletableFuture<LookupResult> lookupFuture = new CompletableFuture<>();
  try {
    checkArgument(StringUtils.isNotBlank(candidateBroker), "Lookup broker can't be null " + candidateBroker);
    URI uri = new URI(candidateBroker);
    String path = String.format("%s/%s:%s", LoadManager.LOADBALANCE_BROKERS_ROOT, uri.getHost(),
        uri.getPort());
    pulsar.getLocalZkCache().getDataAsync(path, pulsar.getLoadManager().get().getLoadReportDeserializer()).thenAccept(reportData -> {
      if (reportData.isPresent()) {
        ServiceLookupData lookupData = reportData.get();
        lookupFuture.complete(new LookupResult(lookupData.getWebServiceUrl(),
            lookupData.getWebServiceUrlTls(), lookupData.getPulsarServiceUrl(),
            lookupData.getPulsarServiceUrlTls()));
      } else {
        lookupFuture.completeExceptionally(new KeeperException.NoNodeException(path));
      }
    }).exceptionally(ex -> {
      lookupFuture.completeExceptionally(ex);
      return null;
    });
  } catch (Exception e) {
    lookupFuture.completeExceptionally(e);
  }
  return lookupFuture;
}

相关文章