Return-Path: Delivered-To: apmail-lucene-lucene-net-commits-archive@www.apache.org Received: (qmail 38294 invoked from network); 17 Feb 2010 21:57:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Feb 2010 21:57:41 -0000 Received: (qmail 45849 invoked by uid 500); 17 Feb 2010 21:57:41 -0000 Delivered-To: apmail-lucene-lucene-net-commits-archive@lucene.apache.org Received: (qmail 45794 invoked by uid 500); 17 Feb 2010 21:57:41 -0000 Mailing-List: contact lucene-net-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-dev@lucene.apache.org Delivered-To: mailing list lucene-net-commits@lucene.apache.org Received: (qmail 45785 invoked by uid 99); 17 Feb 2010 21:57:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Feb 2010 21:57:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Feb 2010 21:57:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A6EFE2388993; Wed, 17 Feb 2010 21:57:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r911185 - /lucene/lucene.net/trunk/C#/src/Lucene.Net/Search/FilterManager.cs Date: Wed, 17 Feb 2010 21:57:11 -0000 To: lucene-net-commits@lucene.apache.org From: mgarski@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100217215711.A6EFE2388993@eris.apache.org> Author: mgarski Date: Wed Feb 17 21:57:11 2010 New Revision: 911185 URL: http://svn.apache.org/viewvc?rev=911185&view=rev Log: LUCENENET-339 : Fix for exception thrown by FilterCleaner Modified: lucene/lucene.net/trunk/C#/src/Lucene.Net/Search/FilterManager.cs Modified: lucene/lucene.net/trunk/C#/src/Lucene.Net/Search/FilterManager.cs URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/src/Lucene.Net/Search/FilterManager.cs?rev=911185&r1=911184&r2=911185&view=diff ============================================================================== --- lucene/lucene.net/trunk/C#/src/Lucene.Net/Search/FilterManager.cs (original) +++ lucene/lucene.net/trunk/C#/src/Lucene.Net/Search/FilterManager.cs Wed Feb 17 21:57:11 2010 @@ -16,6 +16,7 @@ */ using System; +using System.Collections.Generic; namespace Lucene.Net.Search { @@ -163,71 +164,27 @@ /// protected internal class FilterCleaner : IThreadRunnable { - private class AnonymousClassComparator : System.Collections.Generic.IComparer - { - public AnonymousClassComparator(FilterCleaner enclosingInstance) - { - InitBlock(enclosingInstance); - } - private void InitBlock(FilterCleaner enclosingInstance) - { - this.enclosingInstance = enclosingInstance; - } - private FilterCleaner enclosingInstance; - public FilterCleaner Enclosing_Instance - { - get - { - return enclosingInstance; - } - - } - public virtual int Compare(System.Object a, System.Object b) - { - if (a is System.Collections.DictionaryEntry && b is System.Collections.DictionaryEntry) - { - FilterItem fia = (FilterItem) ((System.Collections.DictionaryEntry) a).Value; - FilterItem fib = (FilterItem) ((System.Collections.DictionaryEntry) b).Value; - if (fia.timestamp == fib.timestamp) - { - return 0; - } - // smaller timestamp first - if (fia.timestamp < fib.timestamp) - { - return - 1; - } - // larger timestamp last - return 1; - } - else - { - throw new System.InvalidCastException("Objects are not Map.Entry"); - } - } - } - private void InitBlock(FilterManager enclosingInstance) - { - this.enclosingInstance = enclosingInstance; - } - private FilterManager enclosingInstance; - public FilterManager Enclosing_Instance - { - get - { - return enclosingInstance; - } - - } + private class FilterItemComparer : IComparer + { + #region IComparer Members + + public int Compare(FilterItem x, FilterItem y) + { + return x.timestamp.CompareTo(y.timestamp); + } + + #endregion + } private bool running = true; - private System.Collections.Generic.SortedDictionary sortedFilterItems; + private FilterManager manager; + private List filterItems; public FilterCleaner(FilterManager enclosingInstance) { - InitBlock(enclosingInstance); - sortedFilterItems = new System.Collections.Generic.SortedDictionary(new AnonymousClassComparator(this)); - } + this.manager = enclosingInstance; + filterItems = new List(); + } public virtual void Run() { @@ -236,34 +193,32 @@ // sort items from oldest to newest // we delete the oldest filters - if (Enclosing_Instance.cache.Count > Enclosing_Instance.cacheCleanSize) + if (this.manager.cache.Count > this.manager.cacheCleanSize) { // empty the temporary set - sortedFilterItems.Clear(); - lock (Enclosing_Instance.cache.SyncRoot) + filterItems.Clear(); + lock (this.manager.cache.SyncRoot) { - System.Collections.IDictionaryEnumerator entries = Enclosing_Instance.cache.GetEnumerator(); - while (entries.MoveNext()) + foreach (FilterItem item in this.manager.cache.Values) { - sortedFilterItems.Add(entries.Entry.Key, entries.Entry.Value); + filterItems.Add(item); } - System.Collections.IEnumerator it = sortedFilterItems.GetEnumerator(); - int numToDelete = (int) ((Enclosing_Instance.cache.Count - Enclosing_Instance.cacheCleanSize) * 1.5); - int counter = 0; + filterItems.Sort(new FilterItemComparer()); + + int numToDelete = (int)((this.manager.cache.Count - this.manager.cacheCleanSize) * 1.5); // loop over the set and delete all of the cache entries not used in a while - while (it.MoveNext() && counter++ < numToDelete) - { - System.Collections.DictionaryEntry entry = (System.Collections.DictionaryEntry) it.Current; - Enclosing_Instance.cache.Remove(entry.Key); - } + for(int i = 0; i < numToDelete; i++) + { + this.manager.cache.Remove(filterItems[i].filter.GetHashCode()); + } } // empty the set so we don't tie up the memory - sortedFilterItems.Clear(); + filterItems.Clear(); } // take a nap try { - System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * Enclosing_Instance.cleanSleepTime)); + System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64)10000 * this.manager.cleanSleepTime)); } catch (System.Threading.ThreadInterruptedException ie) {