Ejemplo n.º 1
0
        public void WaitUntil(TimeSpan timeout, EndPointIs upOrDown)
        {
            var stopWatch = Stopwatch.StartNew();

            try
            {
                while (Interlocked.Read(ref isRunning) == 1)
                {
                    try
                    {
                        if (Interlocked.Read(ref isUp) == (upOrDown == EndPointIs.Up ? 1 : 0))
                        {
                            break;
                        }

                        if (stopWatch.Elapsed > timeout)
                        {
                            throw new EndPointMonitorWaitTimeoutException($"{EndPoint} failed to come up in {stopWatch.Elapsed.TotalSeconds} second(s).");
                        }
                    }
                    finally
                    {
                        if (Interlocked.Read(ref isUp) != (upOrDown == EndPointIs.Up ? 1 : 0))
                        {
                            Thread.Sleep(Constants.END_POINT_MONTIOR_SLEEP_INTERVAL);
                        }
                    }
                }
            }
            finally
            {
                stopWatch.Stop();
            }
        }
Ejemplo n.º 2
0
        public static void WaitUntil(EndPoint endPoint, EndPointIs upOrDown)
        {
            var endPointMonitor = new EndPointMonitor(endPoint);

            try
            {
                endPointMonitor.WaitUntil(Constants.END_POINT_UP_WAIT_FOR_TIMEOUT, upOrDown);
            }
            finally
            {
                endPointMonitor.Dispose();
            }
        }