Esempio n. 1
0
        /// <summary>
        /// 单个节点
        /// </summary>
        /// <param name="node"></param>
        public void AddNode(StoreNode node)
        {
            resetEvent.Reset();
            List <ulong> lst = new List <ulong>();

            for (int i = 0; i < numReps; i++)
            {
                //getKeyForNode方法为这组虚拟结点得到惟一名称
                /** 是一个16字节长度的数组,将16字节的数组每四个字节一组,分别对应一个虚拟结点,这就是为什么上面把虚拟结点四个划分一组的原因*/
                try
                {
                    byte[] digest = MurmurHashFactory.ComputeMurmur(node.ToString() + i);
                    ulong  key    = MurmurHashFactory.Hash(digest);
                    ketamaNodes.Add(key, node);
                }
                catch (RedBlackException ex)
                {
                    if (ex.Error == ReadBlackCode.KeyExists)
                    {
                        foreach (ulong key in lst)
                        {
                            try
                            {
                                ketamaNodes.Remove(key);
                            }
                            catch
                            {
                            }
                        }
                    }
                    i--;
                }
            }
            resetEvent.Set();
        }
Esempio n. 2
0
        /// <summary>
        /// 移除节点
        /// </summary>
        /// <param name="node"></param>
        public void Remove(StoreNode node)
        {
            var lst = ketamaNodes.FindKeys(node);

            for (int i = 0; i < lst.Count; i++)
            {
                ketamaNodes.Remove(lst[i]);
            }
            lst.Clear();
        }
Esempio n. 3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if ((obj.GetType().Equals(this.GetType())) == false)
            {
                return(false);
            }
            StoreNode temp = null;

            temp = (StoreNode)obj;

            return(this.ToString().Equals(temp.ToString()));
        }
Esempio n. 4
0
        /**
         * Gets the mock node by the material parameter
         *  测试使用的
         * @param nodeCount
         *      the count of node wanted
         * @return
         *      the node list
         */
        private static List <StoreNode> GetNodes(int nodeCount)
        {
            List <StoreNode> nodes = new List <StoreNode>();
            var configs            = Configuration.ConfigManager.GetEntity <List <Config> >("ServiceConfig");

            for (int k = 1; k <= configs.Count(); k++)
            {
                StoreNode node = new StoreNode()
                {
                    Name   = "Node", IP = "192.168.3." + (k + 100), Port = 7123 + k,
                    Config = configs[k - 1]
                };
                nodes.Add(node);
            }

            return(nodes);
        }