lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [08/20] lucenenet git commit: Lucene.Net.Core.Codecs.FieldsConsumer: implemented .NET dispose pattern
Date Sun, 02 Apr 2017 07:06:08 GMT
Lucene.Net.Core.Codecs.FieldsConsumer: 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/6af91bd7
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/6af91bd7
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/6af91bd7

Branch: refs/heads/api-work
Commit: 6af91bd74efec0dc75768a74f457f898b592aa6a
Parents: 8105155
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Apr 2 10:25:52 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Apr 2 11:58:33 2017 +0700

----------------------------------------------------------------------
 .../BlockTerms/BlockTermsWriter.cs              | 53 +++++++-------
 .../Bloom/BloomFilteringPostingsFormat.cs       | 61 ++++++++--------
 .../Memory/FSTOrdTermsWriter.cs                 | 77 ++++++++++----------
 src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs  | 59 ++++++++-------
 .../Memory/MemoryPostingsFormat.cs              | 22 +++---
 .../SimpleText/SimpleTextFieldsWriter.cs        | 27 ++++---
 .../Codecs/BlockTreeTermsWriter.cs              | 65 +++++++++--------
 src/Lucene.Net.Core/Codecs/FieldsConsumer.cs    | 11 ++-
 .../Codecs/PerField/PerFieldPostingsFormat.cs   |  9 ++-
 .../Codecs/Asserting/AssertingPostingsFormat.cs |  9 +--
 .../Codecs/Lucene3x/PreFlexRWFieldsWriter.cs    |  7 +-
 .../Codecs/RAMOnly/RAMOnlyPostingsFormat.cs     |  2 +-
 12 files changed, 217 insertions(+), 185 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.Codecs/BlockTerms/BlockTermsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsWriter.cs b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsWriter.cs
index fdc9226..7c25d01 100644
--- a/src/Lucene.Net.Codecs/BlockTerms/BlockTermsWriter.cs
+++ b/src/Lucene.Net.Codecs/BlockTerms/BlockTermsWriter.cs
@@ -130,38 +130,41 @@ namespace Lucene.Net.Codecs.BlockTerms
             return new TermsWriter(this, fieldIndexWriter, field, postingsWriter);
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            if (m_output != null)
+            if (disposing)
             {
-                try
+                if (m_output != null)
                 {
-                    long dirStart = m_output.GetFilePointer();
-
-                    m_output.WriteVInt32(fields.Count);
-                    foreach (FieldMetaData field in fields)
+                    try
                     {
-                        m_output.WriteVInt32(field.FieldInfo.Number);
-                        m_output.WriteVInt64(field.NumTerms);
-                        m_output.WriteVInt64(field.TermsStartPointer);
-                        if (field.FieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
-                        {
-                            m_output.WriteVInt64(field.SumTotalTermFreq);
-                        }
-                        m_output.WriteVInt64(field.SumDocFreq);
-                        m_output.WriteVInt32(field.DocCount);
-                        if (VERSION_CURRENT >= VERSION_META_ARRAY)
+                        long dirStart = m_output.GetFilePointer();
+
+                        m_output.WriteVInt32(fields.Count);
+                        foreach (FieldMetaData field in fields)
                         {
-                            m_output.WriteVInt32(field.Int64sSize);
+                            m_output.WriteVInt32(field.FieldInfo.Number);
+                            m_output.WriteVInt64(field.NumTerms);
+                            m_output.WriteVInt64(field.TermsStartPointer);
+                            if (field.FieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
+                            {
+                                m_output.WriteVInt64(field.SumTotalTermFreq);
+                            }
+                            m_output.WriteVInt64(field.SumDocFreq);
+                            m_output.WriteVInt32(field.DocCount);
+                            if (VERSION_CURRENT >= VERSION_META_ARRAY)
+                            {
+                                m_output.WriteVInt32(field.Int64sSize);
+                            }
                         }
+                        WriteTrailer(dirStart);
+                        CodecUtil.WriteFooter(m_output);
+                    }
+                    finally
+                    {
+                        IOUtils.Close(m_output, postingsWriter, termsIndexWriter);
+                        m_output = null;
                     }
-                    WriteTrailer(dirStart);
-                    CodecUtil.WriteFooter(m_output);
-                }
-                finally
-                {
-                    IOUtils.Close(m_output, postingsWriter, termsIndexWriter);
-                    m_output = null;
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs b/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
index 2f9b2c4..8ab4952 100644
--- a/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Bloom/BloomFilteringPostingsFormat.cs
@@ -449,41 +449,44 @@ namespace Lucene.Net.Codecs.Bloom
                 return _delegateFieldsConsumer.AddField(field);
             }
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
-                _delegateFieldsConsumer.Dispose();
-                // Now we are done accumulating values for these fields
-                var nonSaturatedBlooms = (from entry in _bloomFilters.EntrySet() let bloomFilter
= entry.Value where !outerInstance._bloomFilterFactory.IsSaturated(bloomFilter, entry.Key)
select entry).ToList();
-
-                var bloomFileName = IndexFileNames.SegmentFileName(
-                    _state.SegmentInfo.Name, _state.SegmentSuffix, BLOOM_EXTENSION);
-                IndexOutput bloomOutput = null;
-
-                try
+                if (disposing)
                 {
-                    bloomOutput = _state.Directory.CreateOutput(bloomFileName, _state.Context);
-                    CodecUtil.WriteHeader(bloomOutput, /*BLOOM_CODEC_NAME*/ outerInstance.Name,
VERSION_CURRENT);
-                    // remember the name of the postings format we will delegate to
-                    bloomOutput.WriteString(outerInstance._delegatePostingsFormat.Name);
+                    _delegateFieldsConsumer.Dispose();
+                    // Now we are done accumulating values for these fields
+                    var nonSaturatedBlooms = (from entry in _bloomFilters.EntrySet() let
bloomFilter = entry.Value where !outerInstance._bloomFilterFactory.IsSaturated(bloomFilter,
entry.Key) select entry).ToList();
+
+                    var bloomFileName = IndexFileNames.SegmentFileName(
+                        _state.SegmentInfo.Name, _state.SegmentSuffix, BLOOM_EXTENSION);
+                    IndexOutput bloomOutput = null;
 
-                    // First field in the output file is the number of fields+blooms saved
-                    bloomOutput.WriteInt32(nonSaturatedBlooms.Count);
-                    foreach (var entry in nonSaturatedBlooms)
+                    try
                     {
-                        var fieldInfo = entry.Key;
-                        var bloomFilter = entry.Value;
-                        bloomOutput.WriteInt32(fieldInfo.Number);
-                        SaveAppropriatelySizedBloomFilter(bloomOutput, bloomFilter, fieldInfo);
+                        bloomOutput = _state.Directory.CreateOutput(bloomFileName, _state.Context);
+                        CodecUtil.WriteHeader(bloomOutput, /*BLOOM_CODEC_NAME*/ outerInstance.Name,
VERSION_CURRENT);
+                        // remember the name of the postings format we will delegate to
+                        bloomOutput.WriteString(outerInstance._delegatePostingsFormat.Name);
+
+                        // First field in the output file is the number of fields+blooms
saved
+                        bloomOutput.WriteInt32(nonSaturatedBlooms.Count);
+                        foreach (var entry in nonSaturatedBlooms)
+                        {
+                            var fieldInfo = entry.Key;
+                            var bloomFilter = entry.Value;
+                            bloomOutput.WriteInt32(fieldInfo.Number);
+                            SaveAppropriatelySizedBloomFilter(bloomOutput, bloomFilter, fieldInfo);
+                        }
+
+                        CodecUtil.WriteFooter(bloomOutput);
                     }
-
-                    CodecUtil.WriteFooter(bloomOutput);
-                }
-                finally
-                {
-                    IOUtils.Close(bloomOutput);
+                    finally
+                    {
+                        IOUtils.Close(bloomOutput);
+                    }
+                    //We are done with large bitsets so no need to keep them hanging around
+                    _bloomFilters.Clear();
                 }
-                //We are done with large bitsets so no need to keep them hanging around
-                _bloomFilters.Clear();
             }
 
             private void SaveAppropriatelySizedBloomFilter(DataOutput bloomOutput,

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs
index 839929e..ecd90db 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTOrdTermsWriter.cs
@@ -185,50 +185,53 @@ namespace Lucene.Net.Codecs.Memory
             return new TermsWriter(this, field);
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            if (blockOut == null) return;
-
-            IOException ioe = null;
-            try
+            if (disposing)
             {
-                var blockDirStart = blockOut.GetFilePointer();
+                if (blockOut == null) return;
 
-                // write field summary
-                blockOut.WriteVInt32(_fields.Count);
-                foreach (var field in _fields)
+                IOException ioe = null;
+                try
                 {
-                    blockOut.WriteVInt32(field.FieldInfo.Number);
-                    blockOut.WriteVInt64(field.NumTerms);
-                    if (field.FieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
+                    var blockDirStart = blockOut.GetFilePointer();
+
+                    // write field summary
+                    blockOut.WriteVInt32(_fields.Count);
+                    foreach (var field in _fields)
                     {
-                        blockOut.WriteVInt64(field.SumTotalTermFreq);
+                        blockOut.WriteVInt32(field.FieldInfo.Number);
+                        blockOut.WriteVInt64(field.NumTerms);
+                        if (field.FieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
+                        {
+                            blockOut.WriteVInt64(field.SumTotalTermFreq);
+                        }
+                        blockOut.WriteVInt64(field.SumDocFreq);
+                        blockOut.WriteVInt32(field.DocCount);
+                        blockOut.WriteVInt32(field.Int64sSize);
+                        blockOut.WriteVInt64(field.StatsOut.GetFilePointer());
+                        blockOut.WriteVInt64(field.MetaInt64sOut.GetFilePointer());
+                        blockOut.WriteVInt64(field.MetaBytesOut.GetFilePointer());
+
+                        field.SkipOut.WriteTo(blockOut);
+                        field.StatsOut.WriteTo(blockOut);
+                        field.MetaInt64sOut.WriteTo(blockOut);
+                        field.MetaBytesOut.WriteTo(blockOut);
+                        field.Dict.Save(indexOut);
                     }
-                    blockOut.WriteVInt64(field.SumDocFreq);
-                    blockOut.WriteVInt32(field.DocCount);
-                    blockOut.WriteVInt32(field.Int64sSize);
-                    blockOut.WriteVInt64(field.StatsOut.GetFilePointer());
-                    blockOut.WriteVInt64(field.MetaInt64sOut.GetFilePointer());
-                    blockOut.WriteVInt64(field.MetaBytesOut.GetFilePointer());
-
-                    field.SkipOut.WriteTo(blockOut);
-                    field.StatsOut.WriteTo(blockOut);
-                    field.MetaInt64sOut.WriteTo(blockOut);
-                    field.MetaBytesOut.WriteTo(blockOut);
-                    field.Dict.Save(indexOut);
+                    WriteTrailer(blockOut, blockDirStart);
+                    CodecUtil.WriteFooter(indexOut);
+                    CodecUtil.WriteFooter(blockOut);
+                }
+                catch (IOException ioe2)
+                {
+                    ioe = ioe2;
+                }
+                finally
+                {
+                    IOUtils.CloseWhileHandlingException(ioe, blockOut, indexOut, postingsWriter);
+                    blockOut = null;
                 }
-                WriteTrailer(blockOut, blockDirStart);
-                CodecUtil.WriteFooter(indexOut);
-                CodecUtil.WriteFooter(blockOut);
-            }
-            catch (IOException ioe2)
-            {
-                ioe = ioe2;
-            }
-            finally
-            {
-                IOUtils.CloseWhileHandlingException(ioe, blockOut, indexOut, postingsWriter);
-                blockOut = null;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs b/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs
index 3f18e36..2f2b7d6 100644
--- a/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs
+++ b/src/Lucene.Net.Codecs/Memory/FSTTermsWriter.cs
@@ -164,41 +164,44 @@ namespace Lucene.Net.Codecs.Memory
             return new TermsWriter(this, field);
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            if (_output == null) return;
-
-            IOException ioe = null;
-            try
+            if (disposing)
             {
-                // write field summary
-                var dirStart = _output.GetFilePointer();
+                if (_output == null) return;
 
-                _output.WriteVInt32(_fields.Count);
-                foreach (var field in _fields)
+                IOException ioe = null;
+                try
                 {
-                    _output.WriteVInt32(field.FieldInfo.Number);
-                    _output.WriteVInt64(field.NumTerms);
-                    if (field.FieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
+                    // write field summary
+                    var dirStart = _output.GetFilePointer();
+
+                    _output.WriteVInt32(_fields.Count);
+                    foreach (var field in _fields)
                     {
-                        _output.WriteVInt64(field.SumTotalTermFreq);
+                        _output.WriteVInt32(field.FieldInfo.Number);
+                        _output.WriteVInt64(field.NumTerms);
+                        if (field.FieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
+                        {
+                            _output.WriteVInt64(field.SumTotalTermFreq);
+                        }
+                        _output.WriteVInt64(field.SumDocFreq);
+                        _output.WriteVInt32(field.DocCount);
+                        _output.WriteVInt32(field.Int64sSize);
+                        field.Dict.Save(_output);
                     }
-                    _output.WriteVInt64(field.SumDocFreq);
-                    _output.WriteVInt32(field.DocCount);
-                    _output.WriteVInt32(field.Int64sSize);
-                    field.Dict.Save(_output);
+                    WriteTrailer(_output, dirStart);
+                    CodecUtil.WriteFooter(_output);
+                }
+                catch (IOException ioe2)
+                {
+                    ioe = ioe2;
+                }
+                finally
+                {
+                    IOUtils.CloseWhileHandlingException(ioe, _output, _postingsWriter);
+                    _output = null;
                 }
-                WriteTrailer(_output, dirStart);
-                CodecUtil.WriteFooter(_output);
-            }
-            catch (IOException ioe2)
-            {
-                ioe = ioe2;
-            }
-            finally
-            {
-                IOUtils.CloseWhileHandlingException(ioe, _output, _postingsWriter);
-                _output = null;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs b/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
index d617030..9336c7b 100644
--- a/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/Memory/MemoryPostingsFormat.cs
@@ -359,20 +359,22 @@ namespace Lucene.Net.Codecs.Memory
                 return new TermsWriter(@out, field, outerInstance.doPackFST, outerInstance.acceptableOverheadRatio);
             }
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
-                // EOF marker:
-                try
-                {
-                    @out.WriteVInt32(0);
-                    CodecUtil.WriteFooter(@out);
-                }
-                finally
+                if (disposing)
                 {
-                    @out.Dispose();
+                    // EOF marker:
+                    try
+                    {
+                        @out.WriteVInt32(0);
+                        CodecUtil.WriteFooter(@out);
+                    }
+                    finally
+                    {
+                        @out.Dispose();
+                    }
                 }
             }
-
         }
 
         private sealed class FSTDocsEnum : DocsEnum

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
index e82e3a4..66a6027 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
@@ -192,20 +192,23 @@ namespace Lucene.Net.Codecs.SimpleText
         }
 
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            if (_output == null) return;
-
-            try
-            {
-                Write(END);
-                Newline();
-                SimpleTextUtil.WriteChecksum(_output, _scratch);
-            }
-            finally
+            if (disposing)
             {
-                _output.Dispose();
-                _output = null;
+                if (_output == null) return;
+
+                try
+                {
+                    Write(END);
+                    Newline();
+                    SimpleTextUtil.WriteChecksum(_output, _scratch);
+                }
+                finally
+                {
+                    _output.Dispose();
+                    _output = null;
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.Core/Codecs/BlockTreeTermsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/BlockTreeTermsWriter.cs b/src/Lucene.Net.Core/Codecs/BlockTreeTermsWriter.cs
index ea0a46a..d026e76 100644
--- a/src/Lucene.Net.Core/Codecs/BlockTreeTermsWriter.cs
+++ b/src/Lucene.Net.Core/Codecs/BlockTreeTermsWriter.cs
@@ -1197,44 +1197,47 @@ namespace Lucene.Net.Codecs
             internal readonly RAMOutputStream bytesWriter = new RAMOutputStream();
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            System.IO.IOException ioe = null;
-            try
+            if (disposing)
             {
-                long dirStart = @out.GetFilePointer();
-                long indexDirStart = indexOut.GetFilePointer();
+                System.IO.IOException ioe = null;
+                try
+                {
+                    long dirStart = @out.GetFilePointer();
+                    long indexDirStart = indexOut.GetFilePointer();
 
-                @out.WriteVInt32(fields.Count);
+                    @out.WriteVInt32(fields.Count);
 
-                foreach (FieldMetaData field in fields)
-                {
-                    //System.out.println("  field " + field.fieldInfo.name + " " + field.numTerms
+ " terms");
-                    @out.WriteVInt32(field.FieldInfo.Number);
-                    @out.WriteVInt64(field.NumTerms);
-                    @out.WriteVInt32(field.RootCode.Length);
-                    @out.WriteBytes(field.RootCode.Bytes, field.RootCode.Offset, field.RootCode.Length);
-                    if (field.FieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
+                    foreach (FieldMetaData field in fields)
                     {
-                        @out.WriteVInt64(field.SumTotalTermFreq);
+                        //System.out.println("  field " + field.fieldInfo.name + " " + field.numTerms
+ " terms");
+                        @out.WriteVInt32(field.FieldInfo.Number);
+                        @out.WriteVInt64(field.NumTerms);
+                        @out.WriteVInt32(field.RootCode.Length);
+                        @out.WriteBytes(field.RootCode.Bytes, field.RootCode.Offset, field.RootCode.Length);
+                        if (field.FieldInfo.IndexOptions != IndexOptions.DOCS_ONLY)
+                        {
+                            @out.WriteVInt64(field.SumTotalTermFreq);
+                        }
+                        @out.WriteVInt64(field.SumDocFreq);
+                        @out.WriteVInt32(field.DocCount);
+                        @out.WriteVInt32(field.Int64sSize);
+                        indexOut.WriteVInt64(field.IndexStartFP);
                     }
-                    @out.WriteVInt64(field.SumDocFreq);
-                    @out.WriteVInt32(field.DocCount);
-                    @out.WriteVInt32(field.Int64sSize);
-                    indexOut.WriteVInt64(field.IndexStartFP);
+                    WriteTrailer(@out, dirStart);
+                    CodecUtil.WriteFooter(@out);
+                    WriteIndexTrailer(indexOut, indexDirStart);
+                    CodecUtil.WriteFooter(indexOut);
+                }
+                catch (System.IO.IOException ioe2)
+                {
+                    ioe = ioe2;
+                }
+                finally
+                {
+                    IOUtils.CloseWhileHandlingException(ioe, @out, indexOut, postingsWriter);
                 }
-                WriteTrailer(@out, dirStart);
-                CodecUtil.WriteFooter(@out);
-                WriteIndexTrailer(indexOut, indexDirStart);
-                CodecUtil.WriteFooter(indexOut);
-            }
-            catch (System.IO.IOException ioe2)
-            {
-                ioe = ioe2;
-            }
-            finally
-            {
-                IOUtils.CloseWhileHandlingException(ioe, @out, indexOut, postingsWriter);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.Core/Codecs/FieldsConsumer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/FieldsConsumer.cs b/src/Lucene.Net.Core/Codecs/FieldsConsumer.cs
index d338fce..ee6d7cd 100644
--- a/src/Lucene.Net.Core/Codecs/FieldsConsumer.cs
+++ b/src/Lucene.Net.Core/Codecs/FieldsConsumer.cs
@@ -60,7 +60,16 @@ namespace Lucene.Net.Codecs
 
         /// <summary>
         /// Called when we are done adding everything. </summary>
-        public abstract void Dispose();
+        // LUCENENET specific - implementing proper dispose pattern
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        /// <summary>
+        /// Called when we are done adding everything. </summary>
+        protected abstract void Dispose(bool disposing);
 
         /// <summary>
         /// Called during merging to merge all <seealso cref="Fields"/> from

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.Core/Codecs/PerField/PerFieldPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/PerField/PerFieldPostingsFormat.cs b/src/Lucene.Net.Core/Codecs/PerField/PerFieldPostingsFormat.cs
index e45056f..c214df8 100644
--- a/src/Lucene.Net.Core/Codecs/PerField/PerFieldPostingsFormat.cs
+++ b/src/Lucene.Net.Core/Codecs/PerField/PerFieldPostingsFormat.cs
@@ -157,10 +157,13 @@ namespace Lucene.Net.Codecs.PerField
                 return consumer.Consumer.AddField(field);
             }
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
-                // Close all subs
-                IOUtils.Close(formats.Values);
+                if (disposing)
+                {
+                    // Close all subs
+                    IOUtils.Close(formats.Values);
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs b/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs
index d2b0a8c..fd3c9f7 100644
--- a/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/Asserting/AssertingPostingsFormat.cs
@@ -126,15 +126,12 @@ namespace Lucene.Net.Codecs.Asserting
                 return new AssertingTermsConsumer(consumer, field);
             }
 
-            public override void Dispose()
-            {
-                Dispose(true);
-            }
-
-            protected void Dispose(bool disposing)
+            protected override void Dispose(bool disposing)
             {
                 if (disposing)
+                {
                     @in.Dispose();
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWFieldsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWFieldsWriter.cs b/src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWFieldsWriter.cs
index 053933a..ff80ffb 100644
--- a/src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWFieldsWriter.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/Lucene3x/PreFlexRWFieldsWriter.cs
@@ -96,9 +96,12 @@ namespace Lucene.Net.Codecs.Lucene3x
             return new PreFlexTermsWriter(this, field);
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            IOUtils.Close(TermsOut, FreqOut, ProxOut);
+            if (disposing)
+            {
+                IOUtils.Close(TermsOut, FreqOut, ProxOut);
+            }
         }
 
         private class PreFlexTermsWriter : TermsConsumer

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6af91bd7/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs b/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
index fbf5a25..9a8f03d 100644
--- a/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
+++ b/src/Lucene.Net.TestFramework/Codecs/RAMOnly/RAMOnlyPostingsFormat.cs
@@ -317,7 +317,7 @@ namespace Lucene.Net.Codecs.RAMOnly
                 return TermsConsumer;
             }
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
                 // TODO: finalize stuff
             }


Mime
View raw message