标签:sse inf end ssi 运行 soc strong mil print
启动客户端 zkCli.sh文件里面的配置
实际运行
public static void main(String args[]) throws KeeperException, IOException, InterruptedException { ZooKeeperMain main = new ZooKeeperMain(args); main.run(); }
Main方法流程:
在ZookeeperMain的构造方法里面,重点是
public ZooKeeperMain(String args[]) throws IOException, InterruptedException { cl.parseOptions(args); System.out.println("Connecting to " + cl.getOption("server")); //连接上ZK connectToZK(cl.getOption("server")); }
protected void connectToZK(String newHost) throws InterruptedException, IOException { if (zk != null && zk.getState().isAlive()) { zk.close(); } host = newHost; boolean readOnly = cl.getOption("readonly") != null; zk = new ZooKeeper(host, Integer.parseInt(cl.getOption("timeout")), new MyWatcher(), readOnly); }
最终在connectToZK方法里面也就是使用原生的Zk客户端进行连接的。
public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws IOException { LOG.info("Initiating client connection, connectString=" + connectString + " sessionTimeout=" + sessionTimeout + " watcher=" + watcher); watchManager.defaultWatcher = watcher; ConnectStringParser connectStringParser = new ConnectStringParser( connectString); HostProvider hostProvider = new StaticHostProvider( connectStringParser.getServerAddresses()); cnxn = new ClientCnxn(connectStringParser.getChrootPath(), hostProvider, sessionTimeout, this, watchManager, //获得和服务端连接的对象 getClientCnxnSocket(), canBeReadOnly); //调用start() cnxn.start(); }
public void start() {
sendThread.start();
eventThread.start();
}
org.apache.zookeeper.ClientCnxn.SendThread#run
org.apache.zookeeper.ClientCnxn.EventThread.run
标签:sse inf end ssi 运行 soc strong mil print
原文地址:https://www.cnblogs.com/Soy-technology/p/11391746.html