- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
使用 curator treeCache
时,如何确保缓存准备就绪?
在 cache.start()
之后,如果我立即调用 getCurrentData
,它将返回 null
,那么如何确保缓存准备就绪?,有人可以给我举个例子吗?谢谢
client = CuratorFrameworkFactory.builder()
.connectString(connectionString)
.retryPolicy(new ExponentialBackoffRetry(zkConnectionTimeoutMs, 3))
.sessionTimeoutMs(zkSessionTimeoutMs)
.build();
client.start();
cache = new TreeCache(client, rootPath);
cache.start();
ChildData child = cache.getCurrentData(rootPath); // child is null
Thread.sleep(50); // must sleep for a while
child = cache.getCurrentData(rootPath); // child is ok
最佳答案
您可以为 Treecache 添加一个监听器并监听 INITIALIZED 事件。
Semaphore sem = new Semaphore(0);
client = CuratorFrameworkFactory.builder()
.connectString(connectionString)
.retryPolicy(new ExponentialBackoffRetry(zkConnectionTimeoutMs, 3))
.sessionTimeoutMs(zkSessionTimeoutMs)
.build();
client.start();
cache = new TreeCache(client, rootPath);
cache.start();
TreeCacheListener listener = new TreeCacheListener() {
@Override
public void childEvent(CuratorFramework client, TreeCacheEvent event)
throws Exception {
switch (event.getType()) {
case INITIALIZED: {
sem.release();
}
}
};
cache.getListenable().addListener(listener);
sem.acquire();
child = cache.getCurrentData(rootPath);
关于java - 使用 curator treeCache 时,如何确保缓存准备就绪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37825464/
有没有一种方法可以让我使用 Curator 来观察领导层的变化?当领导者改变时,我需要所有的追随者都知道这已经发生了,这样他们才能发现新的领导者是谁。追随者想知道领导者是谁,这似乎是一种标准,但我无法
给CuratorFrameworkFactory#newClient的连接字符串如何看起来像?到目前为止,我还没有在网上找到任何信息,JavaDoc 也没有告诉我正确的格式。 最佳答案 根据 this
本文整理了Java中org.apache.flink.shaded.curator.org.apache.curator.utils.ZKPaths类的一些代码示例,展示了ZKPaths类的具体用法。
本文整理了Java中org.apache.flink.shaded.curator.org.apache.curator.utils.ZKPaths.getNodeFromPath()方法的一些代码示
本文整理了Java中org.apache.flink.shaded.curator.org.apache.curator.utils.ZKPaths.deleteChildren()方法的一些代码示例
我正在尝试来自策展人的基本代码 http://curator.readthedocs.io/en/4.0/examples.html 我尝试 import elasticsearch import c
只是想知道是否有任何 API 可以使用 Curator Framework 中的 CuratorFramework 类来知道特定节点是领导者。我正在使用 LeaderLatch,但即使 Node 是领
Apache Curator library for ZooKeeper 使用了一个很好的“流畅”语法。例如,要修改事务中的多个节点,代码如下所示: client.inTransaction().
我正在尝试使用CLI探索Elasticsearch策展人 https://www.elastic.co/guide/en/elasticsearch/client/curator/current/in
使用Elasticsearch策展人,如何删除与模式匹配的所有索引,但最新的除外? 我尝试使用filtertype: age,但似乎无法满足我的需要。 最佳答案 您需要两个过滤器:pattern(以匹
我想删除超过 7 天的 Elasticsearch 索引。所以我安装了curator 4.2,因为我的elasticsearch版本是5.0.0(4.x之前的curator版本与elasticsear
场景: 使用Curator实现分布式互斥体。如果已经获取互斥量的客户端由于网络故障而与 zk 服务器断开连接,则 Curator 将尝试重新连接。假设最终重连成功,但是最后一个 session 已经过
我创建了一个 Curator 客户端,如下所示: RetryPolicy retryPolicy = new RetryNTimes(3, 1000); CuratorFramewor
创建路径时,我在以下代码中收到 NodeExists 错误。 CuratorTransaction transaction = curatorFramework.inTransaction(); tr
我已将 Curator 设置为通过此过滤器删除旧的 Elasticsearch 索引: (...) filters: - filtertype: pattern kind: regex val
我正在尝试测试 Apache Curator 中的可撤销锁定。我有两个尝试获取锁的线程。如果第一个测试获取了锁,第二个线程可以要求第一个线程释放锁,以便第二个线程可以获取它 Retry
我目前正在使用 Apache Curator 来外部化共享资源(数据库中的一行)的锁定。总结一下这个问题,我正在运行一个服务的 2 个实例(使用 Spring Boot),我们将其称为服务 A,并调用
我知道 Apache Curator 可以实现基于 zookeeper 的分布式锁功能。根据 Apache Curator 官方网站上发布的文档,它看起来非常容易使用。例如: RetryPolicy
本文整理了Java中org.apache.curator.utils.ZKPaths类的一些代码示例,展示了ZKPaths类的具体用法。这些代码示例主要来源于Github/Stackoverflow/
本文整理了Java中com.bazaarvoice.curator.dropwizard.ZooKeeperConfiguration类的一些代码示例,展示了ZooKeeperConfiguratio
我是一名优秀的程序员,十分优秀!