gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-18 02:45:31 27 4
gpt4 key购买 nike

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

ZooKeeperCache.exists介绍

[英]Returns if the node at the given path exists in the cache
[中]返回给定路径上的节点是否存在于缓存中

代码示例

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

/**
 * Returns if the node at the given path exists in the cache
 *
 * @param path
 *            path of the node
 * @return true if node exists, false if it does not
 * @throws KeeperException
 * @throws InterruptedException
 */
public boolean exists(final String path) throws KeeperException, InterruptedException {
  return exists(path, this);
}

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

&& exists(path, watcher)) {
  return getChildren(path, watcher);
} else if (cause instanceof KeeperException) {

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

private void validatePoliciesReadOnlyAccess() {
  boolean arePoliciesReadOnly = true;
  ZooKeeperCache globalZkCache = configCache.cache();
  try {
    arePoliciesReadOnly = globalZkCache.exists(POLICIES_READONLY_FLAG_PATH);
  } catch (Exception e) {
    log.warn("Unable to fetch contents of [{}] from global zookeeper", POLICIES_READONLY_FLAG_PATH, e);
    throw new IllegalStateException("Unable to fetch content from global zk");
  }
  if (arePoliciesReadOnly) {
    if (log.isDebugEnabled()) {
      log.debug("Policies are read-only. Broker cannot do read-write operations");
    }
    throw new IllegalStateException("policies are in readonly mode");
  } else {
    // Make sure the broker is connected to the global zookeeper before writing. If not, throw an exception.
    if (globalZkCache.getZooKeeper().getState() != States.CONNECTED) {
      if (log.isDebugEnabled()) {
        log.debug("Broker is not connected to the global zookeeper");
      }
      throw new IllegalStateException("not connected woith global zookeeper");
    } else {
      // Do nothing, just log the message.
      log.debug("Broker is allowed to make read-write operations");
    }
  }
}

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

private void initZK() throws PulsarServerException {
  String[] paths = new String[] { MANAGED_LEDGER_ROOT, OWNER_INFO_ROOT, LOCAL_POLICIES_ROOT };
  // initialize the zk client with values
  try {
    ZooKeeper zk = cache.getZooKeeper();
    for (String path : paths) {
      if (cache.exists(path)) {
        continue;
      }
      try {
        ZkUtils.createFullPathOptimistic(zk, path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
      } catch (KeeperException.NodeExistsException e) {
        // Ok
      }
    }
  } catch (Exception e) {
    LOG.error(e.getMessage(), e);
    throw new PulsarServerException(e);
  }
}

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

private void setDynamicConfigurationToZK(String zkPath, Map<String, String> settings) throws IOException {
  byte[] settingBytes = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(settings);
  try {
    if (pulsar.getLocalZkCache().exists(zkPath)) {
      pulsar.getZkClient().setData(zkPath, settingBytes, -1);
    } else {
      ZkUtils.createFullPathOptimistic(pulsar.getZkClient(), zkPath, settingBytes, Ids.OPEN_ACL_UNSAFE,
          CreateMode.PERSISTENT);
    }
  } catch (Exception e) {
    log.warn("Got exception when writing to ZooKeeper path [{}]:", zkPath, e);
  }
}

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

/**
 * Checks whether the broker is allowed to do read-write operations based on the existence of a node in global
 * zookeeper.
 *
 * @throws WebApplicationException
 *             if broker has a read only access if broker is not connected to the global zookeeper
 */
public void validatePoliciesReadOnlyAccess() {
  boolean arePoliciesReadOnly = true;
  try {
    arePoliciesReadOnly = globalZkCache().exists(POLICIES_READONLY_FLAG_PATH);
  } catch (Exception e) {
    log.warn("Unable to fetch contents of [{}] from global zookeeper", POLICIES_READONLY_FLAG_PATH, e);
    throw new RestException(e);
  }
  if (arePoliciesReadOnly) {
    log.debug("Policies are read-only. Broker cannot do read-write operations");
    throw new RestException(Status.FORBIDDEN, "Broker is forbidden to do read-write operations");
  } else {
    // Make sure the broker is connected to the global zookeeper before writing. If not, throw an exception.
    if (globalZkCache().getZooKeeper().getState() != States.CONNECTED) {
      log.debug("Broker is not connected to the global zookeeper");
      throw new RestException(Status.PRECONDITION_FAILED,
          "Broker needs to be connected to global zookeeper before making a read-write operation");
    } else {
      // Do nothing, just log the message.
      log.debug("Broker is allowed to make read-write operations");
    }
  }
}

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