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


Java ZkClient.getChildren方法代碼示例

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


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

示例1: getChildren

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public List<String> getChildren(String cluster, String path) throws ShepherException {
    ZkClient zkClient = ZkPool.getZkClient(cluster);
    try {
        if (zkClient == null) {
            return Collections.emptyList();
        }
        return zkClient.getChildren(path);
    } catch (Exception e) {
        LOGGER.warn("Fail to get children, Exception:", e);
        throw ShepherException.createUnknownException();
    } finally {
        ZkPool.releaseZkClient(cluster, zkClient);
    }
}
 
開發者ID:XiaoMi,項目名稱:shepher,代碼行數:15,代碼來源:NodeDAO.java

示例2: main

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
public static void main(String[] args) {

        String zkHost = "192.168.88.196:2182,192.168.88.197:2182,192.168.88.198:2182";

        // 進行監控
        ZkClient zkClient = new ZkClient(zkHost, 60000, 5000);

        System.out.println("你妹的: " + zkClient.readData(Constants.ROOT_PATH_PERSISTENT + Constants.SLASH + "app-test"));



        List<String> apps = zkClient.getChildren(Constants.ROOT_PATH_EPHEMERAL);
        for (String app : apps) {
            zkClient.subscribeChildChanges(Constants.ROOT_PATH_EPHEMERAL + Constants.SLASH + app, new AppChildChangeListener());
            List<String> hosts = zkClient.getChildren(Constants.ROOT_PATH_EPHEMERAL + Constants.SLASH + app);
            for (String host : hosts) {
                zkClient.subscribeDataChanges(Constants.ROOT_PATH_EPHEMERAL + Constants.SLASH + app + Constants.SLASH + host, new HostDataChangeListener());
                System.out.println();
            }
        }

        synchronized (ZkTest.class) {
            while (true) {
                try {
                    ZkTest.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
 
開發者ID:JThink,項目名稱:SkyEye,代碼行數:32,代碼來源:ZkTest.java

示例3: test

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
/**
 * @Description: zkClient主要做了兩件事情。
 * @see:一件是在session loss和session expire時自動創建新的ZooKeeper實例進行重連。
 * @see:一件是將一次性watcher包裝為持久watcher。
 * @see:後者的具體做法是簡單的在watcher回調中,重新讀取數據的同時再注冊相同的watcher實例。
 */
private static void test() {
	final ZkClient zc = new ZkClient("123.56.118.135:2181");
	// 創建根節點
	/* Persistent與Ephemeral 就是持久化保存到本地和不持久化的區別 ,不能再臨時節點下麵創建子節點 */
	
	zc.createPersistent("/testroot");
	// zc.createEphemeral("/testroot");
	// 創建子節點
	zc.create("/testroot/node1", "node1", CreateMode.EPHEMERAL);
	zc.createPersistent("/testroot/node2");
	zc.create("/testroot/node2/test", "node1", CreateMode.EPHEMERAL);
	List<String> children = zc.getChildren("/");
	log.info("根節點下麵的字節點個數" + children.size());
	
	// 獲得子節點個數
	
	int chidrenNumbers = zc.countChildren("/testroot");
	log.info("子節點個數" + chidrenNumbers);
	
	zc.writeData("/testroot/node2/test", "給節點寫數據");
	
	// 刪除節點
	zc.delete("/testroot/node2/test");
	zc.delete("/testroot/node2");
	zc.delete("/testroot/node1");
	zc.delete("/testroot");
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:34,代碼來源:ZclientNormal.java

示例4: 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

示例5: test2

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

	List<String> children = zkClient.getChildren("/sdfasdf/asdfsd");

	System.out.println("children - " + children);

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

示例6: zkClientWithSerializer

import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
@Test
public void zkClientWithSerializer(){
    ZkClient zkClient = new ZKClientConnect().zkClientWithSerializer();
    List<String> children = zkClient.getChildren("/zookeeper1223");
    System.out.println(children);
}
 
開發者ID:mumudemo,項目名稱:mumu-zookeeper,代碼行數:7,代碼來源:ZKClientConnectDemo.java


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