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相關的最後一篇博客

相關文章
相關標籤/搜索