當前位置: 首頁>>代碼示例>>Java>>正文


Java ZkClient.readData方法代碼示例

本文整理匯總了Java中org.I0Itec.zkclient.ZkClient.readData方法的典型用法代碼示例。如果您正苦於以下問題:Java ZkClient.readData方法的具體用法?Java ZkClient.readData怎麽用?Java ZkClient.readData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.I0Itec.zkclient.ZkClient的用法示例。


在下文中一共展示了ZkClient.readData方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: nextId

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
/**
 * 利用zookeeper
 * @return
 */
@Override
public String nextId() {
    String app = this.registerDto.getApp();
    String host = this.registerDto.getHost();
    ZkClient zkClient = this.registerDto.getZkClient();
    String path = Constants.ZK_REGISTRY_ID_ROOT_PATH + Constants.SLASH + app + Constants.SLASH + host;
    if (zkClient.exists(path)) {
        // 如果已經有該節點,表示已經為當前的host上部署的該app分配的編號(應對某個服務重啟之後編號不變的問題),直接獲取該id,而無需生成
        return zkClient.readData(Constants.ZK_REGISTRY_ID_ROOT_PATH + Constants.SLASH + app + Constants.SLASH + host);
    } else {
        // 節點不存在,那麽需要生成id,利用zk節點的版本號每寫一次就自增的機製來實現
        Stat stat = zkClient.writeDataReturnStat(Constants.ZK_REGISTRY_SEQ, new byte[0], -1);
        // 生成id
        String id = String.valueOf(stat.getVersion());
        // 將數據寫入節點
        zkClient.createPersistent(path, true);
        zkClient.writeData(path, id);
        return id;
    }
}
 
開發者ID:JThink,項目名稱:SkyEye,代碼行數:25,代碼來源:IncrementIdGen.java

示例2: client

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
private static void client() {
	try {
		ZkClient zc = new ZkClient("localhost:2181");
		String userTwo = "gao:gao";
		zc.addAuthInfo("digest", userTwo.getBytes());

           //使用admin就可以創建
		// String userOne = "admin:admin";
		// zc.addAuthInfo("digest",userOne.getBytes());
		
		String data = zc.readData("/safe");
		log.info("隻讀用戶 " + userTwo + "讀取safe節點返回數據:" + data);
		
		zc.create("/safe2", "test", CreateMode.EPHEMERAL);
		log.info("隻讀用戶創建節點safe2成功:" + zc.readData("/safe2"));
		
		zc.create("/safe/test", "zookeeper加密是針對節點加密的", CreateMode.EPHEMERAL);
		log.info("隻讀用戶創建節點失敗:" + zc.readData("/safe/test"));
		
	} catch (Exception e) {
		e.printStackTrace();
	}
	
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:25,代碼來源:SafeZclient.java

示例3: start

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public synchronized void start(String name) {
    List<String> list = addressMap.get(name);
    if (null != list) {
        return;
    }
    list = new ArrayList<>();
    // 創建 ZooKeeper 客戶端
    ZkClient zkClient = new ZkClient(zkAddress, Constant.ZK_SESSION_TIMEOUT, Constant.ZK_CONNECTION_TIMEOUT);
    LOGGER.info("connect zookeeper={}", zkAddress);
    // 獲取 service 節點
    String servicePath = Constant.ZK_REGISTRY_PATH + "/" + name;
    if (!zkClient.exists(servicePath)) {
        throw new RpcFrameworkException(RpcErrorMsgConstant.FRAMEWORK_REGISTER_ERROR,
                String.format("can not find any service node on path: %s", servicePath));
    }
    List<String> addressList = zkClient.getChildren(servicePath);
    if (CollectionUtil.isEmpty(addressList)) {
        throw new RpcFrameworkException(RpcErrorMsgConstant.FRAMEWORK_REGISTER_ERROR,
                String.format("can not find any address node on path: %s", servicePath));
    }
    for (String path : addressList) {
        String addressPath = servicePath + "/" + path;
        String ipPort = zkClient.readData(addressPath);
        list.add(ipPort);
    }
    addressMap.put(name, list);
}
 
開發者ID:netboynb,項目名稱:coco,代碼行數:28,代碼來源:ZooKeeperServiceDiscovery.java

示例4: load

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
@Override
public void load() {
    ZkClient client = client();
    try {
        byte[] bytes = client.readData(path, true);
        if (bytes == null) return;

        JSONObject json = (JSONObject) new JSONParser().parse(new String(bytes, Charset.forName("utf-8")));
        Nodes.fromJson(json);
    } catch (ParseException e) {
        throw new IOError(e);
    } finally {
        client.close();
    }
}
 
開發者ID:elodina,項目名稱:hdfs-mesos,代碼行數:16,代碼來源:Storage.java

示例5: test1

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
@Test
public void test1() throws Exception {
	ZkClient zkClient = new ZkClient("127.0.0.1:2181", 5000, 5000);

	Object readData = zkClient.readData("/asdfdfs/asdfsf", true);

	System.out.println("read - " + readData);

	Thread.sleep(10000L);
	zkClient.close();
}
 
開發者ID:somefree,項目名稱:zoo-timer,代碼行數:12,代碼來源:MyTest.java


注:本文中的org.I0Itec.zkclient.ZkClient.readData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。