lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [07/20] lucenenet git commit: Lucene.Net.Core.Analysis.TokenStream: implemented .NET dispose pattern
Date Sun, 02 Apr 2017 07:06:07 GMT
Lucene.Net.Core.Analysis.TokenStream: implemented .NET dispose pattern


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/c8c94d13
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/c8c94d13
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/c8c94d13

Branch: refs/heads/api-work
Commit: c8c94d1328f2959f48b0123fa2c0299bf9bde28a
Parents: b3627a7
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Apr 2 10:05:15 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Apr 2 11:58:32 2017 +0700

----------------------------------------------------------------------
 .../Analysis/Miscellaneous/PatternAnalyzer.cs     | 18 ++++++++++++------
 .../PrefixAndSuffixAwareTokenFilter.cs            |  7 +++++--
 .../Miscellaneous/PrefixAwareTokenFilter.cs       |  9 ++++++---
 .../Analysis/Standard/ClassicTokenizer.cs         |  9 ++++++---
 .../Analysis/Standard/StandardTokenizer.cs        |  9 ++++++---
 .../Analysis/Standard/UAX29URLEmailTokenizer.cs   |  9 ++++++---
 .../Analysis/Wikipedia/WikipediaTokenizer.cs      |  9 ++++++---
 src/Lucene.Net.Core/Analysis/TokenFilter.cs       |  9 ++++++---
 src/Lucene.Net.Core/Analysis/TokenStream.cs       |  9 ++++++++-
 src/Lucene.Net.Core/Analysis/Tokenizer.cs         | 15 +++++++++------
 .../Analysis/MockGraphTokenFilter.cs              |  9 ++++++---
 .../Analysis/MockTokenizer.cs                     | 17 ++++++++++-------
 .../Analysis/Core/TestBugInSomething.cs           |  9 ++++++---
 .../Highlight/HighlighterTest.cs                  |  9 ++++++---
 src/Lucene.Net.Tests/Index/TestPayloads.cs        |  7 +++++--
 15 files changed, 103 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs
index 4b5da76..251d30f 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs
@@ -432,10 +432,13 @@ namespace Lucene.Net.Analysis.Miscellaneous
                 this.offsetAtt.SetOffset(finalOffset, finalOffset);
             }
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
-                base.Dispose();
-                this.initialized = false;
+                if (disposing)
+                {
+                    base.Dispose();
+                    this.initialized = false;
+                }
             }
 
             public override void Reset()
@@ -566,10 +569,13 @@ namespace Lucene.Net.Analysis.Miscellaneous
                 return stopWords != null && stopWords.Contains(text);
             }
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
-                base.Dispose();
-                this.str = null;
+                if (disposing)
+                {
+                    base.Dispose();
+                    this.str = null;
+                }
             }
 
             public override void Reset()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAndSuffixAwareTokenFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAndSuffixAwareTokenFilter.cs
b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAndSuffixAwareTokenFilter.cs
index 2479b33..2536cd0 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAndSuffixAwareTokenFilter.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAndSuffixAwareTokenFilter.cs
@@ -89,9 +89,12 @@
             suffix.Reset();
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            suffix.Dispose();
+            if (disposing)
+            {
+                suffix.Dispose();
+            }
         }
 
         public override void End()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAwareTokenFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAwareTokenFilter.cs
b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAwareTokenFilter.cs
index cef54d0..cf61f29 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAwareTokenFilter.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PrefixAwareTokenFilter.cs
@@ -174,10 +174,13 @@ namespace Lucene.Net.Analysis.Miscellaneous
             suffix.End();
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            prefix.Dispose();
-            suffix.Dispose();
+            if (disposing)
+            {
+                prefix.Dispose();
+                suffix.Dispose();
+            }
         }
 
         public override void Reset()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Analysis.Common/Analysis/Standard/ClassicTokenizer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Standard/ClassicTokenizer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Standard/ClassicTokenizer.cs
index 888615a..fd775db 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Standard/ClassicTokenizer.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Standard/ClassicTokenizer.cs
@@ -196,10 +196,13 @@ namespace Lucene.Net.Analysis.Standard
             posIncrAtt.PositionIncrement = posIncrAtt.PositionIncrement + skippedPositions;
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            base.Dispose();
-            scanner.YyReset(m_input);
+            if (disposing)
+            {
+                base.Dispose();
+                scanner.YyReset(m_input);
+            }
         }
 
         public override void Reset()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Analysis.Common/Analysis/Standard/StandardTokenizer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Standard/StandardTokenizer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Standard/StandardTokenizer.cs
index c83e1e5..0c64290 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Standard/StandardTokenizer.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Standard/StandardTokenizer.cs
@@ -250,10 +250,13 @@ namespace Lucene.Net.Analysis.Standard
             posIncrAtt.PositionIncrement = posIncrAtt.PositionIncrement + skippedPositions;
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            base.Dispose();
-            scanner.YyReset(m_input);
+            if (disposing)
+            {
+                base.Dispose();
+                scanner.YyReset(m_input);
+            }
         }
 
         public override void Reset()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Analysis.Common/Analysis/Standard/UAX29URLEmailTokenizer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Standard/UAX29URLEmailTokenizer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Standard/UAX29URLEmailTokenizer.cs
index 32a042c..0ca2477 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Standard/UAX29URLEmailTokenizer.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Standard/UAX29URLEmailTokenizer.cs
@@ -216,10 +216,13 @@ namespace Lucene.Net.Analysis.Standard
             posIncrAtt.PositionIncrement = posIncrAtt.PositionIncrement + skippedPositions;
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            base.Dispose();
-            scanner.YyReset(m_input);
+            if (disposing)
+            {
+                base.Dispose();
+                scanner.YyReset(m_input);
+            }
         }
 
         public override void Reset()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Analysis.Common/Analysis/Wikipedia/WikipediaTokenizer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Wikipedia/WikipediaTokenizer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Wikipedia/WikipediaTokenizer.cs
index e6f1c71..9b8e35e 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Wikipedia/WikipediaTokenizer.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Wikipedia/WikipediaTokenizer.cs
@@ -314,10 +314,13 @@ namespace Lucene.Net.Analysis.Wikipedia
             offsetAtt.SetOffset(CorrectOffset(start), CorrectOffset(start + termAtt.Length));
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            base.Dispose();
-            scanner.YyReset(m_input);
+            if (disposing)
+            {
+                base.Dispose();
+                scanner.YyReset(m_input);
+            }
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Core/Analysis/TokenFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Analysis/TokenFilter.cs b/src/Lucene.Net.Core/Analysis/TokenFilter.cs
index 9a6c715..53044f1 100644
--- a/src/Lucene.Net.Core/Analysis/TokenFilter.cs
+++ b/src/Lucene.Net.Core/Analysis/TokenFilter.cs
@@ -67,15 +67,18 @@ namespace Lucene.Net.Analysis
         /// <para/>
         /// If you override this method, always call <c>base.Dispose()</c>, otherwise
         /// some internal state will not be correctly reset (e.g., <see cref="Tokenizer"/>
will
-        /// throw <see cref="InvalidOperationException"/> on reuse).
+        /// throw <see cref="System.InvalidOperationException"/> on reuse).
         /// <para/>
         /// <b>NOTE:</b>
         /// The default implementation chains the call to the input TokenStream, so
         /// be sure to call <c>base.Dispose()</c> when overriding this method.
         /// </summary>
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            m_input.Dispose();
+            if (disposing)
+            {
+                m_input.Dispose();
+            }
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Core/Analysis/TokenStream.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Analysis/TokenStream.cs b/src/Lucene.Net.Core/Analysis/TokenStream.cs
index f32092f..4bd469c 100644
--- a/src/Lucene.Net.Core/Analysis/TokenStream.cs
+++ b/src/Lucene.Net.Core/Analysis/TokenStream.cs
@@ -200,6 +200,13 @@ namespace Lucene.Net.Analysis
         {
         }
 
+        // LUCENENET specific - implementing proper dispose pattern
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
         /// <summary>
         /// Releases resources associated with this stream.
         /// <para/>
@@ -207,7 +214,7 @@ namespace Lucene.Net.Analysis
         /// some internal state will not be correctly reset (e.g., <see cref="Tokenizer"/>
will
         /// throw <see cref="InvalidOperationException"/> on reuse).
         /// </summary>
-        public virtual void Dispose()
+        protected virtual void Dispose(bool disposing)
         {
         }
     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Core/Analysis/Tokenizer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Analysis/Tokenizer.cs b/src/Lucene.Net.Core/Analysis/Tokenizer.cs
index 3176f01..03aecdd 100644
--- a/src/Lucene.Net.Core/Analysis/Tokenizer.cs
+++ b/src/Lucene.Net.Core/Analysis/Tokenizer.cs
@@ -76,13 +76,16 @@ namespace Lucene.Net.Analysis
         /// The default implementation closes the input <see cref="TextReader"/>, so
         /// be sure to call <c>base.Dispose()</c> when overriding this method.
         /// </remarks>
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            m_input.Dispose();
-            // LUCENE-2387: don't hold onto TextReader after close, so
-            // GC can reclaim
-            inputPending = ILLEGAL_STATE_READER;
-            m_input = ILLEGAL_STATE_READER;
+            if (disposing)
+            {
+                m_input.Dispose();
+                // LUCENE-2387: don't hold onto TextReader after close, so
+                // GC can reclaim
+                inputPending = ILLEGAL_STATE_READER;
+                m_input = ILLEGAL_STATE_READER;
+            }
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.TestFramework/Analysis/MockGraphTokenFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Analysis/MockGraphTokenFilter.cs b/src/Lucene.Net.TestFramework/Analysis/MockGraphTokenFilter.cs
index f9d40fa..129f4b5 100644
--- a/src/Lucene.Net.TestFramework/Analysis/MockGraphTokenFilter.cs
+++ b/src/Lucene.Net.TestFramework/Analysis/MockGraphTokenFilter.cs
@@ -113,10 +113,13 @@ namespace Lucene.Net.Analysis
             this.Random = new Random((int)Seed);
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            base.Dispose();
-            this.Random = null;
+            if (disposing)
+            {
+                base.Dispose();
+                this.Random = null;
+            }
         }
 
         public override bool IncrementToken()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs b/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs
index 2889557..64add2e 100644
--- a/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs
+++ b/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs
@@ -304,14 +304,17 @@ namespace Lucene.Net.Analysis
             StreamState = State.RESET;
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            base.Dispose();
-            // in some exceptional cases (e.g. TestIndexWriterExceptions) a test can prematurely
close()
-            // these tests should disable this check, by default we check the normal workflow.
-            // TODO: investigate the CachingTokenFilter "double-close"... for now we ignore
this
-            Assert.True(!EnableChecks_Renamed || StreamState == State.END || StreamState
== State.CLOSE, "close() called in wrong state: " + StreamState);
-            StreamState = State.CLOSE;
+            if (disposing)
+            {
+                base.Dispose();
+                // in some exceptional cases (e.g. TestIndexWriterExceptions) a test can
prematurely close()
+                // these tests should disable this check, by default we check the normal
workflow.
+                // TODO: investigate the CachingTokenFilter "double-close"... for now we
ignore this
+                Assert.True(!EnableChecks_Renamed || StreamState == State.END || StreamState
== State.CLOSE, "close() called in wrong state: " + StreamState);
+                StreamState = State.CLOSE;
+            }
         }
 
         internal override bool SetReaderTestPoint()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestBugInSomething.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestBugInSomething.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestBugInSomething.cs
index 10fb996..af81d15 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestBugInSomething.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Core/TestBugInSomething.cs
@@ -288,10 +288,13 @@ namespace Lucene.Net.Analysis.Core
                 Console.WriteLine(m_input.GetType().Name + ".end()");
             }
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
-                base.Dispose();
-                Console.WriteLine(m_input.GetType().Name + ".close()");
+                if (disposing)
+                {
+                    base.Dispose();
+                    Console.WriteLine(m_input.GetType().Name + ".close()");
+                }
             }
 
             public override void Reset()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Tests.Highlighter/Highlight/HighlighterTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Highlighter/Highlight/HighlighterTest.cs b/src/Lucene.Net.Tests.Highlighter/Highlight/HighlighterTest.cs
index 3bc972e..5432921 100644
--- a/src/Lucene.Net.Tests.Highlighter/Highlight/HighlighterTest.cs
+++ b/src/Lucene.Net.Tests.Highlighter/Highlight/HighlighterTest.cs
@@ -2166,10 +2166,13 @@ namespace Lucene.Net.Search.Highlight
         }
 
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            base.Dispose();
-            this.realStream.Dispose();
+            if (disposing)
+            {
+                base.Dispose();
+                this.realStream.Dispose();
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c8c94d13/src/Lucene.Net.Tests/Index/TestPayloads.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Index/TestPayloads.cs b/src/Lucene.Net.Tests/Index/TestPayloads.cs
index ba5038e..9ce5cff 100644
--- a/src/Lucene.Net.Tests/Index/TestPayloads.cs
+++ b/src/Lucene.Net.Tests/Index/TestPayloads.cs
@@ -591,9 +591,12 @@ namespace Lucene.Net.Index
                 return true;
             }
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
-                Pool.Release(Payload);
+                if (disposing)
+                {
+                    Pool.Release(Payload);
+                }
             }
         }
 


Mime
View raw message