Exemplo n.º 1
0
        protected void Clear(bool assertOpen)
        {
            if (assertOpen)
            {
                AssertOpen();
            }

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

                    while (!pool.IsEmpty())
                    {
                        TimeRecord <TItem> record = pool.Poll();

                        if (record != null)
                        {
                            Destroy(entry.Key, record.Item, false);
                        }
                    }
                }
            }
            finally
            {
                KeyLock.ReleaseReaderLock();
            }
        }
Exemplo n.º 2
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.º 3
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();
            }
        }