我按照zk权威指南上的代码创建节点:
package com.zkstudy;
import java.io.IOException;
import java.util.Random;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
public class Master implements Watcher {
private ZooKeeper zk = null;
private String host;
private String serverId = null;
private boolean isLeader = false;
public Master(String host) {
this.host = host;
Random radom = new Random();
serverId = Integer.toHexString(radom.nextInt());
}
public void start() {
try {
this.zk