Exemple #1
0
        /// <summary>
        /// Build selector
        /// </summary>
        private Selector()
        {
            List <string> nodeList = SettingItem.GetInstance().CacherCollections;

            //nodeList.Add(Dns.GetHostName());
            _nodeLocator = new KetamaNodeLocator(nodeList, MaxNodeCopy);
        }
Exemple #2
0
        public void SetItems(IEnumerable <object> keys, object sameValue, bool overrides)
        {
            Dictionary <string, Message> list = new Dictionary <string, Message>();

            foreach (var key in keys)
            {
                int    code = key.GetHashCode();
                string host = _nodeLocator.GetNodeForKey(code);
                if (list.ContainsKey(host))
                {
                    list[host].Values.Add(key);
                }
                else
                {
                    Message cacheMsg = new Message(host, Message.CommandType.SetList, key, sameValue, 1, new[] { key },
                                                   overrides);
                    list.Add(host, cacheMsg);
                }
            }

            foreach (var host in list.Keys)
            {
                _client = new Client(host, SettingItem.GetInstance().CacheNodePort);
                Packet packet = new CachePacket(Serializer.SerializeToBytes(list[host]));
                packet.WaiteCallBack = false;
                _client.Send <Message>(packet);
            }
        }
Exemple #3
0
 /// <summary>
 /// 初始化
 /// </summary>
 private static void Init()
 {
     if (_client == null)
     {
         string    remoteServer = SettingItem.GetInstance().MergeServerIP;
         const int remotePort   = 8801;
         _client = new Framework.Network.Synchronous.Client(remoteServer, remotePort);
     }
 }
Exemple #4
0
 /// <summary>
 /// Check Connect to server
 /// </summary>
 private static void CheckConnect()
 {
     if (_clients == null)
     {
         string[] hosts = SettingItem.GetInstance().StateCenterHosts.ToArray();
         _clients = new Client[hosts.Count()];
         int port = SettingItem.GetInstance().StateCenterPort;
         for (int i = 0; i < hosts.Count(); i++)
         {
             _clients[i] = new Client(hosts[i], port);
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// Get the value base on the key
        /// </summary>
        public object GetItem(object key)
        {
            int    code = key.GetHashCode();
            string host = _nodeLocator.GetNodeForKey(code);

            _client = new Client(host, SettingItem.GetInstance().CacheNodePort);
            Message message = new Message(host, Message.CommandType.Get, key, null);
            Packet  packet  = new CachePacket(Serializer.SerializeToBytes(message));

            packet.WaiteCallBack = true;
            message = _client.Send <Message>(packet);
            return(message.Value);
        }
Exemple #6
0
        /// <summary>
        /// Set the value of the key
        /// </summary>
        public void SetItem(object key, object value, bool overrides)
        {
            int     code    = key.GetHashCode();
            string  host    = _nodeLocator.GetNodeForKey(code);
            Message message = new Message(host, Message.CommandType.Set, key, value, 1, null, overrides);

            _client = new Client(host, SettingItem.GetInstance().CacheNodePort);

            Packet packet = new CachePacket(Serializer.SerializeToBytes(message));

            //1207
            packet.WaiteCallBack = false;
            _client.Send <Message>(packet);
        }
Exemple #7
0
        /// <summary>
        /// Get keys by value
        /// </summary>
        public object[] GetKeyByValue(object value, int topN, object changeValue)
        {
            List <string> hosts = SettingItem.GetInstance().CacherCollections;
            List <object> keys  = new List <object>();

            foreach (var host in hosts)
            {
                _client = new Client(host, SettingItem.GetInstance().CacheNodePort);
                Message message = new Message(host, Message.CommandType.GetList, changeValue, value, topN);
                Packet  packet  = new CachePacket(Serializer.SerializeToBytes(message));
                packet.WaiteCallBack = true;
                message = _client.Send <Message>(packet);
                keys.AddRange(message.Values);
            }
            return(keys.ToArray());
        }
Exemple #8
0
 static void Main()
 {
     SettingItem.GetInstance().Save();
 }