CuratorFramework client = CuratorFrameworkFactory.newClient("zookeeper_server:2181", new ExponentialBackoffRetry(1000, 3)); client.start(); CuratorCache cache = CuratorCache.build(client, "/cache_path"); cache.start(); CuratorCacheListener listener = CuratorCacheListener.builder().forAll((type, oldData, data) -> { }).build(); cache.listenable().addListener(listener); cache.putData().forPath("/cache_path/key", "value".getBytes()); byte[] value = cache.getData().forPath("/cache_path/key"); cache.remove().forPath("/cache_path/key"); InterProcessMutex lock = new InterProcessMutex(client, "/lock_path"); if (lock.tryAcquire(5, TimeUnit.SECONDS)) { try { } finally { } } DistributedAtomicInteger counter = new DistributedAtomicInteger(client, "/counter_path", new RetryNTimes(3, 1000)); if (value.succeeded()) { System.out.println("Counter value: " + value.postValue()); } else { System.out.println("Counter increment failed."); } DistributedQueue<String> queue = QueueBuilder.builder(client, new StringSerializer(), "/queue_path").buildQueue();


上一篇:
下一篇:
切换中文