Exemplo n.º 1
0
        private void EvictIdleItems(object source, ElapsedEventArgs e)
        {
            AssertOpen();

            TimeSpan noWait = new TimeSpan(0);

            evictionTimer.Stop();

            KeyLock.AcquireReaderLock(new TimeSpan(-1));
            try
            {
                try
                {
                    foreach (KeyValuePair <TKey, Threading.IQueue <TimeRecord <TItem> > > entry in Keys)
                    {
                        Threading.IQueue <TimeRecord <TItem> > pool = entry.Value;

                        TimeRecord <TItem> record;

                        while ((record = pool.Peek()) != null)
                        {
                            if (evictionCriteria.Evict(record, pool.Size()))
                            {
                                record = pool.Poll(noWait);

                                if (record != null)
                                {
                                    ShrinkPool(entry.Key, record.Item);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                catch (Exception x)
                {
                    Logger.Error(x.Message);
                }
            }
            finally
            {
                KeyLock.ReleaseReaderLock();

                evictionTimer.Start();
            }
        }
Exemplo n.º 2
0
        private void EvictIdleItems(object source, ElapsedEventArgs e)
        {
            AssertOpen();

            TimeSpan noWait = new TimeSpan(0);

            evictionTimer.Stop();
            try
            {
                TimeRecord <TItem> record;

                while ((record = pool.Peek()) != null)
                {
                    if (evictionCriteria.Evict(record, pool.Size()))
                    {
                        record = pool.Poll(noWait);

                        if (record != null)
                        {
                            ShrinkPool(record.Item);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (Exception x)
            {
                Logger.Error(x.Message);
            }
            finally
            {
                evictionTimer.Start();
            }
        }