disconf回调
来源:互联网 发布:如何在淘宝上购物 编辑:程序博客网 时间:2024/05/22 13:16
disconf可以随时同步配置文件的变化到仓库中。也就是说,配置文件中的参数发生了变化,应用系统会随时获取到最新的参数值。这依靠的是watch+callback机制。
Watch
第一次扫描时,在开启disconf的情况下,会在zk上建立一个代表配置文件的临时结点,monitorPath形如”/disconf/应用名版本号环境/file/sys-config.properties”。然后便监控这个节点。
/** * 监控路径,监控前会事先创建路径,并且会新建一个自己的Temp子结点 */ public void watchPath(DisconfCoreProcessor disconfCoreMgr, DisConfCommonModel disConfCommonModel, String keyName, DisConfigTypeEnum disConfigTypeEnum, String value) throws Exception { // 新建 String monitorPath = makeMonitorPath(disConfigTypeEnum, disConfCommonModel, keyName, value); // 进行监控 NodeWatcher nodeWatcher = new NodeWatcher(disconfCoreMgr, monitorPath, keyName, disConfigTypeEnum, new DisconfSysUpdateCallback(), debug); nodeWatcher.monitorMaster(); }
Callback
当结点更新时,会触发一个WatchedEvent,系统会自动调用回调函数。
调用回调函数的源码见com.baidu.disconf.client.watch.inner.NodeWatcher,如下:
/** * 回调函数 */ @Override public void process(WatchedEvent event) { // // 结点更新时 // if (event.getType() == EventType.NodeDataChanged) { try { LOGGER.info("============GOT UPDATE EVENT " + event.toString() + ": (" + monitorPath + "," + keyName + "," + disConfigTypeEnum.getModelName() + ")======================"); // 调用回调函数, 回调函数里会重新进行监控 callback(); } catch (Exception e) { LOGGER.error("monitor node exception. " + monitorPath, e); } } .... } /** * */ private void callback() { try { // 调用回调函数, 回调函数里会重新进行监控 try { disconfSysUpdateCallback.reload(disconfCoreMgr, disConfigTypeEnum, keyName); } catch (Exception e) { LOGGER.error(e.toString(), e); } } catch (Exception e) { LOGGER.error("monitor node exception. " + monitorPath, e); } }
回调函数主要做了两件事情:
(1)更新配置数据仓库(updateOneConfFile方法),再更新实例(inject2OneConf方法)
(2)调用用户的回调函数列表
回调函数的源码见com.baidu.disconf.client.core.processor.impl.DisconfFileCoreProcessorImpl,如下:
/** * 更新消息: 某个配置文件 + 回调 */ @Override public void updateOneConfAndCallback(String key) throws Exception { // 更新 配置 updateOneConf(key); // 回调 invokeOneConfCallback(key); } /** * 更新消息:某个配置文件 */ private void updateOneConf(String fileName) throws Exception { DisconfCenterFile disconfCenterFile = (DisconfCenterFile) disconfStoreProcessor.getConfData(fileName); if (disconfCenterFile != null) { // 更新仓库 updateOneConfFile(fileName, disconfCenterFile, true); // 更新实例 inject2OneConf(fileName, disconfCenterFile); } } @Override public void invokeOneConfCallback(String key) throws Exception { // 回调 DisconfCoreProcessUtils.callOneConf(disconfStoreProcessor, key); callUpdatePipeline(key); }
这样,修改的配置文件就及时得到了更新。
阅读全文
0 0
- disconf回调
- disconf
- Disconf
- Disconf
- disconf-搭建
- Disconf介绍
- Disconf使用说明
- Disconf使用说明
- Disconf(二)disconf-web
- disconf简介及disconf client使用
- 分布式配置管理平台-Disconf
- disconf基于XML实现
- Disconf入门指南(1)
- 分布式配置管理平台 Disconf
- disconf 分布式配置
- 统一配置管理-百度disconf
- 分布式配置管理平台 Disconf
- disconf使用中的问题
- 11.10学习心得
- 软考知识点总结
- 英特尔结盟AMD反击英伟达,谁才是未来芯片之王?
- 谷歌、中科大27位作者Nature联名发文,指马斯克脑机接口易遭入侵
- 营销观察 | 怎么包装企业故事?马化腾让你去他办公室瞧一瞧
- disconf回调
- task1总结
- Android自定义控件基础知识----View的生命周期
- java json总结 读取json文件或者把对象写入到json文件里面
- 如何使检索出来的columns中的值唯一
- selinux
- 设计模式--工厂模式
- 十月十日JavaScript基础3
- Python的hasattr() getattr() setattr() 函数使用方法详解