Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Curator Framework

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report