public CacheData AddCacheDataIfAbsent(string dataId, string group, string tenant) { CacheData cache = GetCache(dataId, group, tenant); if (cache != null) { return(cache); } string key = GroupKey.GetKey(dataId, group, tenant); CacheData cacheFromMap = GetCache(dataId, group, tenant); // multiple listeners on the same dataid+group and race condition,so double check again // other listener thread beat me to set to cacheMap if (cacheFromMap != null) { cache = cacheFromMap; // reset so that server not hang this check cache.IsInitializing = true; } else { cache = new CacheData(_configFilterChainManager, _agent.GetName(), dataId, group, tenant); int taskId = _cacheMap.Count / CacheData.PerTaskConfigSize; cache.TaskId = taskId; } _cacheMap.AddOrUpdate(key, cache, (x, y) => cache); _logger?.LogInformation("[{0}] [subscribe] {1}", this._agent.GetName(), key); return(cache); }
private CacheData AddCacheDataIfAbsent(string dataId, string group) { CacheData cache = GetCache(dataId, group); if (cache != null) { return(cache); } string key = GroupKey.GetKey(dataId, group); cache = new CacheData(_configFilterChainManager, _localConfigInfoProcessor, _agent.GetName(), dataId, group); var cacheFromMap = GetCache(dataId, group); if (cacheFromMap != null) { cache = cacheFromMap; cache.IsInitializing = true; } else { int taskId = _cacheMap.Count / (int)UtilAndComs.PER_TASK_CONFIG_SIZE; cache.TaskId = taskId; } _cacheMap.AddOrUpdate(key, cache, (k, v) => cache); _logger.Info($"[{_agent.GetName()}] [subscribe] {key}"); return(cache); }
internal void RemoveCache(string dataId, string group, string tenant = null) { string groupKey = tenant == null?GroupKey.GetKey(dataId, group) : GroupKey.GetKeyTenant(dataId, group, tenant); _cacheMap.TryRemove(groupKey, out _); _logger?.LogInformation("[{0}] [unsubscribe] {1}", this._agent.GetName(), groupKey); }
private void RemoveCache(string dataId, string group) { string groupKey = GroupKey.GetKey(dataId, group); CacheData cache; _cacheMap.TryRemove(groupKey, out cache); _logger.Info($"[{_agent.GetName()}] [unsubscribe] {groupKey}"); }
protected override Task RemoveCache(string dataId, string group) { var groupKey = GroupKey.GetKey(dataId, group); _cacheMap.TryRemove(groupKey, out _); _logger?.LogInformation("[{0}] [unsubscribe] {1}", GetNameInner(), groupKey); return(Task.CompletedTask); }
private List <string> ParseUpdateDataIdResponse(string response) { if (string.IsNullOrEmpty(response)) { return(new List <string>()); } response = System.Net.WebUtility.UrlDecode(response); var updateList = new List <string>(); foreach (string dataIdAndGroup in response.SplitByString(Constants.LINE_SEPARATOR)) { if (!string.IsNullOrEmpty(dataIdAndGroup)) { var keyArr = dataIdAndGroup.SplitByString(Constants.WORD_SEPARATOR); if (keyArr.Length < 2) { continue; } string dataId = keyArr[0]; string group = keyArr[1]; if (keyArr.Length == 2) { updateList.Add(GroupKey.GetKey(dataId, group)); _logger?.LogInformation( "[{0}] [polling-resp] config changed. dataId={1}, group={2}", _agent.GetName(), dataId, group); } else if (keyArr.Length == 3) { string tenant = keyArr[2]; updateList.Add(GroupKey.GetKeyTenant(dataId, group, tenant)); _logger?.LogInformation( "[{0}] [polling-resp] config changed. dataId={1}, group={2}, tenant={3}", _agent.GetName(), dataId, group, tenant); } else { _logger?.LogError("[{0}] [polling-resp] invalid dataIdAndGroup error {1}", _agent.GetName(), dataIdAndGroup); } } } return(updateList); }
private IList <string> ParseUpdateDataIdResponse(string response) { if (string.IsNullOrEmpty(response)) { return(null); } response = WebUtility.UrlDecode(response); var updateList = new List <string>(); foreach (string dataIdAndGroup in response.Split(Constants.LINE_SEPARATOR)) { if (!string.IsNullOrEmpty(dataIdAndGroup)) { var keyArr = dataIdAndGroup.Split(Constants.WORD_SEPARATOR); if (keyArr.Length < 2) { continue; } string dataId = keyArr[0]; string group = keyArr[1]; if (keyArr.Length == 2) { updateList.Add(GroupKey.GetKey(dataId, group)); _logger.Info($"[{_agent.GetName()}] [polling-resp] config changed. dataId={dataId}, group={group}"); } else if (keyArr.Length == 3) { string tenant = keyArr[2]; updateList.Add(GroupKey.GetKeyTenant(dataId, group, tenant)); _logger.Info($"[{_agent.GetName()}] [polling-resp] config changed. dataId={dataId}, group={group}, tenant={tenant}"); } else { _logger.Error($"[{_agent.GetName()}] [polling-resp] invalid dataIdAndGroup error {dataIdAndGroup}"); } } } return(updateList); }