Zookeeper Watcher 鏈哄埗 -- 鏁版嵁鍙樻洿閫氱煡 ?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zookeeper Watcher 鏈哄埗 -- 鏁版嵁鍙樻洿閫氱煡 ?相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/getchild' title='getchild'>getchild
澶勭悊 涓嶅悓 create exist watcher event 鍛婅瘔 鏀瑰彉Zookeeper 鍏佽瀹㈡埛绔悜鏈嶅姟绔殑鏌愪釜 Znode 娉ㄥ唽涓€涓?Watcher 鐩戝惉锛屽綋鏈嶅姟
绔殑涓€浜涙寚瀹氫簨浠惰Е鍙戜簡杩欎釜 Watcher锛屾湇鍔$浼氬悜鎸囧畾瀹㈡埛绔彂閫佷竴涓簨浠堕€?/p>
鐭ユ潵瀹炵幇鍒嗗竷寮忕殑閫氱煡鍔熻兘锛岀劧鍚庡鎴风鏍规嵁 Watcher 閫氱煡鐘舵€佸拰浜嬩欢绫诲瀷鍋氬嚭
涓氬姟涓婄殑鏀瑰彉銆?/span>
宸ヤ綔鏈哄埗锛?/span>
1銆佸鎴风娉ㄥ唽 watcher
2銆佹湇鍔$澶勭悊 watcher
3銆佸鎴风鍥炶皟 watcher
Watcher 鐗规€ф€荤粨锛?/span>
1銆佷竴娆℃€?/p>
鏃犺鏄湇鍔$杩樻槸瀹㈡埛绔紝涓€鏃︿竴涓?/span> Watcher 琚Е鍙戯紝Zookeeper 閮戒細灏嗗叾浠庣浉
搴旂殑瀛樺偍涓Щ闄ゃ€傝繖鏍风殑璁捐鏈夋晥鐨勫噺杞讳簡鏈嶅姟绔殑鍘嬪姏锛屼笉鐒跺浜庢洿鏂伴潪甯搁
绻佺殑鑺傜偣锛屾湇鍔$浼氫笉鏂殑鍚戝鎴风鍙戦€佷簨浠堕€氱煡锛屾棤璁哄浜庣綉缁滆繕鏄湇鍔$鐨?/span>
鍘嬪姏閮介潪甯稿ぇ銆?/span>
2銆佸鎴风涓茶鎵ц
瀹㈡埛绔?/span> Watcher 鍥炶皟鐨勮繃绋嬫槸涓€涓覆琛屽悓姝ョ殑杩囩▼銆?/p>
3銆佽交閲?/p>
3.1銆乄atcher 閫氱煡闈炲父绠€鍗曪紝鍙細鍛婅瘔瀹㈡埛绔彂鐢熶簡浜嬩欢锛岃€屼笉浼氳鏄庝簨浠剁殑鍏?/p>
浣撳唴瀹广€?/span> 3.2銆佸鎴风鍚戞湇鍔$娉ㄥ唽 Watcher 鐨勬椂鍊欙紝骞朵笉浼氭妸瀹㈡埛绔湡瀹炵殑 Watcher 瀵?/p>
璞″疄浣撲紶閫掑埌鏈嶅姟绔紝浠呬粎鏄湪瀹㈡埛绔姹備腑浣跨敤 boolean 绫诲瀷灞炴€ц繘琛屼簡鏍囪銆?/p>
4銆亀atcher event 寮傛鍙戦€?watcher 鐨勯€氱煡浜嬩欢浠?server 鍙戦€佸埌 client 鏄紓姝?/p>
鐨勶紝杩欏氨瀛樺湪涓€涓棶棰橈紝涓嶅悓鐨勫鎴风鍜屾湇鍔″櫒涔嬮棿閫氳繃 socket 杩涜閫氫俊锛岀敱浜?/p>
缃戠粶寤惰繜鎴栧叾浠栧洜绱犲鑷村鎴风鍦ㄤ笉閫氱殑鏃跺埢鐩戝惉鍒颁簨浠讹紝鐢变簬 Zookeeper 鏈韩 鎻愪緵浜?/span> ordering guarantee锛屽嵆瀹㈡埛绔洃鍚簨浠跺悗锛屾墠浼氭劅鐭ュ畠鎵€鐩戣 znode 鍙戠敓浜嗗彉鍖栥€傛墍浠ユ垜浠娇鐢?/span> Zookeeper 涓嶈兘鏈熸湜鑳藉鐩戞帶鍒拌妭鐐规瘡娆$殑鍙樺寲銆?/p>
Zookeeper 鍙兘淇濊瘉鏈€缁堢殑涓€鑷存€э紝鑰屾棤娉曚繚璇佸己涓€鑷存€с€?/p>
5銆佹敞鍐?watcher getData銆乪xists銆乬etChildren 6銆佽Е鍙?watcher create銆乨elete銆乻etData 7銆佸綋涓€涓鎴风杩炴帴鍒颁竴涓柊鐨勬湇鍔″櫒涓婃椂锛寃atch 灏嗕細琚互浠绘剰浼氳瘽浜嬩欢瑙﹀彂銆?/p>
褰撲笌涓€涓湇鍔″櫒澶卞幓杩炴帴鐨勬椂鍊欙紝鏄棤娉曟帴鏀跺埌 watch 鐨勩€傝€屽綋 client 閲嶆柊杩炴帴 鏃讹紝濡傛灉闇€瑕佺殑璇濓紝鎵€鏈夊厛鍓嶆敞鍐岃繃鐨?/span> watch锛岄兘浼氳閲嶆柊娉ㄥ唽銆傞€氬父杩欐槸瀹屽叏 閫忔槑鐨勩€傚彧鏈夊湪涓€涓壒娈婃儏鍐典笅锛?/span>watch 鍙兘浼氫涪澶憋細瀵逛簬涓€涓湭鍒涘缓鐨?znode 鐨?/span> exist watch锛屽鏋滃湪瀹㈡埛绔柇寮€杩炴帴鏈熼棿琚垱寤轰簡锛屽苟涓旈殢鍚庡湪瀹㈡埛绔繛鎺ヤ笂 涔嬪墠鍙堝垹闄や簡锛岃繖绉嶆儏鍐典笅锛岃繖涓?/span> watch 浜嬩欢鍙兘浼氳涓㈠け銆?/p>
以上是关于Zookeeper Watcher 鏈哄埗 -- 鏁版嵁鍙樻洿閫氱煡 ?的主要内容,如果未能解决你的问题,请参考以下文章