4.2 创建客户端
package com.atguigu.zk;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
public class ZKClientDemo {
private String conn = "hadoop201:2181,hadoop202:2181,hadoop203:2181";
private int sessionTime = 2000;
private ZooKeeper zkClient;
@Test
public void init() throws IOException {
zkClient = new ZooKeeper(conn, sessionTime, new Watcher() {
@Override
public void process(WatchedEvent watchedEvent) {
System.out.println(watchedEvent.getPath()
+ " --- " + watchedEvent.getType()
+ " --- " + watchedEvent.getState());
}
});
}
}