Zookeeper:zookeeper源码笔记

前言:html

https://gitee.com/suyujie/zookeeper-test.gitnode

最近在找工做,以前在使用zookeeper,上手太容易了,因此以为没啥特别东西,但后来面试的时候,面试官问了zookeeper的不少东西,才发现这东西不是像咱们使用的时候那样简单,因此我花了时间研究了一下,并写了这篇博客,上面是我研究zookeeperAPI的一个小demo,代码小细节没有去琢磨,但能够供各位参考,但愿能够帮助各位学到东西,也但愿大牛看到了能够提出建议供相互学习,期间出现的问题,我会在本博客中写出来git

1、zookeeper中随处可见的@InterfaceAudience标签面试

zookeeper中不少代码中都包含了@InterfaceAudience.Public的标签,我稍微看了一下,这个标签的定义是在audience-annotations的包里定义的,同时@IntefaceAudience还有其余的值,我百度了一下,这个标签是用来标识这个类的做用域的,整理以下:app

@InterfaceAudience.Public:做用域在全部的工程和应用(Intended for use by any project or application)tcp

@InterfaceAudience.LimitedPrivate:做用域在本项目的衍生外围项目(Intended only for the project(s) specified in the annotation.For example, "Hadoop Common", "HDFS", "MapReduce", "Zookeeper", "HBase")oop

@InterfaceAudience.Private:做用域在本项目中(Intended for use only within a given project)学习

2、zookeeper开发中出现的问题.net

具体的代码我已经放到了码云上了htm

我出现的问题主要在链接zookeeper上,网上的建议是关闭防火墙,但这个方法太过于简单粗暴,实际确定是不可行的,因此要开放zookeeper的端口号,

网上找到的: iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j  ACCEPT

我平时习惯使用的:iptables -A INPUT -p tcp --dport 2181 -j ACCEPT

3、常量简单罗列

一、节点建立模式,总共有如下四类

CreateMode.PERSISTENT:持久,当client端关闭,这个节点将不会自动删除(The znode will not be automatically deleted upon client's disconnect)

CreateMode.PERSISTENT_SEQUENTAL:持久队列,当client端关闭,这个节点将不会自动删除,它的名称后面将跟着一个单调增长的数字(The znode will not be automatically deleted upon client's disconnect. and its name will be appended with a monotonically increasing number)

CreateMode.EPHEMERAL:临时,当client端关闭,这个节点将自动删除(The znode will be deleted upon client's disconnect)

CreateMode.EPHEMERAL_SEQUENTAL:临时队列,当client端关闭,这个节点将自动删除,它的名称后面将跟着一个单调增长的数字(The znode will be deleted upon client's disconnect. and its name will be appended with a monotonically increasing number)

 

待续。。。

 

更多参考:https://www.w3cschool.cn/zookeeper/zookeeper_overview.html

 

第一篇:http://www.javashuo.com/article/p-qiwiozjk-gn.html

上一篇:http://www.javashuo.com/article/p-qiwiozjk-gn.html

下一篇:本篇博客为zookeeper相关的最后一篇博客