gpt4 book ai didi

com.yahoo.pulsar.zookeeper.ZooKeeperCache.getZooKeeper()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 13:07:39 27 4
gpt4 key购买 nike

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

ZooKeeperCache.getZooKeeper介绍

暂无

代码示例

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

public ZooKeeper getZooKeeper() {
  return this.cache.getZooKeeper();
}

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

private void saveQuotaToZnode(String zpath, ResourceQuota quota) throws Exception {
  ZooKeeper zk = this.localZkCache.getZooKeeper();
  if (zk.exists(zpath, false) == null) {
    try {
      ZkUtils.createFullPathOptimistic(zk, zpath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (KeeperException.NodeExistsException e) {
    }
  }
  zk.setData(zpath, this.jsonMapper.writeValueAsBytes(quota), -1);
}

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

private void initZK() throws PulsarServerException {
  String[] paths = new String[] { CLUSTERS_ROOT, POLICIES_ROOT };
  // initialize the zk client with values
  try {
    ZooKeeper zk = cache.getZooKeeper();
    for (String path : paths) {
      try {
        if (zk.exists(path, false) == null) {
          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: com.yahoo.pulsar/pulsar-broker

protected ZooKeeper globalZk() {
  return pulsar().getGlobalZkCache().getZooKeeper();
}

代码示例来源:origin: com.yahoo.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: com.yahoo.pulsar/pulsar-broker

/**
 * Disable bundle in local cache and on zk
 * 
 * @param bundle
 * @throws Exception
 */
public void disableOwnership(NamespaceBundle bundle) throws Exception {
  String path = ServiceUnitZkUtils.path(bundle);
  updateBundleState(bundle, false);
  localZkCache.getZooKeeper().setData(path, jsonMapper.writeValueAsBytes(selfOwnerInfoDisabled), -1);
  ownershipReadOnlyCache.invalidate(path);
}

代码示例来源: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: 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: com.yahoo.pulsar/pulsar-broker

/**
 * Method to remove the ownership of local broker on the <code>NamespaceBundle</code>, if owned
 *
 */
public CompletableFuture<Void> removeOwnership(NamespaceBundle bundle) {
  CompletableFuture<Void> result = new CompletableFuture<>();
  String key = ServiceUnitZkUtils.path(bundle);
  localZkCache.getZooKeeper().delete(key, -1, (rc, path, ctx) -> {
    if (rc == KeeperException.Code.OK.intValue() || rc == KeeperException.Code.NONODE.intValue()) {
      LOG.info("[{}] Removed zk lock for service unit: {}", key, KeeperException.Code.get(rc));
      ownedBundlesCache.synchronous().invalidate(key);
      ownershipReadOnlyCache.invalidate(key);
      result.complete(null);
    } else {
      LOG.warn("[{}] Failed to delete the namespace ephemeral node. key={}", key,
          KeeperException.Code.get(rc));
      result.completeExceptionally(KeeperException.create(rc));
    }
  }, null);
  return result;
}

代码示例来源:origin: com.yahoo.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");
    }
  }
}

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

/**
 * update new bundle-range to LocalZk (create a new node if not present)
 *
 * @param nsname
 * @param nsBundles
 * @param callback
 * @throws Exception
 */
private void updateNamespaceBundles(NamespaceName nsname, NamespaceBundles nsBundles, StatCallback callback)
    throws Exception {
  checkNotNull(nsname);
  checkNotNull(nsBundles);
  String path = joinPath(LOCAL_POLICIES_ROOT, nsname.toString());
  Optional<LocalPolicies> policies = pulsar.getLocalZkCacheService().policiesCache().get(path);
  if (!policies.isPresent()) {
    // if policies is not present into localZk then create new policies
    this.pulsar.getLocalZkCacheService().createPolicies(path, false).get(cacheTimeOutInSec, SECONDS);
    policies = this.pulsar.getLocalZkCacheService().policiesCache().get(path);
  }
  policies.get().bundles = getBundlesData(nsBundles);
  this.pulsar.getLocalZkCache().getZooKeeper().setData(path,
      ObjectMapperFactory.getThreadLocal().writeValueAsBytes(policies.get()), -1, callback, null);
}

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

ZkUtils.createFullPathOptimistic(pulsar.getLocalZkCache().getZooKeeper(), ELECTION_ROOT,
    jsonMapper.writeValueAsBytes(leaderBroker), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);

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

localZkConnectionSvc.start(exitCode -> {
  try {
    localZkCache.getZooKeeper().close();
  } catch (InterruptedException e) {
    log.warn("Failed to shutdown ZooKeeper gracefully {}", e.getMessage(), e);

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

/**
 * Default constructor.
 *
 * @throws PulsarServerException
 */
public NamespaceService(PulsarService pulsar) {
  this.pulsar = pulsar;
  host = pulsar.getAdvertisedAddress();
  this.config = pulsar.getConfiguration();
  this.loadManager = pulsar.getLoadManager();
  ServiceUnitZkUtils.initZK(pulsar.getLocalZkCache().getZooKeeper(), pulsar.getBrokerServiceUrl());
  this.bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
  this.ownershipCache = new OwnershipCache(pulsar, bundleFactory);
}

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