ZooKeeper源码解析(四):client如何和server连接

客户端使用ClientCnxn和服务器端的ServerCnxn连接
客户端
ZooKeeper源码解析(四):client如何和server连接
sendThread负责向集群服务器发送请求,我们来看看它做了什么?
sendThread的run方法的关键代码:
ZooKeeper源码解析(四):client如何和server连接

ZooKeeper源码解析(四):client如何和server连接
我们再来看看eventThread的run方法
ZooKeeper源码解析(四):client如何和server连接
通过以上的分析我们不难发现客户端是从Outgoing queue取数据发出请求后,再将返回的请求塞入waitingqueue进行解析的,这就是客户端连接服务器端的过程。