Esempio n. 1
0
        protected void ReceivedUpdate()
        {
            IMdbSystemMailboxPinger mdbSystemMailboxPinger = this.pingerReference;

            if (mdbSystemMailboxPinger == null && PingerCache.CreatePingerTestHook != null)
            {
                mdbSystemMailboxPinger = PingerCache.CreatePingerTestHook(this.MdbGuid);
            }
            if (mdbSystemMailboxPinger != null)
            {
                if (mdbSystemMailboxPinger.Pinging)
                {
                    ExTraceGlobals.DatabasePingerTracer.TraceDebug <Guid>((long)this.GetHashCode(), "RPC traffic due to database pinger for Mdb: {0}", this.MdbGuid);
                    Interlocked.Increment(ref this.consecutivePings);
                }
                else
                {
                    Interlocked.Exchange(ref this.consecutivePings, 0);
                }
                if (PingerDependentHealthMonitor.OnPingIntervalUpdate != null)
                {
                    PingerDependentHealthMonitor.OnPingIntervalUpdate(base.Key, this.consecutivePings, this.CurrentPingInterval);
                }
            }
        }
Esempio n. 2
0
        private void PingIfNecessary()
        {
            if (this.pingCheckedOrScheduled)
            {
                this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.PingAlreadyScheduled);
                return;
            }
            bool flag = true;

            try
            {
                lock (this.instanceLock)
                {
                    if (this.pingCheckedOrScheduled)
                    {
                        this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.PingAlreadyScheduled);
                        return;
                    }
                    this.pingCheckedOrScheduled = true;
                }
                if (this.RawLastUpdateUtc != DateTime.MinValue && TimeProvider.UtcNow - this.RawLastUpdateUtc < this.PreviousPingInterval && !PingerDependentHealthMonitor.IgnorePingProximity)
                {
                    this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.TrafficTooClose);
                }
                else if (this.Expired)
                {
                    this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.MonitorExpired);
                    ExTraceGlobals.DatabasePingerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[PingerDependentHealthMonitor.Execute] Will not ping on resource {0} because the monitor is marked as expired.", base.Key);
                }
                else
                {
                    IMdbSystemMailboxPinger mdbSystemMailboxPinger = PingerCache.Singleton.Get(this.MdbGuid);
                    if (!object.ReferenceEquals(mdbSystemMailboxPinger, this.pingerReference))
                    {
                        lock (this.instanceLock)
                        {
                            if (!object.ReferenceEquals(mdbSystemMailboxPinger, this.pingerReference))
                            {
                                this.pingerReference = mdbSystemMailboxPinger;
                            }
                        }
                    }
                    if (mdbSystemMailboxPinger == null)
                    {
                        this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.FailedToGetPinger);
                        ExTraceGlobals.DatabasePingerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[PingerDependentHealthMonitor.Execute] PingerCache returned a null pinger.  Will not ping.  Resource: {0}", base.Key);
                    }
                    else if (mdbSystemMailboxPinger.LastPingAttemptUtc != DateTime.MinValue && TimeProvider.UtcNow - mdbSystemMailboxPinger.LastPingAttemptUtc < this.PreviousPingInterval && !PingerDependentHealthMonitor.IgnorePingProximity)
                    {
                        TimeSpan arg = TimeProvider.UtcNow - mdbSystemMailboxPinger.LastPingAttemptUtc;
                        this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.PingAttemptTooClose);
                        ExTraceGlobals.DatabasePingerTracer.TraceDebug <ResourceKey, TimeSpan, TimeSpan>((long)this.GetHashCode(), "[PingerDependentHealthMonitor.Execute] Will not ping on resource {0} because only {1} has elapsed since the last ping attempt. Expected interval: {2}", base.Key, arg, this.PreviousPingInterval);
                    }
                    else
                    {
                        ThreadPool.QueueUserWorkItem(delegate(object state)
                        {
                            try
                            {
                                IMdbSystemMailboxPinger mdbSystemMailboxPinger2 = PingerCache.Singleton.Get(this.MdbGuid);
                                if (mdbSystemMailboxPinger2 == null)
                                {
                                    this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.FailedToGetPinger);
                                    ExTraceGlobals.DatabasePingerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[PingerDependentHealthMonitor.Execute] PingerCache returned a null pinger.  Will not ping.  Resource: {0}", base.Key);
                                }
                                else if (mdbSystemMailboxPinger2.Ping())
                                {
                                    this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.Pinged);
                                }
                                else
                                {
                                    Interlocked.Increment(ref this.consecutivePings);
                                    if (PingerDependentHealthMonitor.OnPingIntervalUpdate != null)
                                    {
                                        PingerDependentHealthMonitor.OnPingIntervalUpdate(base.Key, this.consecutivePings, this.CurrentPingInterval);
                                    }
                                    this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.FailedPing);
                                }
                            }
                            finally
                            {
                                lock (this.instanceLock)
                                {
                                    this.pingCheckedOrScheduled = false;
                                }
                                this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.PingLockReleased);
                            }
                        });
                        flag = false;
                    }
                }
            }
            finally
            {
                if (flag)
                {
                    lock (this.instanceLock)
                    {
                        this.pingCheckedOrScheduled = false;
                    }
                    this.DoOnExecuteForTest(PingerDependentHealthMonitor.PingResult.PingLockReleased);
                }
            }
        }