ZooKeeper-3.6 管理客户端- 高飞网

3.6 管理客户端

2018-05-30 18:28:18.0

打印主节点;

打印从节点列表

打印任务节点列表

public class AdminClient {
    static Logger logger = LoggerFactory.getLogger(AdminClient.class);

    public static void main(String[] args) throws KeeperException, InterruptedException {
        ZKClient zkClient = ZKClient.instance();
        try {
            Stat stat = new Stat();
            byte[] data = zkClient.getData(Consts.MASTER_PATH, false, stat);
            Date startDate = new Date(stat.getCtime());
            logger.info("master:" + new String(data) + ",since:" + startDate);
        } catch (KeeperException.NoNodeException e) {
            logger.error("No Master.");
        }


        logger.info("Workers:");
        List<String> children = zkClient.getChildren(Consts.WORKERS_PATH, false);
        for (String w : children) {
            byte[] data = zkClient.getData(Consts.WORKERS_PATH + "/" + w, false, null);
            logger.info("\t" + w + ":" + new String(data));
        }


        logger.info("Tasks:");
        List<String> children1 = zkClient.getChildren(Consts.TASKS_PATH, false);
        for (String t : children1) {
            logger.info("\t" + t);
        }

    }
}


上一篇:3.5 任务队列化
下一篇:4.1 单次触发器