コード例 #1
0
        // Token: 0x0600768A RID: 30346 RVA: 0x001865DC File Offset: 0x001847DC
        private bool HandleResourceCacheShouldRemove(ResourceKey key, CacheableResourceHealthMonitor monitor)
        {
            bool flag = false;
            bool result;

            try
            {
                if (monitor is IResourceHealthPoller)
                {
                    if (!Monitor.TryEnter(monitor, 0))
                    {
                        ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.HandleResourceCacheShouldRemove] Could not grab the monitor - extending life in cache for key: {0}", key);
                        return(false);
                    }
                    flag = true;
                }
                bool flag2 = true;
                if (monitor != null)
                {
                    flag2 = (DateTime.UtcNow - monitor.LastAccessUtc > ResourceHealthMonitorManager.MonitorSlidingExpiration && monitor.ShouldRemoveResourceFromCache());
                }
                if (flag2)
                {
                    this.pollingMonitors.Remove(key);
                    monitor.Expire();
                }
                result = flag2;
            }
            finally
            {
                if (flag)
                {
                    Monitor.Exit(monitor);
                }
            }
            return(result);
        }
コード例 #2
0
 public ResourceUnhealthyException(ResourceKey resourceKey) : base(DirectoryStrings.ExceptionResourceUnhealthy(resourceKey))
 {
     this.resourceKey = resourceKey;
 }
コード例 #3
0
        public override bool Equals(object obj)
        {
            ResourceKey resourceKey = obj as ResourceKey;

            return(resourceKey != null && this.MetricType == resourceKey.MetricType && string.Equals(this.Id, resourceKey.Id, StringComparison.OrdinalIgnoreCase));
        }
コード例 #4
0
        // Token: 0x0600768C RID: 30348 RVA: 0x001866AC File Offset: 0x001848AC
        private bool HandlePollingItemShouldRemove(ResourceKey key, IResourceHealthPoller value)
        {
            ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.HandlePollingItemShouldRemove] Firing poll for monitor {0}", key);
            if (!VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).WorkloadManagement.GetObject <IResourceSettings>(key.MetricType, new object[0]).Enabled)
            {
                return(false);
            }
            CacheableResourceHealthMonitor cacheableResourceHealthMonitor = value as CacheableResourceHealthMonitor;

            if (cacheableResourceHealthMonitor.Expired)
            {
                ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.HandlePollingItemShouldRemove] Monitor has already expired - will not poll for key: {0}", key);
                return(false);
            }
            bool flag = false;

            try
            {
                if (!Monitor.TryEnter(value, 0))
                {
                    ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.HandlePollingItemShouldRemove] Could not obtain lock.  Will not poll for key: {0}", key);
                    return(false);
                }
                flag = true;
                if (cacheableResourceHealthMonitor.Expired)
                {
                    return(false);
                }
                if (!value.IsActive)
                {
                    return(false);
                }
                bool flag2 = false;
                try
                {
                    lock (this.instanceLock)
                    {
                        if (!this.outstandingPollCalls.ContainsKey(key))
                        {
                            this.outstandingPollCalls[key] = true;
                            flag2 = true;
                        }
                    }
                    if (flag2)
                    {
                        try
                        {
                            value.Execute();
                        }
                        catch (DataSourceTransientException ex)
                        {
                            ExTraceGlobals.ResourceHealthManagerTracer.TraceError <ResourceKey, string>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.HandlePollingItemShouldRemove] Failed to set metrics for monitor {0}. Exception: {1}", key, ex.Message);
                            return(false);
                        }
                    }
                }
                finally
                {
                    if (flag2)
                    {
                        lock (this.instanceLock)
                        {
                            this.outstandingPollCalls.Remove(key);
                        }
                    }
                }
            }
            finally
            {
                if (flag)
                {
                    Monitor.Exit(value);
                }
            }
            return(false);
        }
コード例 #5
0
 // Token: 0x06007689 RID: 30345 RVA: 0x001865CC File Offset: 0x001847CC
 internal bool IsCached(ResourceKey resourceKey)
 {
     return(this.monitors.Contains(resourceKey));
 }
コード例 #6
0
        // Token: 0x06007686 RID: 30342 RVA: 0x00186284 File Offset: 0x00184484
        public IResourceLoadMonitor Get(ResourceKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            CacheableResourceHealthMonitor cacheableResourceHealthMonitor = null;

            if (!this.monitors.TryGetValue(key, out cacheableResourceHealthMonitor))
            {
                bool flag  = false;
                bool flag2 = false;
                bool flag3 = true;
                CacheableResourceHealthMonitor cacheableResourceHealthMonitor2 = null;
                try
                {
                    if (ResourceHealthMonitorManager.Active && ExTraceGlobals.ResourceHealthManagerTracer.IsTraceEnabled(TraceType.DebugTrace))
                    {
                        StackTrace arg = new StackTrace();
                        ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceHealthComponent, ResourceKey, StackTrace>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.Get] Creating new monitor for component '{0}'.  Resource Identity: {1}, Stack Trace: {2}", ResourceHealthMonitorManager.resourceHealthComponent, key, arg);
                    }
                    cacheableResourceHealthMonitor2 = ((ResourceHealthMonitorManager.Active && key.MetricType != ResourceMetricType.None) ? key.CreateMonitor() : new DummyResourceHealthMonitor(key));
                    lock (this.instanceLock)
                    {
                        if (!this.monitors.TryGetValue(key, out cacheableResourceHealthMonitor))
                        {
                            flag3 = false;
                            flag2 = true;
                            if (cacheableResourceHealthMonitor2 is DummyResourceHealthMonitor)
                            {
                                ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager.Get] Dummy monitor created for resource key {0}", key);
                                this.monitors.TryAddAbsolute(key, cacheableResourceHealthMonitor2, ResourceHealthMonitorManager.DummyMonitorAbsoluteExpiration);
                            }
                            else
                            {
                                this.monitors.TryAddAbsolute(key, cacheableResourceHealthMonitor2, ResourceHealthMonitorManager.MonitorSlidingExpiration);
                            }
                            cacheableResourceHealthMonitor = cacheableResourceHealthMonitor2;
                            flag = true;
                        }
                    }
                }
                finally
                {
                    if (flag3 && cacheableResourceHealthMonitor2 != null)
                    {
                        cacheableResourceHealthMonitor2.Expire();
                        IDisposable disposable = cacheableResourceHealthMonitor2 as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                        cacheableResourceHealthMonitor2 = null;
                    }
                }
                if (flag2)
                {
                    ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager::Get] Cache miss for key '{0}'", key);
                }
                if (flag)
                {
                    IResourceHealthPoller pollHealth = cacheableResourceHealthMonitor as IResourceHealthPoller;
                    if (pollHealth != null)
                    {
                        using (ActivityContext.SuppressThreadScope())
                        {
                            ThreadPool.QueueUserWorkItem(delegate(object state)
                            {
                                this.HandlePollingItemShouldRemove(key, pollHealth);
                            });
                        }
                        ExTraceGlobals.ClientThrottlingTracer.TraceDebug <ResourceKey>((long)this.GetHashCode(), "[ResourceHealthMonitorManager::Get] Adding monitor as polling monitor: {0}", key);
                        this.pollingMonitors.TryAddAbsolute(key, pollHealth, pollHealth.Interval);
                    }
                }
            }
            return(cacheableResourceHealthMonitor.CreateWrapper());
        }
コード例 #7
0
 internal DummyResourceHealthMonitor(ResourceKey key) : base(key)
 {
 }