读取数据

DiamondManager manager = new DefaultDiamondManager("DEFAULT_GROUP", "zml", new ManagerListener() {
public void receiveConfigInfo(String configInfo) {
System.out.println("changed config: " + configInfo);
} public Executor getExecutor() {
return null;
}
}, "127.0.0.1");
//设置diamond-server服务的端口
manager.getDiamondConfigure().setPort(8080);
String availableConfigureInfomation = manager.getAvailableConfigureInfomation(5000);
System.out.println("start config: " + availableConfigureInfomation);
}

1 初始化DefaultDiamondManager 并启动diamondSubscriber

 public DefaultDiamondManager(String group, String dataId, ManagerListener managerListener,String diamondServer) {
this.dataId = dataId;
this.group = group; diamondSubscriber = DiamondClientFactory.getSingletonDiamondSubscriber(); this.managerListeners.add(managerListener);
((DefaultSubscriberListener) diamondSubscriber.getSubscriberListener()).addManagerListeners(this.dataId,
this.group, this.managerListeners);
String s[] = diamondServer.split(",");
if (s != null && s.length > 0) {
for (String o : s) {
if (o != null && !o.trim().equals(""))
diamondSubscriber.getDiamondConfigure().getDomainNameList().add(o.trim());
}
}
diamondSubscriber.addDataId(this.dataId, this.group);
diamondSubscriber.start();
}

1.1 diamondSubscriber.start();

 /**
* 启动DiamondSubscriber:<br>
* 1.阻塞主动获取所有的DataId配置信息<br>
* 2.启动定时线程定时获取所有的DataId配置信息<br>
*/
public synchronized void start() {
if (isRun) {
return;
} if (null == scheduledExecutor || scheduledExecutor.isTerminated()) {
scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
} localConfigInfoProcessor.start(this.diamondConfigure.getFilePath() + "/" + DATA_DIR);//创建根目录并监控根目录C:\Users\zhumenglong/diamond/data
serverAddressProcessor = new ServerAddressProcessor(this.diamondConfigure, this.scheduledExecutor);
serverAddressProcessor.start(); this.snapshotConfigInfoProcessor =
new SnapshotConfigInfoProcessor(this.diamondConfigure.getFilePath() + "/" + SNAPSHOT_DIR);
// 设置domainNamePos值
randomDomainNamePos();
initHttpClient(); // 初始化完毕
isRun = true; if (log.isInfoEnabled()) {
log.info("当前使用的域名有:" + this.diamondConfigure.getDomainNameList());
} if (MockServer.isTestMode()) {
bFirstCheck = false;
}
else {
// 设置轮询间隔时间
this.diamondConfigure.setPollingIntervalTime(Constants.POLLING_INTERVAL_TIME);
}
// 轮询
rotateCheckConfigInfo(); addShutdownHook();
}

1.1.1 http://www.cnblogs.com/clds/p/5997195.html

 localConfigInfoProcessor.start(this.diamondConfigure.getFilePath() + "/" + DATA_DIR);//创建根目录并监控根目录
目录获取方式 System.getProperty("user.home") + "/diamond"; C:\Users\zhumenglong/diamond/data //监控代码分析见 //核心思路起一个线程定时监听文件夹及子文件,判断文件是否增加删除//修改,
//保存到 localConfigInfoProcessor 的existFiles Map<String/* filePath */, Long/* version */>

1.1.2 serverAddressProcessor.start(); http://www.cnblogs.com/clds/p/6001396.html

 public synchronized void start() {
if (isRun) {
return;
}
isRun = true;
initHttpClient();//初始化HttpClient
if (this.diamondConfigure.isLocalFirst()) {
acquireServerAddressFromLocal();//如果是本地,从本地获取服务器列表
}
else {
synAcquireServerAddress();
//如果不再异步每隔一段通过域名时间去取diamondIpList,注释掉下面这行
//asynAcquireServerAddress();
asynAcquireServerAddress();
} }

1.1.3 randomDomainNamePos(); 随机获取服务器地址

   private void randomDomainNamePos() {
// 随机化起始服务器地址
Random rand = new Random();
List<String> domainList = this.diamondConfigure.getDomainNameList();
if (!domainList.isEmpty()) {
this.domainNamePos.set(rand.nextInt(domainList.size()));
}
}

1.1.4 initHttpClient(); 初始化 httpClient 多线程

1.1.5 rotateCheckConfigInfo(); http://www.cnblogs.com/clds/p/6000771.html

1.1.6 addShutdownHook(); jvm关闭钩子

2 //设置diamond-server服务的端口

 manager.getDiamondConfigure().setPort(8080);

3 获取数据String availableConfigureInfomation = manager.getAvailableConfigureInfomation(5000);

  public String getAvailableConfigureInfomation(String dataId, String group, long timeout) {
// 尝试先从本地和网络获取配置信息
try {
String result = getConfigureInfomation(dataId, group, timeout);
if (result != null && result.length() > 0) {
return result;
}
}
catch (Throwable t) {
log.error(t.getMessage(), t);
} // 测试模式不使用本地dump
if (MockServer.isTestMode()) {
return null;
}
return getSnapshotConfiginfomation(dataId, group);//本地快照获取
}

diamond源码阅读-diamond-client的更多相关文章

  1. diamond源码阅读-获取服务器列表

    serverAddressProcessor public synchronized void start() { if (isRun) { return; } isRun = true; initH ...

  2. diamond源码阅读-diamond-server

    diamond-server 1 增加一条数据 /diamond-server/admin.do?method=postConfig 1.1 调用 this.configService.addConf ...

  3. diamond源码阅读-循环探测配置信息是否变化rotateCheckConfigInfo

    rotateCheckConfigInfo 这是一个定时任务,循环调用 /** * 循环探测配置信息是否变化,如果变化,则再次向DiamondServer请求获取对应的配置信息 */ private ...

  4. diamond源码阅读-目录监控

    PathNode(Path)StandardWatchEventKind(WatchEvent)Watchable(WatchKey WatchService WatchEvent)WatchKey( ...

  5. ZooKeeper源码阅读——client(二)

    原创技术文章,转载请注明:转自http://newliferen.github.io/ 如何连接ZooKeeper集群   要想了解ZooKeeper客户端实现原理,首先需要关注一下客户端的使用方式, ...

  6. 【原】AFNetworking源码阅读(一)

    [原]AFNetworking源码阅读(一) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 AFNetworking版本:3.0.4 由于我平常并没有经常使用AFNetw ...

  7. 如何阅读Java源码 阅读java的真实体会

    刚才在论坛不经意间,看到有关源码阅读的帖子.回想自己前几年,阅读源码那种兴奋和成就感(1),不禁又有一种激动. 源码阅读,我觉得最核心有三点:技术基础+强烈的求知欲+耐心.   说到技术基础,我打个比 ...

  8. CI框架源码阅读笔记3 全局函数Common.php

    从本篇开始,将深入CI框架的内部,一步步去探索这个框架的实现.结构和设计. Common.php文件定义了一系列的全局函数(一般来说,全局函数具有最高的加载优先权,因此大多数的框架中BootStrap ...

  9. 转-OpenJDK源码阅读导航跟编译

    OpenJDK源码阅读导航 OpenJDK源码阅读导航 博客分类: Virtual Machine HotSpot VM Java OpenJDK openjdk 这是链接帖.主体内容都在各链接中.  ...

随机推荐

  1. VSM(Virtual Storage Manager For Ceph)安装教程

    转载注明出处,陈小跑 http://www.cnblogs.com/chenxianpao/p/5770271.html 一.安装环境 OS:CentOS7.2 VSM:v2.1 released 二 ...

  2. es6的模块化;js的模块化

    现在感觉Java.Python.Js都是越来越工程花,模块化.懂得每个模块的功能和使用场景,你很快的就能搭起一个功能齐备的应用.至于应用的性能.稳定性等,还在于你对模块的理解深度以及组合的成熟度,就看 ...

  3. leetcode第一刷_Edit Distance

    最小编辑距离.非常经典的问题.今年微软实习生的笔试有一个这个的扩展版,牵扯到模板之类的,当时一行代码也没写出来. . dp能够非常优雅的解决问题.状态转移方程也非常明白.用pos[i][j]表示wor ...

  4. iOS: 格式化新浪微博/QQ说说等等的发布时间

    介绍:对于一些社交工具,我们可以发布一些说说或者心情什么的,如新浪微博,QQ,微信等,发布成功后,上面都会有一个发布的时间. 这个时间并不是具体的NSDate类型,而是经过格式化过的符合一般标准的模式 ...

  5. Yii2系列教程四:实现用户注册,验证,登录

    上一篇写了一点点Yii2的数据库相关知识和强大的Gii,这一篇就如上一篇的最后所说的一样:在Yii2中实现用户的注册和登录. 你可以直接到Github下载源码,以便可以跟上进度,你也可以重头开始,一步 ...

  6. 【Docker】MySQL容器因为内存限制启动失败?

    参考资料: https://github.com/docker-library/mysql/issues/3 Improving MySQL's default configuration:http: ...

  7. hadoop2.2.0集群安装和配置

    hadoop2.0已经发布了稳定版本了,增加了很多特性,比如HDFS HA.YARN等. 注意:apache提供的hadoop-2.2.0的安装包是在32位操作系统编译的,因为hadoop依赖一些C+ ...

  8. python——二进制/十进制等转换

    To 十进制 八进制: >>> int('10', 8) ->8   To 十六进制: 十进制: >>> hex(12) ->‘0xc’ 二进制: &g ...

  9. mysqli 预处理语句

    预处理语句用于执行多个相同的 SQL 语句,并且执行效率更高. <?php // 设置编码格式 header('content-type:text/html;charset=utf-8'); / ...

  10. lodash escapeRegExp 转义正则特殊字符

    _.escapeRegExp([string='']) 转义RegExp 中特殊的字符 "^", "$", "\", ".&quo ...