本文整理了Java中org.apache.twill.zookeeper.ZKClient.exists()
方法的一些代码示例,展示了ZKClient.exists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKClient.exists()
方法的具体详情如下:
包路径:org.apache.twill.zookeeper.ZKClient
类名称:ZKClient
方法名:exists
[英]Checks if the path exists. Same as calling #exists(String,org.apache.zookeeper.Watcher).
[中]检查路径是否存在。与调用#exists相同(String,org.apache.zookeeper.Watcher)。
代码示例来源:origin: org.apache.twill/twill-zookeeper
@Override
public OperationFuture<Stat> exists(String path, @Nullable Watcher watcher) {
return client.exists(path, watcher);
}
代码示例来源:origin: apache/twill
@Override
public OperationFuture<Stat> exists(String path, @Nullable Watcher watcher) {
return delegate.exists(path, watcher);
}
代码示例来源:origin: apache/twill
@Override
public OperationFuture<Stat> exists(String path, @Nullable Watcher watcher) {
return client.exists(path, watcher);
}
代码示例来源:origin: org.apache.twill/twill-zookeeper
@Override
public OperationFuture<Stat> exists(String path, @Nullable Watcher watcher) {
return delegate.exists(path, watcher);
}
代码示例来源:origin: caskdata/coopr
/**
* Starts watching for the max. of smaller node.
*/
private void watchNode(final String nodePath, Watcher watcher) {
OperationFuture<Stat> watchFuture = zkClient.exists(nodePath, watcher);
Futures.addCallback(watchFuture, new FutureCallback<Stat>() {
@Override
public void onSuccess(Stat result) {
if (state != State.CANCELLED) {
becomeFollower();
}
}
@Override
public void onFailure(Throwable t) {
LOG.warn("Exception while setting watch on node {}. Retry.", nodePath, t);
runElection();
}
}, executor);
}
代码示例来源:origin: org.apache.twill/twill-zookeeper
/**
* Watch for the given path until it exists.
* @param zkClient The {@link ZKClient} to use.
* @param path A ZooKeeper path to watch for existent.
*/
private static void watchExists(final ZKClient zkClient, final String path, final SettableFuture<String> completion) {
Futures.addCallback(zkClient.exists(path, new Watcher() {
@Override
public void process(WatchedEvent event) {
if (!completion.isDone()) {
watchExists(zkClient, path, completion);
}
}
}), new FutureCallback<Stat>() {
@Override
public void onSuccess(Stat result) {
if (result != null) {
completion.set(path);
}
}
@Override
public void onFailure(Throwable t) {
completion.setException(t);
}
});
}
代码示例来源:origin: apache/twill
/**
* Watch for the given path until it exists.
* @param zkClient The {@link ZKClient} to use.
* @param path A ZooKeeper path to watch for existent.
*/
private static void watchExists(final ZKClient zkClient, final String path, final SettableFuture<String> completion) {
Futures.addCallback(zkClient.exists(path, new Watcher() {
@Override
public void process(WatchedEvent event) {
if (!completion.isDone()) {
watchExists(zkClient, path, completion);
}
}
}), new FutureCallback<Stat>() {
@Override
public void onSuccess(Stat result) {
if (result != null) {
completion.set(path);
}
}
@Override
public void onFailure(Throwable t) {
completion.setException(t);
}
});
}
代码示例来源:origin: org.apache.twill/twill-zookeeper
public static void watchDeleted(final ZKClient zkClient, final String path,
final SettableFuture<String> completion) {
Futures.addCallback(zkClient.exists(path, new Watcher() {
@Override
public void process(WatchedEvent event) {
if (!completion.isDone()) {
if (event.getType() == Event.EventType.NodeDeleted) {
completion.set(path);
} else {
watchDeleted(zkClient, path, completion);
}
}
}
}), new FutureCallback<Stat>() {
@Override
public void onSuccess(Stat result) {
if (result == null) {
completion.set(path);
}
}
@Override
public void onFailure(Throwable t) {
completion.setException(t);
}
});
}
代码示例来源:origin: apache/twill
public static void watchDeleted(final ZKClient zkClient, final String path,
final SettableFuture<String> completion) {
Futures.addCallback(zkClient.exists(path, new Watcher() {
@Override
public void process(WatchedEvent event) {
if (!completion.isDone()) {
if (event.getType() == Event.EventType.NodeDeleted) {
completion.set(path);
} else {
watchDeleted(zkClient, path, completion);
}
}
}
}), new FutureCallback<Stat>() {
@Override
public void onSuccess(Stat result) {
if (result == null) {
completion.set(path);
}
}
@Override
public void onFailure(Throwable t) {
completion.setException(t);
}
});
}
代码示例来源:origin: caskdata/cdap
/**
* Start watching for changes in resources requirements.
*/
private void beginWatch(final Watcher watcher) {
Futures.addCallback(zkClient.exists(CoordinationConstants.REQUIREMENTS_PATH, watcher),
wrapCallback(new FutureCallback<Stat>() {
@Override
public void onSuccess(Stat result) {
if (result != null) {
fetchAndProcessAllResources(watcher);
}
// If the node doesn't exists yet, that's ok, the watcher would handle it once it's created.
}
@Override
public void onFailure(Throwable t) {
// Something very wrong to have exists call failed.
LOG.error("Failed to call exists on ZK node {}{}",
zkClient.getConnectString(), CoordinationConstants.REQUIREMENTS_PATH, t);
doNotifyFailed(t);
}
}), executor);
}
代码示例来源:origin: co.cask.cdap/cdap-common
/**
* Start watching for changes in resources requirements.
*/
private void beginWatch(final Watcher watcher) {
Futures.addCallback(zkClient.exists(CoordinationConstants.REQUIREMENTS_PATH, watcher),
wrapCallback(new FutureCallback<Stat>() {
@Override
public void onSuccess(Stat result) {
if (result != null) {
fetchAndProcessAllResources(watcher);
}
// If the node doesn't exists yet, that's ok, the watcher would handle it once it's created.
}
@Override
public void onFailure(Throwable t) {
// Something very wrong to have exists call failed.
LOG.error("Failed to call exists on ZK node {}{}",
zkClient.getConnectString(), CoordinationConstants.REQUIREMENTS_PATH, t);
doNotifyFailed(t);
}
}), executor);
}
代码示例来源:origin: caskdata/cdap
private void existsAndWatch(final String name) {
Futures.addCallback(zkClient.exists(getPath(name), new Watcher() {
@Override
public void process(WatchedEvent event) {
代码示例来源:origin: apache/twill
@Override
public OperationFuture<Stat> exists(String path, @Nullable Watcher watcher) {
return relayFuture(delegate.exists(getNamespacedPath(path), watcher), this.<Stat>createFuture(path));
}
代码示例来源:origin: org.apache.twill/twill-zookeeper
@Override
public OperationFuture<Stat> exists(String path, @Nullable Watcher watcher) {
return relayFuture(delegate.exists(getNamespacedPath(path), watcher), this.<Stat>createFuture(path));
}
代码示例来源:origin: caskdata/cdap
/**
* Starts watch for assignment changes when the node exists.
*
* @param serviceName Name of the service.
*/
private void watchAssignmentOnExists(final String serviceName) {
final String zkPath = CoordinationConstants.ASSIGNMENTS_PATH + "/" + serviceName;
Watcher watcher = wrapWatcher(new AssignmentWatcher(serviceName, EnumSet.of(Watcher.Event.EventType.NodeCreated)));
Futures.addCallback(zkClient.exists(zkPath, watcher), wrapCallback(new FutureCallback<Stat>() {
@Override
public void onSuccess(Stat result) {
if (result != null) {
watchAssignment(serviceName);
}
}
@Override
public void onFailure(Throwable t) {
LOG.error("Failed to call exists on ZK {}{}", zkClient.getConnectString(), zkPath, t);
doNotifyFailed(t);
}
}), Threads.SAME_THREAD_EXECUTOR);
}
代码示例来源:origin: co.cask.cdap/cdap-common
/**
* Starts watch for assignment changes when the node exists.
*
* @param serviceName Name of the service.
*/
private void watchAssignmentOnExists(final String serviceName) {
final String zkPath = CoordinationConstants.ASSIGNMENTS_PATH + "/" + serviceName;
Watcher watcher = wrapWatcher(new AssignmentWatcher(serviceName, EnumSet.of(Watcher.Event.EventType.NodeCreated)));
Futures.addCallback(zkClient.exists(zkPath, watcher), wrapCallback(new FutureCallback<Stat>() {
@Override
public void onSuccess(Stat result) {
if (result != null) {
watchAssignment(serviceName);
}
}
@Override
public void onFailure(Throwable t) {
LOG.error("Failed to call exists on ZK {}{}", zkClient.getConnectString(), zkPath, t);
doNotifyFailed(t);
}
}), Threads.SAME_THREAD_EXECUTOR);
}
代码示例来源:origin: cdapio/cdap
public void init() throws InterruptedException {
this.watcher = new ZKWatcher();
try {
LOG.info("Initializing SharedResourceCache. Checking for parent znode {}", parentZnode);
if (zookeeper.exists(parentZnode).get() == null) {
// may be created in parallel by another instance
// Also the child nodes are secure even without adding any ACLs to parent node.
ZKOperations.ignoreError(zookeeper.create(parentZnode, null, CreateMode.PERSISTENT),
KeeperException.NodeExistsException.class, null).get();
}
} catch (ExecutionException ee) {
// recheck if already created
throw Throwables.propagate(ee.getCause());
}
this.resources = reloadAll();
listeners.notifyUpdate();
}
代码示例来源:origin: cdapio/cdap
private void existsAndWatch(final ProgramId serviceId, final SettableFuture<RouteConfig> oldSettableFuture) {
Futures.addCallback(zkClient.exists(getZKPath(serviceId), new Watcher() {
@Override
public void process(WatchedEvent event) {
// If service name doesn't exist in the map, then don't rewatch it.
if (!routeConfigMap.containsKey(serviceId)) {
return;
}
if (event.getType() == Event.EventType.NodeCreated) {
getAndWatchData(serviceId, SettableFuture.<RouteConfig>create(),
oldSettableFuture, new ZKRouteWatcher(serviceId));
}
}
}), new FutureCallback<Stat>() {
@Override
public void onSuccess(@Nullable Stat result) {
if (result != null) {
getAndWatchData(serviceId, SettableFuture.<RouteConfig>create(),
oldSettableFuture, new ZKRouteWatcher(serviceId));
}
}
@Override
public void onFailure(Throwable t) {
routeConfigMap.remove(serviceId);
LOG.debug("Failed to check exists for property data for {}", serviceId, t);
}
});
}
代码示例来源:origin: co.cask.cdap/cdap-app-fabric
private void existsAndWatch(final ProgramId serviceId, final SettableFuture<RouteConfig> oldSettableFuture) {
Futures.addCallback(zkClient.exists(getZKPath(serviceId), new Watcher() {
@Override
public void process(WatchedEvent event) {
// If service name doesn't exist in the map, then don't rewatch it.
if (!routeConfigMap.containsKey(serviceId)) {
return;
}
if (event.getType() == Event.EventType.NodeCreated) {
getAndWatchData(serviceId, SettableFuture.<RouteConfig>create(),
oldSettableFuture, new ZKRouteWatcher(serviceId));
}
}
}), new FutureCallback<Stat>() {
@Override
public void onSuccess(@Nullable Stat result) {
if (result != null) {
getAndWatchData(serviceId, SettableFuture.<RouteConfig>create(),
oldSettableFuture, new ZKRouteWatcher(serviceId));
}
}
@Override
public void onFailure(Throwable t) {
routeConfigMap.remove(serviceId);
LOG.debug("Failed to check exists for property data for {}", serviceId, t);
}
});
}
代码示例来源:origin: caskdata/coopr
private void initializeCounter(Type type) {
Stat stat = Futures.getUnchecked(zkClient.exists(type.path));
if (stat == null) {
Futures.getUnchecked(zkClient.create(type.path, Longs.toByteArray(startId), CreateMode.PERSISTENT, true));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!