Ejemplo n.º 1
0
        private void CheckIncomgCacheThreshold()
        {
            try
            {
                var incomingPackages = _productCacheReceive.GetData();
                var currentCount     = incomingPackages.Count();

                #region "队列个数检查"
                try
                {
                    if (currentCount >= CacheCountThreshold && currentCount % CacheCountThreshold == 0)
                    {
                        var info = new StringBuilder(string.Format("未处理的用户数据个数已达到阈值({0})的{1}倍。",
                                                                   CacheCountThreshold, currentCount / CacheCountThreshold));
                    }

                    // “接收队列个数改变”事件通知。
                    if (currentCount != _lastReceiveCacheCount &&
                        this.IncomingCacheCountChanged != null)
                    {
                        _lastReceiveCacheCount = currentCount;
                        this.IncomingCacheCountChanged(null, new IncomingCacheCountChangedEventArgs(this.Name, currentCount));
                    }
                }
                catch (System.Exception /*ex*/)
                {
                }
                #endregion

                #region "时间检查"
                try
                {
                    if (currentCount > 0)
                    {
                        var farthestTime = incomingPackages.Min(p => p.CreationTime);
                        var blockingTime = Convert.ToInt32((DateTime.Now - farthestTime).TotalSeconds);

                        // “接收队列超过阈值”事件通知。
                        if (this.IncomingCacheDelayed != null &&
                            (blockingTime > BlockingTimeThreshold) &&
                            (blockingTime != _lastReceiveQueueBlockingTime))
                        {
                            _lastReceiveQueueBlockingTime = blockingTime;

                            var args = new IncomingCacheDelayedEventArgs(this.Name, currentCount, CacheCountThreshold,
                                                                         farthestTime);

                            this.IncomingCacheDelayed(null, args);
                        }
                    }
                }
                catch (System.Exception /*ex*/)
                {
                }
                #endregion
            }
            catch (System.Exception)
            {
            }
        }
Ejemplo n.º 2
0
        private void CheckOutgoingCacheThreshold()
        {
            try
            {
                var allPkg       = _productCacheSending.GetData();
                int currentCount = allPkg.Count();

                #region "队列个数检查"
                try
                {
                    if (currentCount >= CacheCountThreshold && currentCount % CacheCountThreshold == 0)
                    {
                        LogUtility.Warn(string.Format("未发送的用户数据个数已达到阈值({0})的{1}倍。",
                                                      CacheCountThreshold, currentCount / CacheCountThreshold));
                    }

                    // “发送队列个数改变”事件通知。
                    if (currentCount != _lastSendingCacheCount &&
                        this.OutgoingCacheCountChanged != null)
                    {
                        _lastSendingCacheCount = currentCount;
                        this.OutgoingCacheCountChanged(null, new OutgoingCacheCountChangedEventArgs(this.Name, currentCount));
                    }
                }
                catch (System.Exception /*ex*/)
                {
                }
                #endregion

                #region "时间检查"
                try
                {
                    if (currentCount > 0)
                    {
                        var farthestTime = allPkg.Min(p => p.CreationTime);
                        var blockingTime = Convert.ToInt32((DateTime.Now - farthestTime).TotalSeconds);

                        if (this.OutgoingCacheDelayed != null &&
                            blockingTime > BlockingTimeThreshold &&
                            (blockingTime != _lastSendQueueBlockingTime))
                        {
                            _lastSendQueueBlockingTime = blockingTime;

                            var args = new OutgoingCacheDelayedEventArgs(this.Name, currentCount, CacheCountThreshold,
                                                                         farthestTime);
                            this.OutgoingCacheDelayed(null, args);
                        }
                    }
                }
                catch (System.Exception /*ex*/)
                {
                }
                #endregion
            }
            catch (System.Exception)
            {
            }
        }