Esempio n. 1
0
        public static void Register(Message service)
        {
            //如果现阶段在data有数据的前提下新插入一条新数据为false,原来有就更新为true
            bool dataStatus = false;
            int  index      = 0;

            if (!data.ContainsKey(service.name))
            {
                data[service.name] = new List <Message>();
            }
            List <Message> services = data[service.name];

            //web是多线程的加锁
            lock (services)
            {
                service.status = Message.service_status.alive.ToString();

                //存入内存
                for (int item = 0; item < services.Count; item++)
                {
                    //如果现阶段内存中有该条数据就,删除原来的再插入新的更新!
                    if (service.id == services[item].id && service.name == services[item].name)
                    {
                        dataStatus = true;
                        index      = item;
                        break;
                    }
                }

                if (dataStatus)
                {
                    //更新
                    service.utc_time = LinuxTime.Seconds(DateTime.Now);
                    services[index]  = service;
                }
                else
                {
                    //如果现阶段内存中没有该条数据就添加插入
                    service.utc_time = LinuxTime.Seconds(DateTime.Now);
                    services.Add(service);
                }
                if (LogHelper.enable)
                {
                    LogHelper.WriteLog(services.ToString());
                }
            }
        }
Esempio n. 2
0
        public Task Execute(IJobExecutionContext context)
        {
            return(Task.Run(() =>
            {
                try
                {
                    foreach (List <Message> item in RDS.data.Values)
                    {
                        if (item == null || item.Count == 0)
                        {
                            return;
                        }
                        foreach (var msg in item)
                        {
                            if (Tasks >= Config.MaxTasks)
                            {
                                Thread.Sleep(100);
                            }

                            Tasks++;
                            var now = LinuxTime.Seconds(DateTime.Now);
                            if ((now - msg.utc_time) > 60)
                            {
                                msg.status = Message.service_status.offLine.ToString();
                                if (LogHelper.enable)
                                {
                                    Console.WriteLine("Loop-----------------------" + DateTime.Now);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message.ToString());
                }
                finally { Tasks = 0; }
            }));
        }
Esempio n. 3
0
        internal static void closeConn(Message service)
        {
            if (!data.ContainsKey(service.name))
            {
                data[service.name] = new List <Message>();
            }
            List <Message> services = data[service.name];

            lock (services)
            {
                if (services != null)
                {
                    foreach (var item in services)
                    {
                        if (item.id == service.id && item.name == service.name)
                        {
                            //服务状态重置为false
                            item.status   = Util.To <string>(Message.service_status.offLine);
                            item.utc_time = LinuxTime.Seconds(DateTime.Now);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        internal static void heartBeatPackage(Message service)
        {
            if (!data.ContainsKey(service.name))
            {
                data[service.name] = new List <Message>();
            }
            List <Message> services = data[service.name];

            lock (services)
            {
                if (services != null)
                {
                    List <Message> result = new List <Message>();
                    foreach (var item in services)
                    {
                        if (item.id == service.id && item.name == service.name)
                        {
                            item.utc_time = LinuxTime.Seconds(DateTime.Now);
                            item.status   = Util.To <string>(Message.service_status.alive);
                        }
                    }
                }
            }
        }