Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Basic use of zookeeper curator

Shulou Source: shulou.com Published: 2022-06-03 05:47:35 11月14日 Update

Below, we'll demonstrate curator's most basic crud functionality with a simple example:

maven dependency:

org.apache.zookeeper zookeeper 3.4.12 org.apache.curator curator-recipes 2.12.0 junit junit 4.12 test

Test Category:

package per.ym.zookeeper;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.BoundedExponentialBackoffRetry;import org.apache.curator.retry.ExponentialBackoffRetry;import org.apache.curator.retry.RetryForever;import org.apache.curator.retry.RetryNTimes;import org.apache.curator.retry.RetryOneTime;import org.apache.curator.retry.RetryUntilElapsed;import org.apache.zookeeper.data.Stat;import org.junit.After;import org.junit.Before;import org.junit.Test;public class CuratorBasicAPI { private CuratorFramework client; private String connectString = "192.168.61.131:2184"; private int sessionTimeoutMs = 60000; private int connectionTimeoutMs = 60000; private String path = "/test"; private String rootPath = "/"; private byte[] data = "data".getBytes(); private byte[] newData = "newData".getBytes(); private int baseSleepTimeMs = 1000; private int maxRetries = 3; @Before public void connect() { //baseSleepTimeMs: basal sleep time;maxRetries: maximum number of retries;maxSleepMs: maximum sleep time between retries //The formula for calculating sleep time is: sleepMs = baseSleepTimeMs * Math.max(1, random.nextInt(1

Tags: Node time data maximum sleep under root directory formula unit subclass sequence number of times version valid successful between function foundation that is method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Technology Shulou Tech Info OPPO Reno NVidia