Exemple #1
0
        private static void DoPing(object o)
        {
            PingerJob job = o as PingerJob;

            job.Run();
        }
Exemple #2
0
        public override void OnRun()
        {            
            Dictionary<string, ServerInfo> servers;

            for (; ; )
            {
				if (GetCanRun() == false)
                {
                    Sleep(1000);
                }
                else
                {
					// Note: If Pinger is not enabled, works like all ping results is 0.						
					bool enabled = GetEnabled();					
					int delaySuccess = getPingerDelaySuccess();
					int delayRetry = getPingerDelayRetry();

					int timeNow = Utils.UnixTimeStamp();
					int jobsLimit = Engine.Instance.Storage.GetInt("advanced.pinger.jobs");

					lock (Engine.Servers)
                        servers = new Dictionary<string, ServerInfo>(Engine.Servers);
					
					bool startOne = false;

                    foreach (ServerInfo infoServer in servers.Values)
                    {
						if (GetCanRun() == false)
							break;

						int delay = delaySuccess;
						if (infoServer.PingFailedConsecutive > 0)
							delay = delayRetry;

						if(timeNow - infoServer.LastPingTest >= delay)								
						{
							if (enabled)
							{
								if (Jobs.Count < jobsLimit)
								{
									infoServer.LastPingTest = timeNow;
									
									PingerJob job = new PingerJob();
									job.Server = infoServer;
									/*
									lock (Jobs)
									{
										Jobs.Add(job);										
									}
									job.Start();
									*/

									ThreadPool.QueueUserWorkItem(new WaitCallback(DoPing), job);
									startOne = true;
								}
							}
							else
							{
								infoServer.LastPingTest = timeNow;
								infoServer.PingTests = 0;
								infoServer.PingFailedConsecutive = 0;
								infoServer.Ping = 0;
								infoServer.LastPingResult = infoServer.LastPingTest;
								infoServer.LastPingSuccess = infoServer.LastPingTest;
							}
						}
						
                        if (CancelRequested)
                            return;
                    }
					
					if (startOne)
						Sleep(100); // Waiting for a queue slot
					else
						Sleep(1000); // Waiting for a ping need
                }
                                
                if (CancelRequested)
                    return;

				
            }
        }
Exemple #3
0
        public override void OnRun()
        {
            Dictionary <string, ServerInfo> servers;

            for (; ;)
            {
                if (GetCanRun() == false)
                {
                    Sleep(1000);
                }
                else
                {
                    // Note: If Pinger is not enabled, works like all ping results is 0.
                    bool enabled      = GetEnabled();
                    int  delaySuccess = getPingerDelaySuccess();
                    int  delayRetry   = getPingerDelayRetry();

                    int timeNow   = Utils.UnixTimeStamp();
                    int jobsLimit = Engine.Instance.Storage.GetInt("advanced.pinger.jobs");

                    lock (Engine.Servers)
                        servers = new Dictionary <string, ServerInfo>(Engine.Servers);

                    bool startOne = false;

                    foreach (ServerInfo infoServer in servers.Values)
                    {
                        if (GetCanRun() == false)
                        {
                            break;
                        }

                        int delay = delaySuccess;
                        if (infoServer.PingFailedConsecutive > 0)
                        {
                            delay = delayRetry;
                        }

                        if (timeNow - infoServer.LastPingTest >= delay)
                        {
                            if (enabled)
                            {
                                if (Jobs.Count < jobsLimit)
                                {
                                    infoServer.LastPingTest = timeNow;

                                    PingerJob job = new PingerJob();
                                    job.Server = infoServer;

                                    /*
                                     * lock (Jobs)
                                     * {
                                     *      Jobs.Add(job);
                                     * }
                                     * job.Start();
                                     */

                                    ThreadPool.QueueUserWorkItem(new WaitCallback(DoPing), job);
                                    startOne = true;
                                }
                            }
                            else
                            {
                                infoServer.LastPingTest          = timeNow;
                                infoServer.PingTests             = 0;
                                infoServer.PingFailedConsecutive = 0;
                                infoServer.Ping            = 0;
                                infoServer.LastPingResult  = infoServer.LastPingTest;
                                infoServer.LastPingSuccess = infoServer.LastPingTest;
                            }
                        }

                        if (CancelRequested)
                        {
                            return;
                        }
                    }

                    if (startOne)
                    {
                        Sleep(100);                         // Waiting for a queue slot
                    }
                    else
                    {
                        Sleep(1000);                         // Waiting for a ping need
                    }
                }

                if (CancelRequested)
                {
                    return;
                }
            }
        }