由于zk客户端流程对于zk单机服务或者集群基本一致,所以先从zk客户端源码开始学习。
1、客户端启动
首先我们启动一个单机的server,然后给ZookeeperMain打上断点进入调试
//成员变量
private static final Logger LOG = LoggerFactory.getLogger(ZooKeeperMain.class);
//当前支持解析的command命令如ls等
static final Map<String, String> commandMap = new HashMap<String, String>();
static final Map<String, CliCommand> commandMapCli = new HashMap<String, CliCommand>();
protected MyCommandOptions cl = new MyCommandOptions();
//当前会话的历史命令---history命令就是从这个里面取
protected HashMap<Integer, String> history = new HashMap<Integer, String>();
protected int commandCount = 0;
protected boolean printWatches = true;
protected int exitCode = ExitCode.EXECUTION_FINISHED.getValue();
protected ZooKeeper zk;
protected String host = "";
private CountDownLatch connectLatch = null;</