当前位置: 首页>>代码示例>>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;未经允许,请勿转载。