示例#1
0
        private void GetAllConfigs()
        {
            IEnumerable <string>         files;
            IDictionary <string, string> items;

            FetchManager.Instance.GetAllConfigs(out files, out items);
            string zkHosts = FetchManager.Instance.GetZookeeperHosts();

            if (files != null)
            {
                IZkTreeBuilder fileBuilder = new ZkFileTreeBuilder(config.ClientInfo.AppName, config.ClientInfo.Version, config.ClientInfo.Environment);
                foreach (var file in files)
                {
                    fileBuilder.GetOrAddZnodeName(file);
                    this.FileRules.For(file);
                    this.FileRules.ConfigChanged(file, null);
                }
                this._fileWatcher              = new NodeWatcher(zkHosts, 30000, fileBuilder);
                this._fileWatcher.NodeChanged += _fileWatcher_NodeChanged;
            }
            if (items != null)
            {
                IZkTreeBuilder itemBuilder = new ZkItemTreeBuilder(config.ClientInfo.AppName, config.ClientInfo.Version, config.ClientInfo.Environment);
                foreach (var item in items.Keys)
                {
                    itemBuilder.GetOrAddZnodeName(item);
                    this.ItemRules.ConfigChanged(item, items[item]);
                }
                this._itemWatcher              = new NodeWatcher(zkHosts, 30000, itemBuilder);
                this._itemWatcher.NodeChanged += _itemWatcher_NodeChanged;;
            }
        }
示例#2
0
 private void RefreshAndInitFiles(string zkHosts, IEnumerable <string> files)
 {
     if (files != null)
     {
         IZkTreeBuilder fileBuilder = new ZkFileTreeBuilder(config.ClientInfo.AppName, config.ClientInfo.Version, config.ClientInfo.Environment);
         foreach (var file in files)
         {
             fileBuilder.GetOrAddZnodeName(file);
             this._handler.Execute(() =>
             {
                 if (!config.UpdateStrategy.FileIgnoreList.Contains(file))
                 {
                     //对于文件类型,如果本地没配置过Rule规则,则采用默认规则,即将文件复制到实际位置,然后RefreshSection配置对应的文件名
                     this.FileRules.For(file);
                     this.FileRules.ConfigChanged(file, null);
                 }
             }, string.Format("Some thing is wrong with file '{0}'", file));//除了外部包含保证Exception不会导致程序异常,方法内部同样需要保证单次异常不会导致其它监控流程失败
         }
         if (!string.IsNullOrWhiteSpace(zkHosts))
         {
             this._fileWatcher              = new NodeWatcher(zkHosts, 30000, fileBuilder, config.ClientInfo.ClientName);
             this._fileWatcher.NodeChanged += _fileWatcher_NodeChanged;
         }
     }
 }
示例#3
0
        public static string GetPath(string configName, string appName, string version, string env, int type)
        {
            ZkTreeBuilder zkBuilder;

            if (type == (int)ConfigType.File)
            {
                zkBuilder = new ZkFileTreeBuilder(appName, version, env);
            }
            else
            {
                zkBuilder = new ZkItemTreeBuilder(appName, version, env);
            }
            var nodeName = zkBuilder.GetOrAddZnodeName(configName);

            return(zkBuilder.GetZkPath(nodeName));
        }
示例#4
0
        /// <summary>
        /// 刷新文件配置
        /// </summary>
        /// <param name="zkHosts"></param>
        /// <param name="files"></param>
        private void RefreshAndInitFiles(string zkHosts, IEnumerable <string> files)
        {
            if (files != null)
            {
                var fileBuilder = new ZkFileTreeBuilder(config.ClientInfo.AppName, config.ClientInfo.Version, config.ClientInfo.Environment);
                foreach (var configName in files)
                {
                    fileBuilder.GetOrAddZnodeName(configName);
                    FileRules.For(configName).MapTo(configName);
                    FileWatcher_NodeChanged(configName);
                }

                if (!string.IsNullOrWhiteSpace(zkHosts))
                {
                    _fileWatcher              = new NodeWatcher(zkHosts, 30000, fileBuilder, config.ClientInfo.ClientName);
                    _fileWatcher.NodeChanged += FileWatcher_NodeChanged;
                }
            }
        }