private void NodeError(ClientNode node) { LocalLoggingService.Warning("{0} {1} {2} {3}", DistributedServerConfiguration.ModuleName, "ClientCluster", "NodeError", string.Format("集群 {0} 中节点 {1} 出现错误,尝试从集群中移除节点", config.Name, node.Name)); locker.EnterWriteLock(); try { if (!deadClientNodes.ContainsKey(node.Name)) { deadClientNodes.Add(node.Name, node); } if (clientNodes.ContainsKey(node.Name)) { clientNodes.Remove(node.Name); } if (clientNodes.Count == 0) { LocalLoggingService.Error("{0} {1} {2} {3}", DistributedServerConfiguration.ModuleName, "ClientCluster", "NodeError", string.Format("严重错误,集群 {0} 中的所有节点都已经失效!", config.Name)); } node.Destory(); InitNodeLocator(); LocalLoggingService.Warning("{0} {1} {2} {3}", DistributedServerConfiguration.ModuleName, "ClientCluster", "NodeError", string.Format("集群 {0} 中节点 {1} 出现错误,已经从集群中移除", config.Name, node.Name)); } catch (Exception ex) { LocalLoggingService.Error("{0} {1} {2} {3}", DistributedServerConfiguration.ModuleName, "ClientCluster", "NodeError", ex.Message); } finally { locker.ExitWriteLock(); } }
private List <uint> GenerateKeys(ClientNode node, int numberOfKeys) { List <uint> k = new List <uint>(numberOfKeys); for (int i = 0; i < numberOfKeys; i++) { string s = String.Concat(node.Name, "-", i); byte[] data = new FNV1a().ComputeHash(Encoding.ASCII.GetBytes(s)); k.Add(BitConverter.ToUInt32(data, 0)); } return(k); }
private List<uint> GenerateKeys(ClientNode node, int numberOfKeys) { List<uint> k = new List<uint>(numberOfKeys); for (int i = 0; i < numberOfKeys; i++) { string s = String.Concat(node.Name, "-", i); byte[] data = new FNV1a().ComputeHash(Encoding.ASCII.GetBytes(s)); k.Add(BitConverter.ToUInt32(data, 0)); } return k; }
internal ClientSocket AcquireSocket(string itemKey) { ClientNode node = AcquireNode(itemKey); if (node == null) { LocalLoggingService.Error("{0} {1} {2} {3}", DistributedServerConfiguration.ModuleName, "ClientCluster", "AcquireSocket", string.Format("在集群 {0} 中根据 Key {1} 没有获取到节点,集群现有节点数量 {2}", config.Name, itemKey, clientNodes.Count)); return(null); } if (!node.IsAlive) { NodeError(node); } //AppInfoCenterService.LoggingService.Debug("集群分配方案 Key {0} -> 节点 {1}", itemKey, node.Name); return(node.GetClientSocket()); }
internal ClientCluster(ClientClusterConfiguration config) { if (config == null) { throw new ArgumentNullException("传入的集群配置为空!"); } if (string.IsNullOrEmpty(config.Name)) { throw new ArgumentException("集群名为空!"); } this.config = config; tryRecoverNodeThread = new Thread(TryRecoverNodeThreadAction) { Name = string.Format("{0}_{1}", "Adhesive.DistributedComponentClient_TryRecoverNodeThread", config.Name), IsBackground = true, }; tryRecoverNodeThread.Start(); foreach (var nodeConfig in config.ClientNodeConfigurations.Select(item => item.Value).ToList()) { if (clientNodes.ContainsKey(nodeConfig.Name)) { throw new Exception(string.Format("在集群 {0} 中已经存在名为 {1} 的节点!", config.Name, nodeConfig.Name)); } var node = new ClientNode(nodeConfig, this.NodeError); locker.EnterWriteLock(); try { clientNodes.Add(nodeConfig.Name, node); } finally { locker.ExitWriteLock(); } } InitNodeLocator(); }
internal ClientCluster(ClientClusterConfiguration config) { if (config == null) throw new ArgumentNullException("传入的集群配置为空!"); if (string.IsNullOrEmpty(config.Name)) throw new ArgumentException("集群名为空!"); this.config = config; tryRecoverNodeThread = new Thread(TryRecoverNodeThreadAction) { Name = string.Format("{0}_{1}", "Adhesive.DistributedComponentClient_TryRecoverNodeThread", config.Name), IsBackground = true, }; tryRecoverNodeThread.Start(); foreach (var nodeConfig in config.ClientNodeConfigurations.Select(item => item.Value).ToList()) { if (clientNodes.ContainsKey(nodeConfig.Name)) throw new Exception(string.Format("在集群 {0} 中已经存在名为 {1} 的节点!", config.Name, nodeConfig.Name)); var node = new ClientNode(nodeConfig, this.NodeError); locker.EnterWriteLock(); try { clientNodes.Add(nodeConfig.Name, node); } finally { locker.ExitWriteLock(); } } InitNodeLocator(); }