Zookeeper之javaAPI的使用

2021-09-22 16:46:35 字數 2956 閱讀 4893

主要jar包在主目錄下

專案需要的相關依賴的jar包在zookeeper的解壓檔案的lib目錄下就有

將這幾個jar包匯入專案中

// zookeeper的伺服器位址,配置conf是用主機名,這裡一樣

private string connectstring ="zek00:2181,zek01:2181,zek02:2181";

// 連線超時時間

private int sessiontimeout = 2000;

private zookeeper zk = null;

/*** 設定zookeeper物件

* @throws ioexception

*/@before

public void setzookeeper() throws ioexception

});system.out.println("---"+zk);

}

/**

* create 方法引數

* 第乙個引數 路徑

* 第二個引數 值 bytes

* 第三個引數 對節點的訪問控制

* 第四個引數 節點的型別 短暫 永久 序號

* @throws keeperexception

* @throws interruptedexception

*/@test

public void create() throws keeperexception, interruptedexception

/** * 判斷節點是否存在

* @throws interruptedexception

* @throws keeperexception

*/@test

public void exist() throws keeperexception, interruptedexceptionelse

}/**

* 獲取子節點

* @throws interruptedexception

* @throws keeperexception

*/@test

public void getchilren() throws keeperexception, interruptedexception

}/**

* 獲取節點的內容

* @throws interruptedexception

* @throws keeperexception

*/@test

public void getdata() throws keeperexception, interruptedexception

/** * 修改節點內容

* version -1 自動維護

* @throws interruptedexception

* @throws keeperexception

*/@test

public void setdata() throws keeperexception, interruptedexception

/** * 刪除節點

* 非空節點刪除不掉

* @throws interruptedexception

* @throws keeperexception

*/@test

public void deletenode() throws interruptedexception, keeperexception

@before

public static void setupbeforeclass() throws exception

});}/**

* 獲取子節點

* getchildren(path,watch?)監聽的事件是:節點下的子節點增減變化事件

* @throws interruptedexception

* @throws keeperexception

*/@test

public void getchilren() throws keeperexception, interruptedexception

});for (string s : list)

thread.sleep(long.max_value);

}/**

* 獲取節點的內容

* getdata(path,watch?)監聽的事件是:節點資料變化事件

* @throws interruptedexception

* @throws keeperexception

*/@test

public void getdata() throws keeperexception, interruptedexception

}, null );

system.out.println(new string(b));

thread.sleep(long.max_value);

}

Zookeeper之FileTxnLog原始碼分析

if hdr null if hdr.getzxid lastzxidseen is for hdr.getzxid lastzxidseen,hdr.gettype else if logstream null util.makelogname hdr.getzxid logfilewrite n...

Zookeeper之工作原理

zookeeper是乙個分布式的,開放原始碼的分布式應用程式協調服務,它包含乙個簡單的原語集,分布式應用程式可以基於它實現同步服務,配置維護和命名服務等。zookeeper是hadoop的乙個子專案,其發展歷程無需贅述。在分布式應用中,由於工程師不能很好地使用鎖機制,以及基於訊息的協調機制不適合在某...

zookeeper學習之簡述

概況 zookeeper是乙個分布式的,開放原始碼的分布式應用程式協調服務,是google的chubby乙個開源實現,是hadoop和hbase的重要元件。它是乙個為分布式應用提供一致性服務的軟體,提供的功能包括 配置維護 網域名稱服務 分布式同步 組服務等。用途 常用來管理資料,例如作為dubbo...