serverAddressProcessor

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

1 initHttpClinet()

private void initHttpClient() {
HostConfiguration hostConfiguration = new HostConfiguration(); SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
connectionManager.closeIdleConnections(5000L);//空闲时间 HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
connectionManager.setParams(params); configHttpClient = new HttpClient(connectionManager);
configHttpClient.setHostConfiguration(hostConfiguration);
}

2 acquireServerAddressFromLocal

protected void acquireServerAddressFromLocal() {
if (!isRun) {
throw new RuntimeException("ServerAddressProcessor不在运行状态,无法同步获取服务器地址列表");
}
if (MockServer.isTestMode()) {
diamondConfigure.addDomainName("测试模式,没有使用的真实服务器");
return;
} int acquireCount = 0;
if (diamondConfigure.getDomainNameList().size() == 0) {
reloadServerAddresses();
if (diamondConfigure.getDomainNameList().size() == 0) {
if (!acquireServerAddressOnce(acquireCount)) {//从本地获取 发送http请求
acquireCount++;
if (acquireServerAddressOnce(acquireCount)) {//从服务器获取
// 存入本地文件
storeServerAddressesToLocal();
log.info("在同步获取服务器列表时,向日常ConfigServer服务器获取到了服务器列表");
}
else {
throw new RuntimeException("当前没有可用的服务器列表");
}
}
else {
log.info("在同步获取服务器列表时,向线上ConfigServer服务器获取到了服务器列表");
// 存入本地文件
storeServerAddressesToLocal();
}
}
else {
log.info("在同步获取服务器列表时,由于本地指定了服务器列表,不向ConfigServer服务器同步获取服务器列表");
}
}
}

3 类似第2步

protected void synAcquireServerAddress() {
if (!isRun) {
throw new RuntimeException("ServerAddressProcessor不在运行状态,无法同步获取服务器地址列表");
}
if (MockServer.isTestMode()) {
diamondConfigure.addDomainName("测试模式,没有使用的真实服务器");
return;
} if (reloadServerAddresses()) {
log.info("成功从本地获取Diamond地址列表");
return ;
} int acquireCount = 0; if (diamondConfigure.getDomainNameList().size() == 0) {
if (!acquireServerAddressOnce(acquireCount)) {
acquireCount++;
if (acquireServerAddressOnce(acquireCount)) {
// 存入本地文件
storeServerAddressesToLocal();
log.info("在同步获取服务器列表时,向日常ConfigServer服务器获取到了服务器列表");
}
else {
log.info("从本地获取Diamond地址列表");
reloadServerAddresses();
if (diamondConfigure.getDomainNameList().size() == 0)
throw new RuntimeException("当前没有可用的服务器列表");
}
}
else {
log.info("在同步获取服务器列表时,向线上ConfigServer服务器获取到了服务器列表");
// 存入本地文件
storeServerAddressesToLocal();
}
}
if (diamondConfigure.getDomainNameList().size() == 0) {
throw new RuntimeException("当前没有可用的服务器列表");
}
}

4 开线程获取服务器地址列表

protected void asynAcquireServerAddress() {
if (MockServer.isTestMode()) {
return;
}
this.scheduledExecutor.schedule(new Runnable() {
public void run() {
if (!isRun) {
log.warn("ServerAddressProcessor不在运行状态,无法异步获取服务器地址列表");
return;
}
int acquireCount = 0;
if (!acquireServerAddressOnce(acquireCount)) {
acquireCount++;
if (acquireServerAddressOnce(acquireCount)) {
// 存入本地文件
storeServerAddressesToLocal();
}
}
else {
// 存入本地文件
storeServerAddressesToLocal();
} asynAcquireServerAddress();
}
}, asynAcquireIntervalInSec, TimeUnit.SECONDS);
}

5 获取到服务器列表后

this.diamondConfigure.setDomainNameList(newDomainNameList);

diamond源码阅读-获取服务器列表的更多相关文章

  1. diamond源码阅读-diamond-client

    读取数据 DiamondManager manager = new DefaultDiamondManager("DEFAULT_GROUP", "zml", ...

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

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

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

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

  4. diamond源码阅读-diamond-server

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

  5. SDWebImage 源码阅读分享

    SDWebImage 源码阅读分享 疑问列表 SDWebImage 整体框架图,主要的类包含哪些 SDWebImage 如何进行缓存管理,过期失效策略,缓存更新 SDWebImage 如何多线程处理的 ...

  6. gin 源码阅读(5) - 灵活的返回值处理

    gin 源码阅读系列文章列表: gin 源码阅读(1) - gin 与 net/http 的关系 gin 源码阅读(2) - http请求是如何流入gin的? gin 源码阅读(3) - gin 路由 ...

  7. 【安卓本卓】Android系统源码篇之(一)源码获取、源码目录结构及源码阅读工具简介

    前言        古人常说,“熟读唐诗三百首,不会作诗也会吟”,说明了大量阅读诗歌名篇对学习作诗有非常大的帮助.做开发也一样,Android源码是全世界最优秀的Android工程师编写的代码,也是A ...

  8. cas服务器源码阅读笔记,对标博客

    对标源码阅读博客:http://www.cnblogs.com/jiuzhongguo/category/375405.html 在CAS中很多地方使用了策略模式,那么根据什么方式来确定使用哪种策略呢 ...

  9. redis 5.0.7 源码阅读——压缩列表ziplist

    redis中压缩列表ziplist相关的文件为:ziplist.h与ziplist.c 压缩列表是redis专门开发出来为了节约内存的内存编码数据结构.源码中关于压缩列表介绍的注释也写得比较详细. 一 ...

随机推荐

  1. DL380 G6 BIOS刷新方法

    bios下载地址SP44873.exe (5.9 MB) http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareDescription.js ...

  2. chromatic aberration

    https://github.com/keijiro/KinoFringe https://en.wikipedia.org/wiki/Chromatic_aberration 色差偏移 做神经病效果 ...

  3. http://blog.csdn.net/fbysss/article/details/8024748

    http://blog.csdn.net/fbysss/article/details/8024748

  4. 利用JS实现vue中的双向绑定

    Vue 已经是主流框架了 它的好处也不用多说,都已经是大家公认的了 那我们就来理解一下Vue的单向数据绑定和双向数据绑定 然后再使用JS来实现Vue的双向数据绑定 单向数据绑定 指的是我们先把模板写好 ...

  5. eclipse中egit插件使用(转)

    1.eclipse和egit版本 eclipse使用的是kepler的SR1版,egit就是自带的那个版本,要详细的话,我就也只能把文件名贴出来了:eclipse-jee-kepler-SR1-win ...

  6. ColorSchemer Studio 2 破解

    软件介绍: ColorSchemer Studio 2 is a professional color matching application for anyone from hobbyists t ...

  7. scp命令使下用

    先说下背景把,使用ubuntu,没有windows以下到xshell软件管理一下vps.正瞅着须要下载一个chrome(chrominum真的不好用).此刻大谷歌正墙外呢,无奈挂着ss firefox ...

  8. 【Android Studio探索之路系列】之中的一个:Android Studio开篇

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells github:https://github.co ...

  9. IDC机房与阿里云vpc网络建立高速通道

    本操作以下图所示的场景为例,演示如何通过高速通道建立本地数据中心与VPC之间的私网通信. 前提条件 已提交工单获取接入点的地理位置. 步骤一: 申请物理专线并完成专线接入 登录高速通道管理控制台. 在 ...

  10. lua_pcall,lua_call 调用前后栈情况

    lua_pcall和lua_call功能一样,只是lua_pcall提供了一个可以提供错误处理函数的功能 首先压入函数 ,再依次压入参数,现在你就可以调用lua_call了,函数调用后将参数,函数都弹 ...