Stat stat = curator.checkExists()
.usingWatcher((CuratorWatcher) event -> System.out.println(event)) // 单次监听器(NodeCreated/NodeDeleted/NodeDataChanged)
//.inBackground((cf, event) -> System.out.println(event.getStat())) // 使用异步
.forPath("/node");
boolean exists = stat != null;
int version = stat.getVersion();
long ctime = stat.getCtime();
long mtime = stat.getMtime();
long num = stat.getNumChildren();
// 可重入锁
InterProcessMutex lock = new InterProcessMutex(curator, "/lock");
// 非重入锁
InterProcessSemaphoreMutex lock = new InterProcessSemaphoreMutex(curator, "/lock");
// 可重入读写锁
InterProcessReadWriteLock readWriteLock = new InterProcessReadWriteLock(curator, "/lock");
var lock = readWriteLock.writeLock(); // readWriteLock.readLock();
// 组合锁(可重入锁/非重入锁)
InterProcessMultiLock lock = new InterProcessMultiLock(List.of(lock1, lock2));
// 获得锁
lock.acquire();
lock.acquire(10, TimeUnit.SECONDS);
// 锁状态
lock.isAcquiredInThisProcess();
//lock.isOwnedByCurrentThread();
// 释放锁
lock.release();
分布式计数器
DistributedAtomicLong atomic = new DistributedAtomicLong(curator, "/count", new RetryNTimes(10, 1000));
boolean succeeded = atomic.increment().succeeded();
long value = atomic.get().postValue();
POM
创建客户端
启动长连接(自动重连)
监听状态改变
创建节点
查询节点信息
查询节点数据与信息
更新节点数据
删除节点
查询子节点
使用事务
创建监听器 注意:需要ZooKeeper 3.6+
关闭连接
高级API
POM
缓存/持久监听器
注意:需要ZooKeeper 3.6+
分布式锁
分布式计数器
Leader选举