lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [10/20] lucenenet git commit: Lucene.Net.Replicator: Fixed member accessibility
Date Fri, 18 Aug 2017 08:04:57 GMT
Lucene.Net.Replicator: Fixed member accessibility


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

Branch: refs/heads/replicator
Commit: 73f6a4e2891a42371125fe40e7bb6c9b18176456
Parents: 6788246
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Thu Aug 17 02:42:27 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Thu Aug 17 02:42:27 2017 +0700

----------------------------------------------------------------------
 .../Http/HttpClientBase.cs                      | 28 +++++-----
 .../Http/HttpReplicator.cs                      | 12 ++---
 .../Http/ReplicationService.cs                  | 10 ++--
 .../IndexAndTaxonomyReplicationHandler.cs       | 55 +++++++++++---------
 .../IndexAndTaxonomyRevision.cs                 | 52 ++++++++++--------
 .../IndexInputInputStream.cs                    |  4 +-
 .../IndexReplicationHandler.cs                  | 35 +++++++------
 src/Lucene.Net.Replicator/IndexRevision.cs      | 26 ++++-----
 src/Lucene.Net.Replicator/LocalReplicator.cs    | 30 ++++++-----
 .../PerSessionDirectoryFactory.cs               |  6 +--
 src/Lucene.Net.Replicator/ReplicationClient.cs  | 22 ++++----
 src/Lucene.Net.Replicator/RevisionFile.cs       |  2 +-
 12 files changed, 151 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/Http/HttpClientBase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/HttpClientBase.cs b/src/Lucene.Net.Replicator/Http/HttpClientBase.cs
index 8f46b98..361d0b9 100644
--- a/src/Lucene.Net.Replicator/Http/HttpClientBase.cs
+++ b/src/Lucene.Net.Replicator/Http/HttpClientBase.cs
@@ -1,12 +1,12 @@
-using System;
+using Lucene.Net.Support;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
 using System.IO;
 using System.Linq;
 using System.Net;
 using System.Net.Http;
 using System.Text;
-using Lucene.Net.Support;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
 
 namespace Lucene.Net.Replicator.Http
 {
@@ -48,8 +48,8 @@ namespace Lucene.Net.Replicator.Http
         /// </summary>
         protected string Url { get; private set; }
 
-        private readonly HttpClient httpc;
         private volatile bool isDisposed = false;
+        private readonly HttpClient httpc;
 
         /// <summary>
         /// Creates a new <see cref="HttpClientBase"/> with the given host, port and
path.
@@ -106,7 +106,7 @@ namespace Lucene.Net.Replicator.Http
         /// Gets or Sets the connection timeout for this client, in milliseconds. This setting
         /// is used to modify <see cref="HttpClient.Timeout"/>.
         /// </summary>
-        public int ConnectionTimeout
+        public virtual int ConnectionTimeout
         {
             get { return (int)httpc.Timeout.TotalMilliseconds; }
             set { httpc.Timeout = TimeSpan.FromMilliseconds(value); }
@@ -139,7 +139,7 @@ namespace Lucene.Net.Replicator.Http
         /// </summary>
         /// <exception cref="IOException">IO Error happened at the server, check inner
exception for details.</exception>
         /// <exception cref="HttpRequestException">Unknown error received from the
server.</exception>
-        protected void VerifyStatus(HttpResponseMessage response)
+        protected virtual void VerifyStatus(HttpResponseMessage response)
         {
             if (!response.IsSuccessStatusCode)
             {
@@ -152,7 +152,7 @@ namespace Lucene.Net.Replicator.Http
         /// </summary>
         /// <exception cref="IOException">IO Error happened at the server, check inner
exception for details.</exception>
         /// <exception cref="HttpRequestException">Unknown error received from the
server.</exception>
-        protected void ThrowKnownError(HttpResponseMessage response)
+        protected virtual void ThrowKnownError(HttpResponseMessage response)
         {
             Stream input;
             try
@@ -199,7 +199,7 @@ namespace Lucene.Net.Replicator.Http
         /// <b>Internal:</b> Execute a request and return its result.
         /// The <paramref name="parameters"/> argument is treated as: name1,value1,name2,value2,...
         /// </summary>
-        protected HttpResponseMessage ExecutePost(string request, object entity, params string[]
parameters)
+        protected virtual HttpResponseMessage ExecutePost(string request, object entity,
params string[] parameters)
         {
             EnsureOpen();
             //.NET Note: No headers? No ContentType?... Bad use of Http?
@@ -219,7 +219,7 @@ namespace Lucene.Net.Replicator.Http
         /// <b>Internal:</b> Execute a request and return its result.
         /// The <paramref name="parameters"/> argument is treated as: name1,value1,name2,value2,...
         /// </summary>
-        protected HttpResponseMessage ExecuteGet(string request, params string[] parameters)
+        protected virtual HttpResponseMessage ExecuteGet(string request, params string[]
parameters)
         {
             EnsureOpen();
             //Note: No headers? No ContentType?... Bad use of Http?
@@ -243,7 +243,7 @@ namespace Lucene.Net.Replicator.Http
         /// Internal utility: input stream of the provided response.
         /// </summary>
         /// <exception cref="IOException"></exception>
-        public Stream ResponseInputStream(HttpResponseMessage response)
+        public virtual Stream ResponseInputStream(HttpResponseMessage response)
         {
             return ResponseInputStream(response, false);
         }
@@ -254,7 +254,7 @@ namespace Lucene.Net.Replicator.Http
         /// consumes the response's resources when the input stream is exhausted.
         /// </summary>
         /// <exception cref="IOException"></exception>
-        public Stream ResponseInputStream(HttpResponseMessage response, bool consume)
+        public virtual Stream ResponseInputStream(HttpResponseMessage response, bool consume)
         {
             return response.Content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult();
         }
@@ -269,7 +269,7 @@ namespace Lucene.Net.Replicator.Http
         /// <summary>
         /// Calls the overload <see cref="DoAction{T}(HttpResponseMessage, bool, Func{T})"/>
passing <c>true</c> to consume.
         /// </summary>
-        protected T DoAction<T>(HttpResponseMessage response, Func<T> call)
+        protected virtual T DoAction<T>(HttpResponseMessage response, Func<T>
call)
         {
             return DoAction(response, true, call);
         }
@@ -279,7 +279,7 @@ namespace Lucene.Net.Replicator.Http
         /// and if not, attempt to extract the actual server side exception. Optionally
         /// release the response at exit, depending on <paramref name="consume"/> parameter.
         /// </summary>
-        protected T DoAction<T>(HttpResponseMessage response, bool consume, Func<T>
call)
+        protected virtual T DoAction<T>(HttpResponseMessage response, bool consume,
Func<T> call)
         {
             Exception error = new NotImplementedException();
             try

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/Http/HttpReplicator.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/HttpReplicator.cs b/src/Lucene.Net.Replicator/Http/HttpReplicator.cs
index 052450a..860ef54 100644
--- a/src/Lucene.Net.Replicator/Http/HttpReplicator.cs
+++ b/src/Lucene.Net.Replicator/Http/HttpReplicator.cs
@@ -1,7 +1,7 @@
-using System;
+using Lucene.Net.Support.IO;
+using System;
 using System.IO;
 using System.Net.Http;
-using Lucene.Net.Support.IO;
 
 namespace Lucene.Net.Replicator.Http
 {
@@ -62,7 +62,7 @@ namespace Lucene.Net.Replicator.Http
         /// <summary>
         /// Checks for updates at the remote host.
         /// </summary>
-        public SessionToken CheckForUpdate(string currentVersion)
+        public virtual SessionToken CheckForUpdate(string currentVersion)
         {
             string[] parameters = null;
             if (currentVersion != null)
@@ -81,7 +81,7 @@ namespace Lucene.Net.Replicator.Http
         /// <summary>
         /// Obtains the given file from it's source at the remote host.
         /// </summary>
-        public Stream ObtainFile(string sessionId, string source, string fileName)
+        public virtual Stream ObtainFile(string sessionId, string source, string fileName)
         {
             HttpResponseMessage response = ExecuteGet(ReplicationService.ReplicationAction.OBTAIN.ToString(),
                 ReplicationService.REPLICATE_SESSION_ID_PARAM, sessionId,
@@ -94,7 +94,7 @@ namespace Lucene.Net.Replicator.Http
         /// Not supported.
         /// </summary>
         /// <exception cref="NotSupportedException">this replicator implementation
does not support remote publishing of revisions</exception>
-        public void Publish(IRevision revision)
+        public virtual void Publish(IRevision revision)
         {
             throw new NotSupportedException("this replicator implementation does not support
remote publishing of revisions");
         }
@@ -102,7 +102,7 @@ namespace Lucene.Net.Replicator.Http
         /// <summary>
         /// Releases a session obtained from the remote host.
         /// </summary>
-        public void Release(string sessionId)
+        public virtual void Release(string sessionId)
         {
             HttpResponseMessage response = ExecuteGet(ReplicationService.ReplicationAction.RELEASE.ToString(),
ReplicationService.REPLICATE_SESSION_ID_PARAM, sessionId);
             // do not remove this call: as it is still validating for us!

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/Http/ReplicationService.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/ReplicationService.cs b/src/Lucene.Net.Replicator/Http/ReplicationService.cs
index 95c8b50..9290683 100644
--- a/src/Lucene.Net.Replicator/Http/ReplicationService.cs
+++ b/src/Lucene.Net.Replicator/Http/ReplicationService.cs
@@ -1,9 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using Lucene.Net.Replicator.Http.Abstractions;
+using Lucene.Net.Replicator.Http.Abstractions;
 using Lucene.Net.Support.IO;
 using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.IO;
 
 namespace Lucene.Net.Replicator.Http
 {
@@ -130,7 +130,7 @@ namespace Lucene.Net.Replicator.Http
         /// Executes the replication task.
         /// </summary>
         /// <exception cref="InvalidOperationException">required parameters are missing</exception>
-        public void Perform(IReplicationRequest request, IReplicationResponse response)
+        public virtual void Perform(IReplicationRequest request, IReplicationResponse response)
         {
             string[] pathElements = GetPathElements(request);
             if (pathElements.Length != 2)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs b/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs
index d6a3ce0..80d6432 100644
--- a/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs
+++ b/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs
@@ -1,10 +1,10 @@
-using System;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
+using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
-using Lucene.Net.Index;
-using Lucene.Net.Store;
-using Lucene.Net.Util;
 using Directory = Lucene.Net.Store.Directory;
 
 namespace Lucene.Net.Replicator
@@ -53,19 +53,9 @@ namespace Lucene.Net.Replicator
         private readonly Directory taxonomyDirectory;
         private readonly Func<bool?> callback;
 
-        private InfoStream infoStream = InfoStream.Default;
-
-        public string CurrentVersion { get; private set; }
-        public IDictionary<string, IList<RevisionFile>> CurrentRevisionFiles
{ get; private set; }
-
-        /// <summary>
-        /// Gets or sets the <see cref="Util.InfoStream"/> to use for logging messages.
-        /// </summary>
-        public InfoStream InfoStream
-        {
-            get { return infoStream; }
-            set { infoStream = value ?? InfoStream.NO_OUTPUT; }
-        }
+        private volatile IDictionary<string, IList<RevisionFile>> currentRevisionFiles;
+        private volatile string currentVersion;
+        private volatile InfoStream infoStream = InfoStream.Default;
 
         /// <summary>
         /// Constructor with the given index directory and callback to notify when the indexes
were updated.
@@ -77,8 +67,8 @@ namespace Lucene.Net.Replicator
             this.taxonomyDirectory = taxonomyDirectory;
             this.callback = callback;
 
-            CurrentVersion = null;
-            CurrentRevisionFiles = null;
+            currentVersion = null;
+            currentRevisionFiles = null;
 
             bool indexExists = DirectoryReader.IndexExists(indexDirectory);
             bool taxonomyExists = DirectoryReader.IndexExists(taxonomyDirectory);
@@ -91,16 +81,19 @@ namespace Lucene.Net.Replicator
                 IndexCommit indexCommit = IndexReplicationHandler.GetLastCommit(indexDirectory);
                 IndexCommit taxonomyCommit = IndexReplicationHandler.GetLastCommit(taxonomyDirectory);
 
-                CurrentRevisionFiles = IndexAndTaxonomyRevision.RevisionFiles(indexCommit,
taxonomyCommit);
-                CurrentVersion = IndexAndTaxonomyRevision.RevisionVersion(indexCommit, taxonomyCommit);
+                currentRevisionFiles = IndexAndTaxonomyRevision.RevisionFiles(indexCommit,
taxonomyCommit);
+                currentVersion = IndexAndTaxonomyRevision.RevisionVersion(indexCommit, taxonomyCommit);
 
                 WriteToInfoStream(
-                    string.Format("constructor(): currentVersion={0} currentRevisionFiles={1}",
CurrentVersion, CurrentRevisionFiles),
+                    string.Format("constructor(): currentVersion={0} currentRevisionFiles={1}",
currentVersion, currentRevisionFiles),
                     string.Format("constructor(): indexCommit={0} taxoCommit={1}", indexCommit,
taxonomyCommit));
             }
         }
 
-        public void RevisionReady(string version,
+        public virtual string CurrentVersion { get { return currentVersion; } }
+        public virtual IDictionary<string, IList<RevisionFile>> CurrentRevisionFiles
{ get { return currentRevisionFiles; } }
+
+        public virtual void RevisionReady(string version,
             IDictionary<string, IList<RevisionFile>> revisionFiles,
             IDictionary<string, IList<string>> copiedFiles,
             IDictionary<string, Directory> sourceDirectory)
@@ -148,10 +141,10 @@ namespace Lucene.Net.Replicator
             }
 
             // all files have been successfully copied + sync'd. update the handler's state
-            CurrentRevisionFiles = revisionFiles;
-            CurrentVersion = version;
+            currentRevisionFiles = revisionFiles;
+            currentVersion = version;
             
-            WriteToInfoStream("revisionReady(): currentVersion=" + CurrentVersion + " currentRevisionFiles="
+ CurrentRevisionFiles);
+            WriteToInfoStream("revisionReady(): currentVersion=" + currentVersion + " currentRevisionFiles="
+ currentRevisionFiles);
             
             // update the segments.gen file
             IndexReplicationHandler.WriteSegmentsGen(taxonomySegmentsFile, taxonomyDirectory);
@@ -176,6 +169,7 @@ namespace Lucene.Net.Replicator
             } 
         }
 
+        // LUCENENET specific utility method
         private void WriteToInfoStream(params string[] messages)
         {
             if (!InfoStream.IsEnabled(INFO_STREAM_COMPONENT))
@@ -184,5 +178,14 @@ namespace Lucene.Net.Replicator
             foreach (string message in messages)
                 InfoStream.Message(INFO_STREAM_COMPONENT, message);
         }
+
+        /// <summary>
+        /// Gets or sets the <see cref="Util.InfoStream"/> to use for logging messages.
+        /// </summary>
+        public virtual InfoStream InfoStream
+        {
+            get { return infoStream; }
+            set { infoStream = value ?? InfoStream.NO_OUTPUT; }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs b/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
index 63040b0..e501a58 100644
--- a/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
+++ b/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
@@ -1,13 +1,13 @@
-using System;
+using Lucene.Net.Facet.Taxonomy.Directory;
+using Lucene.Net.Facet.Taxonomy.WriterCache;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Globalization;
 using System.IO;
 using System.Linq;
-using Lucene.Net.Facet.Taxonomy.Directory;
-using Lucene.Net.Facet.Taxonomy.WriterCache;
-using Lucene.Net.Index;
-using Lucene.Net.Store;
 using Directory = Lucene.Net.Store.Directory;
 
 namespace Lucene.Net.Replicator
@@ -48,14 +48,8 @@ namespace Lucene.Net.Replicator
         /// </summary>
         public class SnapshotDirectoryTaxonomyWriter : DirectoryTaxonomyWriter
         {
-            /// <summary>
-            /// Gets the <see cref="SnapshotDeletionPolicy"/> used by the underlying
<see cref="Index.IndexWriter"/>.
-            /// </summary>
-            public SnapshotDeletionPolicy DeletionPolicy { get; private set; }
-            /// <summary>
-            /// Gets the <see cref="Index.IndexWriter"/> used by this <see cref="DirectoryTaxonomyWriter"/>.
-            /// </summary>
-            public IndexWriter IndexWriter { get; private set; }
+            private SnapshotDeletionPolicy sdp;
+            private IndexWriter writer;
 
             /// <summary>
             /// <see cref="DirectoryTaxonomyWriter(Directory, OpenMode, ITaxonomyWriterCache)"/>
@@ -78,14 +72,24 @@ namespace Lucene.Net.Replicator
             protected override IndexWriterConfig CreateIndexWriterConfig(OpenMode openMode)
             {
                 IndexWriterConfig conf = base.CreateIndexWriterConfig(openMode);
-                conf.IndexDeletionPolicy = DeletionPolicy = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
+                conf.IndexDeletionPolicy = sdp = new SnapshotDeletionPolicy(conf.IndexDeletionPolicy);
                 return conf;
             }
 
             protected override IndexWriter OpenIndexWriter(Directory directory, IndexWriterConfig
config)
             {
-                return IndexWriter = base.OpenIndexWriter(directory, config);
+                return writer = base.OpenIndexWriter(directory, config);
             }
+
+            /// <summary>
+            /// Gets the <see cref="SnapshotDeletionPolicy"/> used by the underlying
<see cref="Index.IndexWriter"/>.
+            /// </summary>
+            public virtual SnapshotDeletionPolicy DeletionPolicy { get { return sdp; } }
+
+            /// <summary>
+            /// Gets the <see cref="Index.IndexWriter"/> used by this <see cref="DirectoryTaxonomyWriter"/>.
+            /// </summary>
+            public virtual IndexWriter IndexWriter { get { return writer; } }
         }
 
         public const string INDEX_SOURCE = "index";
@@ -95,6 +99,8 @@ namespace Lucene.Net.Replicator
         private readonly SnapshotDirectoryTaxonomyWriter taxonomyWriter;
         private readonly IndexCommit indexCommit, taxonomyCommit;
         private readonly SnapshotDeletionPolicy indexSdp, taxonomySdp;
+        private readonly string version;
+        private readonly IDictionary<string, IList<RevisionFile>> sourceFiles;
 
         /// <summary>
         /// Returns a map of the revision files from the given <see cref="IndexCommit"/>s
of the search and taxonomy indexes.
@@ -136,14 +142,14 @@ namespace Lucene.Net.Replicator
             this.taxonomySdp = taxonomyWriter.DeletionPolicy;
             this.indexCommit = indexSdp.Snapshot();
             this.taxonomyCommit = taxonomySdp.Snapshot();
-            this.Version = RevisionVersion(indexCommit, taxonomyCommit);
-            this.SourceFiles = RevisionFiles(indexCommit, taxonomyCommit);
+            this.version = RevisionVersion(indexCommit, taxonomyCommit);
+            this.sourceFiles = RevisionFiles(indexCommit, taxonomyCommit);
         }
 
         /// <summary>
         /// Compares this <see cref="IndexAndTaxonomyRevision"/> to the given <see
cref="version"/>.
         /// </summary>
-        public int CompareTo(string version)
+        public virtual int CompareTo(string version)
         {
             string[] parts = version.Split(':');
             long indexGen = long.Parse(parts[0], NumberStyles.HexNumber);
@@ -160,7 +166,7 @@ namespace Lucene.Net.Replicator
             return taxonomyCommitGen < taxonomyGen ? -1 : (taxonomyCommitGen > taxonomyGen
? 1 : 0);
         }
 
-        public int CompareTo(IRevision other)
+        public virtual int CompareTo(IRevision other)
         {
             if (other == null)
                 throw new ArgumentNullException("other");
@@ -173,12 +179,12 @@ namespace Lucene.Net.Replicator
             return cmp != 0 ? cmp : taxonomyCommit.CompareTo(itr.taxonomyCommit);
         }
 
-        public string Version { get; private set; }
+        public virtual string Version { get { return version; } }
 
-        public IDictionary<string, IList<RevisionFile>> SourceFiles { get; private
set; }
+        public virtual IDictionary<string, IList<RevisionFile>> SourceFiles {
get { return sourceFiles; } }
 
         /// <exception cref="IOException"></exception>
-        public Stream Open(string source, string fileName)
+        public virtual Stream Open(string source, string fileName)
         {
             Debug.Assert(source.Equals(INDEX_SOURCE) || source.Equals(TAXONOMY_SOURCE), string.Format("invalid
source; expected=({0} or {1}) got={2}", INDEX_SOURCE, TAXONOMY_SOURCE, source));
             IndexCommit commit = source.Equals(INDEX_SOURCE) ? indexCommit : taxonomyCommit;
@@ -186,7 +192,7 @@ namespace Lucene.Net.Replicator
         }
 
         /// <exception cref="IOException"></exception>
-        public void Release()
+        public virtual void Release()
         {
             try
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/IndexInputInputStream.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IndexInputInputStream.cs b/src/Lucene.Net.Replicator/IndexInputInputStream.cs
index df72010..d6af827 100644
--- a/src/Lucene.Net.Replicator/IndexInputInputStream.cs
+++ b/src/Lucene.Net.Replicator/IndexInputInputStream.cs
@@ -1,6 +1,6 @@
-using System;
+using Lucene.Net.Store;
+using System;
 using System.IO;
-using Lucene.Net.Store;
 
 namespace Lucene.Net.Replicator
 {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/IndexReplicationHandler.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IndexReplicationHandler.cs b/src/Lucene.Net.Replicator/IndexReplicationHandler.cs
index 5189e44..99d3445 100644
--- a/src/Lucene.Net.Replicator/IndexReplicationHandler.cs
+++ b/src/Lucene.Net.Replicator/IndexReplicationHandler.cs
@@ -1,11 +1,11 @@
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+using Lucene.Net.Util;
 using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Text.RegularExpressions;
-using Lucene.Net.Index;
-using Lucene.Net.Store;
-using Lucene.Net.Util;
 using Directory = Lucene.Net.Store.Directory;
 
 namespace Lucene.Net.Replicator
@@ -57,7 +57,10 @@ namespace Lucene.Net.Replicator
 
         private readonly Directory indexDirectory;
         private readonly Func<bool?> callback;
-        private InfoStream infoStream;
+
+        private volatile IDictionary<string, IList<RevisionFile>> currentRevisionFiles;
+        private volatile string currentVersion;
+        private volatile InfoStream infoStream;
 
         //Note: LUCENENET Specific Utility Method
         private void WriteToInfoStream(params string[] messages)
@@ -236,28 +239,28 @@ namespace Lucene.Net.Replicator
             this.callback = callback;
             this.indexDirectory = indexDirectory;
 
-            CurrentVersion = null;
-            CurrentRevisionFiles = null;
+            currentVersion = null;
+            currentRevisionFiles = null;
 
             if (DirectoryReader.IndexExists(indexDirectory))
             {
                 IList<IndexCommit> commits = DirectoryReader.ListCommits(indexDirectory);
                 IndexCommit commit = commits.Last();
 
-                CurrentVersion = IndexRevision.RevisionVersion(commit);
-                CurrentRevisionFiles = IndexRevision.RevisionFiles(commit);
+                currentVersion = IndexRevision.RevisionVersion(commit);
+                currentRevisionFiles = IndexRevision.RevisionFiles(commit);
 
                 WriteToInfoStream(
-                    string.Format("constructor(): currentVersion={0} currentRevisionFiles={1}",
CurrentVersion, CurrentRevisionFiles),
+                    string.Format("constructor(): currentVersion={0} currentRevisionFiles={1}",
currentVersion, currentRevisionFiles),
                     string.Format("constructor(): commit={0}", commit));
             }
         }
 
-        public string CurrentVersion { get; private set; }
+        public virtual string CurrentVersion { get { return currentVersion; } }
 
-        public IDictionary<string, IList<RevisionFile>> CurrentRevisionFiles
{ get; private set; }
+        public virtual IDictionary<string, IList<RevisionFile>> CurrentRevisionFiles
{ get { return currentRevisionFiles; } }
 
-        public void RevisionReady(string version,
+        public virtual void RevisionReady(string version,
             IDictionary<string, IList<RevisionFile>> revisionFiles,
             IDictionary<string, IList<string>> copiedFiles,
             IDictionary<string, Directory> sourceDirectory)
@@ -293,10 +296,10 @@ namespace Lucene.Net.Replicator
             }
 
             // all files have been successfully copied + sync'd. update the handler's state
-            CurrentRevisionFiles = revisionFiles;
-            CurrentVersion = version;
+            currentRevisionFiles = revisionFiles;
+            currentVersion = version;
 
-            WriteToInfoStream(string.Format("revisionReady(): currentVersion={0} currentRevisionFiles={1}",
CurrentVersion, CurrentRevisionFiles));
+            WriteToInfoStream(string.Format("revisionReady(): currentVersion={0} currentRevisionFiles={1}",
currentVersion, currentRevisionFiles));
 
             // update the segments.gen file
             WriteSegmentsGen(segmentsFile, indexDirectory);
@@ -326,7 +329,7 @@ namespace Lucene.Net.Replicator
         /// <summary>
         /// Gets or sets the <see cref="Util.InfoStream"/> to use for logging messages.
         /// </summary>
-        public InfoStream InfoStream
+        public virtual InfoStream InfoStream
         {
             get { return infoStream; }
             set { infoStream = value ?? InfoStream.NO_OUTPUT; }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/IndexRevision.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IndexRevision.cs b/src/Lucene.Net.Replicator/IndexRevision.cs
index 29ea77c..092fc3e 100644
--- a/src/Lucene.Net.Replicator/IndexRevision.cs
+++ b/src/Lucene.Net.Replicator/IndexRevision.cs
@@ -1,11 +1,11 @@
+using Lucene.Net.Index;
+using Lucene.Net.Store;
 using System;
-using System.IO;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Globalization;
+using System.IO;
 using System.Linq;
-using Lucene.Net.Index;
-using Lucene.Net.Store;
 using Directory = Lucene.Net.Store.Directory;
 
 namespace Lucene.Net.Replicator
@@ -50,8 +50,8 @@ namespace Lucene.Net.Replicator
         private readonly IndexWriter writer;
         private readonly IndexCommit commit;
         private readonly SnapshotDeletionPolicy sdp;
-
-        public IDictionary<string, IList<RevisionFile>> SourceFiles { get; private
set; }
+        private readonly string version;
+        private readonly IDictionary<string, IList<RevisionFile>> sourceFiles;
 
         // returns a RevisionFile with some metadata
         private static RevisionFile CreateRevisionFile(string fileName, Directory directory)
@@ -98,11 +98,11 @@ namespace Lucene.Net.Replicator
 
             this.writer = writer;
             this.commit = sdp.Snapshot();
-            this.Version = RevisionVersion(commit);
-            this.SourceFiles = RevisionFiles(commit);
+            this.version = RevisionVersion(commit);
+            this.sourceFiles = RevisionFiles(commit);
         }
 
-        public int CompareTo(string version)
+        public virtual int CompareTo(string version)
         {
             long gen = long.Parse(version, NumberStyles.HexNumber);
             long commitGen = commit.Generation;
@@ -110,7 +110,7 @@ namespace Lucene.Net.Replicator
             return commitGen < gen ? -1 : (commitGen > gen ? 1 : 0);
         }
 
-        public int CompareTo(IRevision other)
+        public virtual int CompareTo(IRevision other)
         {
             //TODO: This breaks the contract and will fail if called with a different implementation
             //      This is a flaw inherited from the original source...
@@ -119,15 +119,17 @@ namespace Lucene.Net.Replicator
             return commit.CompareTo(or.commit);
         }
 
-        public string Version { get; private set; }
+        public virtual string Version { get { return version; } }
+
+        public virtual IDictionary<string, IList<RevisionFile>> SourceFiles {
get { return sourceFiles; } }
 
-        public Stream Open(string source, string fileName)
+        public virtual Stream Open(string source, string fileName)
         {
             Debug.Assert(source.Equals(SOURCE), string.Format("invalid source; expected={0}
got={1}", SOURCE, source));
             return new IndexInputStream(commit.Directory.OpenInput(fileName, IOContext.READ_ONCE));
         }
 
-        public void Release()
+        public virtual void Release()
         {
             sdp.Release(commit);
             writer.DeleteUnusedFiles();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/LocalReplicator.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/LocalReplicator.cs b/src/Lucene.Net.Replicator/LocalReplicator.cs
index 981eecb..349a088 100644
--- a/src/Lucene.Net.Replicator/LocalReplicator.cs
+++ b/src/Lucene.Net.Replicator/LocalReplicator.cs
@@ -55,7 +55,7 @@ namespace Lucene.Net.Replicator
 
             /// <summary/>
             /// <exception cref="InvalidOperationException"></exception>
-            public void DecRef()
+            public virtual void DecRef()
             {
                 if (refCount.Get() <= 0)
                 {
@@ -86,7 +86,7 @@ namespace Lucene.Net.Replicator
                 }
             }
 
-            public void IncRef()
+            public virtual void IncRef()
             {
                 refCount.IncrementAndGet();
             }
@@ -106,12 +106,12 @@ namespace Lucene.Net.Replicator
                 lastAccessTime = Stopwatch.GetTimestamp();
             }
 
-            public bool IsExpired(long expirationThreshold)
+            public virtual bool IsExpired(long expirationThreshold)
             {
                 return lastAccessTime < Stopwatch.GetTimestamp() - expirationThreshold
* Stopwatch.Frequency / 1000; // LUCENENET TODO: CurrentTimeMilliseconds()
             }
 
-            public void MarkAccessed()
+            public virtual void MarkAccessed()
             {
                 lastAccessTime = Stopwatch.GetTimestamp(); // LUCENENET TODO: CurrentTimeMilliseconds()
             }
@@ -169,7 +169,7 @@ namespace Lucene.Net.Replicator
             }
         }
 
-        public SessionToken CheckForUpdate(string currentVersion)
+        public virtual SessionToken CheckForUpdate(string currentVersion)
         {
             lock (padlock)
             {
@@ -190,9 +190,9 @@ namespace Lucene.Net.Replicator
             }
         }
 
-        public void Dispose() // LUCENENET TODO: API Dispose pattern
+        protected virtual void Dispose(bool disposing)
         {
-            if (disposed)
+            if (disposed || !disposing)
                 return;
 
             lock (padlock)
@@ -204,14 +204,20 @@ namespace Lucene.Net.Replicator
             disposed = true;
         }
 
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
         /// <summary>
-        /// Gets or sets the expiration threshold.
+        /// Gets or sets the expiration threshold in milliseconds.
         /// <para/>
         /// If a replication session is inactive this
         /// long it is automatically expired, and further attempts to operate within
         /// this session will throw a <see cref="SessionExpiredException"/>.
         /// </summary>
-        public long ExpirationThreshold
+        public virtual long ExpirationThreshold
         {
             get { return expirationThreshold; }
             set
@@ -225,7 +231,7 @@ namespace Lucene.Net.Replicator
             }
         }
 
-        public Stream ObtainFile(string sessionId, string source, string fileName)
+        public virtual Stream ObtainFile(string sessionId, string source, string fileName)
         {
             lock (padlock)
             {
@@ -247,7 +253,7 @@ namespace Lucene.Net.Replicator
             }
         }
 
-        public void Publish(IRevision revision)
+        public virtual void Publish(IRevision revision)
         {
             lock (padlock)
             {
@@ -280,7 +286,7 @@ namespace Lucene.Net.Replicator
         }
 
         /// <exception cref="InvalidOperationException"></exception>
-        public void Release(string sessionId)
+        public virtual void Release(string sessionId)
         {
             lock (padlock)
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/PerSessionDirectoryFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/PerSessionDirectoryFactory.cs b/src/Lucene.Net.Replicator/PerSessionDirectoryFactory.cs
index 3661f71..d16ea4e 100644
--- a/src/Lucene.Net.Replicator/PerSessionDirectoryFactory.cs
+++ b/src/Lucene.Net.Replicator/PerSessionDirectoryFactory.cs
@@ -1,6 +1,6 @@
+using Lucene.Net.Store;
 using System;
 using System.IO;
-using Lucene.Net.Store;
 using Directory = Lucene.Net.Store.Directory;
 
 namespace Lucene.Net.Replicator
@@ -40,14 +40,14 @@ namespace Lucene.Net.Replicator
             this.workingDirectory = workingDirectory;
         }
 
-        public Directory GetDirectory(string sessionId, string source)
+        public virtual Directory GetDirectory(string sessionId, string source)
         {
             string sourceDirectory = Path.Combine(workingDirectory, sessionId, source);
             System.IO.Directory.CreateDirectory(sourceDirectory);
             return FSDirectory.Open(sourceDirectory);
         }
 
-        public void CleanupSession(string sessionId)
+        public virtual void CleanupSession(string sessionId)
         {
             if (string.IsNullOrEmpty(sessionId)) throw new ArgumentException("sessionID cannot
be empty", "sessionId");
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/ReplicationClient.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/ReplicationClient.cs b/src/Lucene.Net.Replicator/ReplicationClient.cs
index 6064856..7388093 100644
--- a/src/Lucene.Net.Replicator/ReplicationClient.cs
+++ b/src/Lucene.Net.Replicator/ReplicationClient.cs
@@ -1,3 +1,6 @@
+using Lucene.Net.Store;
+using Lucene.Net.Support.Threading;
+using Lucene.Net.Util;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
@@ -5,9 +8,6 @@ using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Threading;
-using Lucene.Net.Store;
-using Lucene.Net.Support.Threading;
-using Lucene.Net.Util;
 using Directory = Lucene.Net.Store.Directory;
 
 namespace Lucene.Net.Replicator
@@ -314,7 +314,7 @@ namespace Lucene.Net.Replicator
         }
 
         /// <summary>Throws <see cref="ObjectDisposedException"/> if the client
has already been disposed.</summary>
-        protected virtual void EnsureOpen()
+        protected void EnsureOpen()
         {
             if (!disposed)
                 return;
@@ -350,7 +350,7 @@ namespace Lucene.Net.Replicator
         /// Returns the files required for replication. By default, this method returns
         /// all files that exist in the new revision, but not in the handler.
         /// </summary>
-        private IDictionary<string, IList<RevisionFile>> RequiredFiles(IDictionary<string,
IList<RevisionFile>> newRevisionFiles)
+        protected virtual IDictionary<string, IList<RevisionFile>> RequiredFiles(IDictionary<string,
IList<RevisionFile>> newRevisionFiles)
         {
             IDictionary<string, IList<RevisionFile>> handlerRevisionFiles = handler.CurrentRevisionFiles;
             if (handlerRevisionFiles == null)
@@ -375,7 +375,7 @@ namespace Lucene.Net.Replicator
 
         protected virtual void Dispose(bool disposing)
         {
-            if (disposed)
+            if (disposed || !disposing)
                 return;
 
             StopUpdateThread();
@@ -395,7 +395,7 @@ namespace Lucene.Net.Replicator
         /// will be set.
         /// </summary>
         /// <exception cref="InvalidOperationException"> if the thread has already
been started </exception>
-        public void StartUpdateThread(long intervalMillis, string threadName)
+        public virtual void StartUpdateThread(long intervalMillis, string threadName)
         {
             EnsureOpen();
             if (updateThread != null && updateThread.IsAlive)
@@ -412,7 +412,7 @@ namespace Lucene.Net.Replicator
         /// Stop the update thread. If the update thread is not running, silently does
         /// nothing. This method returns after the update thread has stopped.
         /// </summary>
-        public void StopUpdateThread()
+        public virtual void StopUpdateThread()
         {
             // this will trigger the thread to terminate if it awaits the lock.
             // otherwise, if it's in the middle of replication, we wait for it to
@@ -429,7 +429,7 @@ namespace Lucene.Net.Replicator
         /// caused it to terminate (i.e. <see cref="HandleUpdateException"/>
         /// threw the exception further).
         /// </summary>
-        public bool IsUpdateThreadAlive
+        public virtual bool IsUpdateThreadAlive
         {
             get { return updateThread != null && updateThread.IsAlive; }
         }
@@ -446,7 +446,7 @@ namespace Lucene.Net.Replicator
         /// is running or not.
         /// </summary>
         /// <exception cref="IOException"></exception>
-        public void UpdateNow() 
+        public virtual void UpdateNow() 
         {
             EnsureOpen();
             if (updateThread != null)
@@ -472,7 +472,7 @@ namespace Lucene.Net.Replicator
         /// <summary> 
         /// Gets or sets the <see cref="Util.InfoStream"/> to use for logging messages.

         /// </summary>
-        public InfoStream InfoStream
+        public virtual InfoStream InfoStream
         {
             get { return infoStream; }
             set { infoStream = value ?? InfoStream.NO_OUTPUT; }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/73f6a4e2/src/Lucene.Net.Replicator/RevisionFile.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/RevisionFile.cs b/src/Lucene.Net.Replicator/RevisionFile.cs
index c74f057..0fa897f 100644
--- a/src/Lucene.Net.Replicator/RevisionFile.cs
+++ b/src/Lucene.Net.Replicator/RevisionFile.cs
@@ -60,7 +60,7 @@ namespace Lucene.Net.Replicator
         }
 
         // LUCENENET specific Equals overload
-        public bool Equals(RevisionFile other)
+        public virtual bool Equals(RevisionFile other)
         {
             if (ReferenceEquals(null, other)) return false;
             if (ReferenceEquals(this, other)) return true;


Mime
View raw message