zoukankan      html  css  js  c++  java
  • diamond源码阅读-diamond-server

    diamond-server

    1 增加一条数据 /diamond-server/admin.do?method=postConfig

    1.1 调用 this.configService.addConfigInfo(dataId, group, content);

     public void addConfigInfo(String dataId, String group, String content) {
            ConfigInfo configInfo = new ConfigInfo(dataId, group, content);//md5加密content
            // 保存顺序:先数据库,再磁盘
            try {
                checkParameter(dataId, group, content);//参数校验
                persistService.addConfigInfo(configInfo);//插入数据库
                // 切记更新缓存
                this.contentMD5Cache.put(generateMD5CacheKey(dataId, group), configInfo.getMd5());// key = group + "/" + dataId value=MD5
                diskService.saveToDisk(configInfo);//保存到文件
                // 通知其他节点() HTTP 方式通知
                this.notifyOtherNodes(dataId, group);//http://ip:port/diamond-server/notify.do?method=notifyConfigInfo&dataId=" + dataId + "&group=" + group
            }
            catch (Exception e) {
                log.error("保存ConfigInfo失败", e);
                throw new ConfigServiceException(e);
            }
        }
    

    1.2 其他节点接收到信息后

    this.configService.loadConfigInfoToDisk(dataId, group);

    public void loadConfigInfoToDisk(String dataId, String group) {
            try {
                ConfigInfo configInfo = this.persistService.findConfigInfo(dataId, group);//数据库读取配置
                if (configInfo != null) {
                    this.contentMD5Cache.put(generateMD5CacheKey(dataId, group), configInfo.getMd5());//保存到内存 key = group + "/" + dataId value=MD5
                    this.diskService.saveToDisk(configInfo);//保存到文件
                }
                else {
                    // 删除文件
                    this.contentMD5Cache.remove(generateMD5CacheKey(dataId, group));
                    this.diskService.removeConfigInfo(dataId, group);
                }
            }
            catch (Exception e) {
                log.error("保存ConfigInfo到磁盘失败", e);
                throw new ConfigServiceException(e);
            }
        }
    

    1.3 删除同样是修改数据库,修改内存,修改本地文件,通知其他节点

    2 定时任务TimerTaskService DumpConfigInfoTask

    如果通过http请求并没有通知到其他实例,通过定时任务保证从数据库读取信息,更新缓存信息和写入硬盘文件

  • 相关阅读:
    软件工程课程总结
    团队-象棋游戏-团队一阶段互评
    课后作业-结对编程项目总结
    团队-象棋游戏-模块测试过程
    团队编程项目作业3-模块开发过程
    结对-结对编项目作业名称-最终程序
    2017-10-30 课后作业-阅读任务-阅读提问
    阅读任务-阅读提问
    2017-10-30 课后作业-阅读任务-阅读笔记-2
    2017-10-06-构建之法:现代软件工程-阅读笔记
  • 原文地址:https://www.cnblogs.com/clds/p/6001385.html
Copyright © 2011-2022 走看看