Exemple #1
0
        public void EnqueuRequest(ProcCommand request)
        {
#if NET40
            _semaLock.Enter();

            _commandsQueue.Enqueue(request);

            if (_workerWaiting)
            {
                lock (_queueLock){
                    Monitor.Pulse(_queueLock);
                }
            }

            _semaLock.Exit();
#else
            lock (_queueLock)
            {
                _commandsQueue.Enqueue(request);
                if (_workerWaiting)
                {
                    Monitor.Pulse(_queueLock);
                }
            }
#endif
        }
Exemple #2
0
        public void EnqueueEvent(IEvent request)
        {
#if NET40
            try
            {
                _semaLock.Enter();

                _eventsQueue.Enqueue(request);

                if (_workerWaiting)
                {
                    lock (_queueLock)
                    {
                        Monitor.Pulse(_queueLock);
                    }
                }
            }
            finally
            {
                _semaLock.Exit();
            }
#else
            lock (_queueLock)
            {
                _eventsQueue.Enqueue(request);
                if (_workerWaiting)
                {
                    Monitor.Pulse(_queueLock);
                }
            }
#endif
        }
        private void IncrementBucketStats(string key, int bucketId, long dataSize)
        {
            if (_stats.LocalBuckets != null && _stats.LocalBuckets.Contains(bucketId))
            {
                ((BucketStatistics)_stats.LocalBuckets[bucketId]).Increment(dataSize);
            }

            if (_keyList == null)
            {
                _keyList = new HashVector();
            }

            if (_keyList != null)
            {
                HashVector keys;
                bool       isKeyExist = false;

                _keyListLock.Enter();

                if (!_keyList.Contains(bucketId))
                {
                    keys      = new HashVector();
                    keys[key] = null;
                    long keySize     = keys.BucketCount * MemoryUtil.NetHashtableOverHead;
                    long currentsize = _keyListSize;
                    _keyListSize       = currentsize + keySize;
                    _keyList[bucketId] = keys;
                    isKeyExist         = true;
                }

                _keyListLock.Exit();

                if (isKeyExist)
                {
                    return;
                }
                keys = (HashVector)_keyList[bucketId];
                long oldSize = keys.BucketCount * MemoryUtil.NetHashtableOverHead;
                lock (keys)
                {
                    keys[key] = null;
                }
                long newSize = keys.BucketCount * MemoryUtil.NetHashtableOverHead;
                long tmpsize = _keyListSize;
                _keyListSize = tmpsize + (newSize - oldSize);
            }
        }
Exemple #4
0
        private void IncrementBucketStats(string cacheKeyOrMessageId, int bucketId, long dataSize, bool isMessage, string topic)
        {
            lock (_bucketStatsMutex)
            {
                if (_stats.LocalBuckets != null && _stats.LocalBuckets.Contains(bucketId))
                {
                    if (isMessage)
                    {
                        ((BucketStatistics)_stats.LocalBuckets[bucketId]).IncrementTopicStats(topic, dataSize);
                    }
                    else
                    {
                        ((BucketStatistics)_stats.LocalBuckets[bucketId]).Increment(dataSize);
                    }
                }
            }

            if (_keyList == null)
            {
                _keyList = new HashVector();
            }
            if (_keyList != null)
            {
                HashVector      keys;
                BucketStatistcs bucketStats = null;
                bool            isKeyExist  = false;

#if NET40
                try
                {
                    _keyListLock.Enter();
#else
                lock (_keyListLock)
                {
#endif
                    if (!_keyList.Contains(bucketId))
                    {
                        bucketStats        = new BucketStatistcs(bucketId);
                        _keyList[bucketId] = bucketStats;

                        if (isMessage)
                        {
                            bucketStats.AddMessage(topic, cacheKeyOrMessageId);
                        }
                        else
                        {
                            bucketStats.AddCacheKey(cacheKeyOrMessageId);
                        }

                        _inMemorySize += bucketStats.InMemorySize;
                        isKeyExist     = true;
                    }
                    else
                    {
                    }
#if NET40
                }
                finally
                {
                    _keyListLock.Exit();
                }
#else
                }
#endif
                if (isKeyExist)
                {
                    return;
                }

                bucketStats = (BucketStatistcs)_keyList[bucketId];
                long oldSize = bucketStats.InMemorySize;

                lock (bucketStats)
                {
                    if (isMessage)
                    {
                        bucketStats.AddMessage(topic, cacheKeyOrMessageId);
                    }
                    else
                    {
                        bucketStats.AddCacheKey(cacheKeyOrMessageId);
                    }
                }

                long newSize = bucketStats.InMemorySize;
                long tmpsize = _inMemorySize;

                _inMemorySize = tmpsize + (newSize - oldSize);
            }