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;; } }
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)); }
/// <summary> /// 刷新键值对 /// </summary> /// <param name="zkHosts"></param> /// <param name="items"></param> private void RefreshAndInitItems(string zkHosts, IDictionary <string, string> items) { if (items != null) { var itemBuilder = new ZkItemTreeBuilder(config.ClientInfo.AppName, config.ClientInfo.Version, config.ClientInfo.Environment); foreach (var itemName in items.Keys) { itemBuilder.GetOrAddZnodeName(itemName); ItemWatcher_NodeChanged(itemName); } if (!string.IsNullOrWhiteSpace(zkHosts)) { _itemWatcher = new NodeWatcher(zkHosts, 30000, itemBuilder, config.ClientInfo.ClientName); _itemWatcher.NodeChanged += ItemWatcher_NodeChanged; } } }
private void RefreshAndInitItems(string zkHosts, IDictionary <string, string> items) { 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._handler.Execute(() => { if (!config.UpdateStrategy.ItemIgnoreList.Contains(item)) { //键值对必须配置本地规则,否则无法处理 this.ItemRules.ConfigChanged(item, items[item]); } }, string.Format("Some thing is wrong with item '{0}'", item)); } if (!string.IsNullOrWhiteSpace(zkHosts)) { this._itemWatcher = new NodeWatcher(zkHosts, 30000, itemBuilder, config.ClientInfo.ClientName); this._itemWatcher.NodeChanged += _itemWatcher_NodeChanged; } } }