本文整理了Java中org.apache.pulsar.zookeeper.ZooKeeperCache.exists()
方法的一些代码示例,展示了ZooKeeperCache.exists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperCache.exists()
方法的具体详情如下:
包路径:org.apache.pulsar.zookeeper.ZooKeeperCache
类名称: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");
}
}
}
内容来源于网络,如有侵权,请联系作者删除!