Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use Curator Framework

Shulou Source: shulou.com Published: 2022-05-31 12:22:24 11月14日 Update

This article mainly introduces the relevant knowledge of "how to use Curator Framework". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use Curator Framework" can help you solve the problem.

Framework is relatively simple, just some CRUD,Watch:

Package curator.framework;import java.util.List;import org.apache.curator.RetryPolicy;import org.apache.curator.framework.CuratorFramework;import org.apache.curator.framework.CuratorFrameworkFactory;import org.apache.curator.retry.ExponentialBackoffRetry;import org.apache.zookeeper.CreateMode;public class FrameworkDemo {public static void main (String [] args) {connection1 ();} private static void connection1 () {RetryPolicy retryPolicy = new ExponentialBackoffRetry (1000, 3) CuratorFramework client = CuratorFrameworkFactory.builder () .connectString ("127.0.0.1purl 2181") .sessionTimeoutMs (5000) .connectionTimeoutMs (10000) .retryPolicy (retryPolicy) .namespace ("text") .build () Client.start (); try {byte [] b = null; / / create client.create () .withMode (CreateMode.EPHEMERAL) .forPath ("/ xx", new String (") .getBytes ()) / / get the value client.getData () .forPath (""); / / get the child node List List ls = client.getChildren () .forPath (""); / / delete client.delete () .forPath ("") / / modify client.setData () .forPath ("", b);} catch (Exception e) {} client.close ();} private static void connection2 () {RetryPolicy retryPolicy = new ExponentialBackoffRetry (1000, 3) CuratorFramework client = CuratorFrameworkFactory.newClient ("127.0.0.1 client.start 2181", retryPolicy); client.start (); client.close ();}} that's all for "how to use CuratorFramework". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Knowledge industry different practical content practical that is articles methods more cases knowledge points articles nodes information channels processes problems channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi OPPO Reno Apple Xiaomi