lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject lucenenet git commit: More .NET alignment
Date Mon, 19 Jan 2015 17:51:01 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master eb4de4d75 -> eef038634


More .NET alignment


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

Branch: refs/heads/master
Commit: eef03863458de264f09806b9833f34083d3aad87
Parents: eb4de4d
Author: Itamar Syn-Hershko <itamar@code972.com>
Authored: Mon Jan 19 19:50:47 2015 +0200
Committer: Itamar Syn-Hershko <itamar@code972.com>
Committed: Mon Jan 19 19:50:47 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Store/IOContext.cs          |  6 +--
 .../Store/RateLimitedDirectoryWrapper.cs        | 42 +++++++++-----------
 src/Lucene.Net.Core/Store/RateLimiter.cs        | 17 ++++----
 3 files changed, 31 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/eef03863/src/Lucene.Net.Core/Store/IOContext.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/IOContext.cs b/src/Lucene.Net.Core/Store/IOContext.cs
index 458c52c..3838899 100644
--- a/src/Lucene.Net.Core/Store/IOContext.cs
+++ b/src/Lucene.Net.Core/Store/IOContext.cs
@@ -43,7 +43,7 @@ namespace Lucene.Net.Store
         /// <summary>
         /// An object of a enumerator Context type
         /// </summary>
-        public readonly Context_e Context;
+        public readonly Context_e? Context;
 
         public readonly MergeInfo MergeInfo;
 
@@ -71,7 +71,7 @@ namespace Lucene.Net.Store
             this.FlushInfo = flushInfo;
         }
 
-        public IOContext(Context_e context)
+        public IOContext(Context_e? context)
             : this(context, null)
         {
         }
@@ -89,7 +89,7 @@ namespace Lucene.Net.Store
         {
         }
 
-        private IOContext(Context_e context, MergeInfo mergeInfo)
+        private IOContext(Context_e? context, MergeInfo mergeInfo)
         {
             Debug.Assert(context != Context_e.MERGE || mergeInfo != null, "MergeInfo must
not be null if context is MERGE");
             Debug.Assert(context != Context_e.FLUSH, "Use IOContext(FlushInfo) to create
a FLUSH IOContext");

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/eef03863/src/Lucene.Net.Core/Store/RateLimitedDirectoryWrapper.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/RateLimitedDirectoryWrapper.cs b/src/Lucene.Net.Core/Store/RateLimitedDirectoryWrapper.cs
index 8ac68b1..ba7d06d 100644
--- a/src/Lucene.Net.Core/Store/RateLimitedDirectoryWrapper.cs
+++ b/src/Lucene.Net.Core/Store/RateLimitedDirectoryWrapper.cs
@@ -1,8 +1,9 @@
+using System;
+using System.Collections.Concurrent;
 using System.Diagnostics;
 
 namespace Lucene.Net.Store
 {
-    using Lucene.Net.Support;
     using System.Collections.Generic;
 
     /*
@@ -34,7 +35,7 @@ namespace Lucene.Net.Store
         // we need to be volatile here to make sure we see all the values that are set
         // / modified concurrently
         //private volatile RateLimiter[] ContextRateLimiters = new RateLimiter[Enum.GetValues(typeof(IOContext.Context_e)).Length];
-        private IDictionary<IOContext.Context_e?, RateLimiter> ContextRateLimiters
= new ConcurrentHashMap<IOContext.Context_e?, RateLimiter>();
+        private readonly IDictionary<IOContext.Context_e?, RateLimiter> _contextRateLimiters
= new ConcurrentDictionary<IOContext.Context_e?, RateLimiter>();
 
         public RateLimitedDirectoryWrapper(Directory wrapped)
             : base(wrapped)
@@ -44,8 +45,8 @@ namespace Lucene.Net.Store
         public override IndexOutput CreateOutput(string name, IOContext context)
         {
             EnsureOpen();
-            IndexOutput output = base.CreateOutput(name, context);
-            RateLimiter limiter = GetRateLimiter(context.Context);
+            var output = base.CreateOutput(name, context);
+            var limiter = GetRateLimiter(context.Context);
             if (limiter != null)
             {
                 return new RateLimitedIndexOutput(limiter, output);
@@ -65,10 +66,11 @@ namespace Lucene.Net.Store
             @in.Copy(to, src, dest, context);
         }
 
-        private RateLimiter GetRateLimiter(IOContext.Context_e context)
+        private RateLimiter GetRateLimiter(IOContext.Context_e? context)
         {
             Debug.Assert(context != null);
-            return ContextRateLimiters[context];
+            RateLimiter ret;
+            return _contextRateLimiters.TryGetValue(context, out ret) ? ret : null;
         }
 
         /// <summary>
@@ -89,7 +91,7 @@ namespace Lucene.Net.Store
         ///           if context is <code>null</code> </exception>
         /// <exception cref="AlreadyClosedException"> if the <seealso cref="Directory"/>
is already closed
         /// @lucene.experimental </exception>
-        public void SetMaxWriteMBPerSec(double mbPerSec, IOContext.Context_e? context)
+        public void SetMaxWriteMBPerSec(double? mbPerSec, IOContext.Context_e? context)
         {
             EnsureOpen();
             if (context == null)
@@ -98,24 +100,24 @@ namespace Lucene.Net.Store
             }
             //int ord = context.ordinal();
             RateLimiter limiter;
-            ContextRateLimiters.TryGetValue(context, out limiter);
+            _contextRateLimiters.TryGetValue(context, out limiter);
 
             if (mbPerSec == null)
             {
                 if (limiter != null)
                 {
                     limiter.MbPerSec = double.MaxValue;
-                    ContextRateLimiters[context] = null;
+                    _contextRateLimiters[context] = null;
                 }
             }
             else if (limiter != null)
             {
-                limiter.MbPerSec = mbPerSec;
-                ContextRateLimiters[context] = limiter; // cross the mem barrier again
+                limiter.MbPerSec = mbPerSec.Value;
+                _contextRateLimiters[context] = limiter; // cross the mem barrier again
             }
             else
             {
-                ContextRateLimiters[context] = new RateLimiter.SimpleRateLimiter(mbPerSec);
+                _contextRateLimiters[context] = new RateLimiter.SimpleRateLimiter(mbPerSec.Value);
             }
         }
 
@@ -130,35 +132,27 @@ namespace Lucene.Net.Store
         /// allows to use the same limiter instance across several directories globally
         /// limiting IO across them.
         /// </summary>
-        /// <exception cref="IllegalArgumentException">
+        /// <exception cref="ArgumentException">
         ///           if context is <code>null</code> </exception>
         /// <exception cref="AlreadyClosedException"> if the <seealso cref="Directory"/>
is already closed
         /// @lucene.experimental </exception>
         public void SetRateLimiter(RateLimiter mergeWriteRateLimiter, IOContext.Context_e
context)
         {
             EnsureOpen();
-            if (context == null)
-            {
-                throw new System.ArgumentException("Context must not be null");
-            }
-            ContextRateLimiters[context] = mergeWriteRateLimiter;
+            _contextRateLimiters[context] = mergeWriteRateLimiter;
         }
 
         /// <summary>
         /// See <seealso cref="#setMaxWriteMBPerSec"/>.
         /// </summary>
-        /// <exception cref="IllegalArgumentException">
+        /// <exception cref="ArgumentException">
         ///           if context is <code>null</code> </exception>
         /// <exception cref="AlreadyClosedException"> if the <seealso cref="Directory"/>
is already closed
         /// @lucene.experimental </exception>
         public double GetMaxWriteMBPerSec(IOContext.Context_e context)
         {
             EnsureOpen();
-            if (context == null)
-            {
-                throw new System.ArgumentException("Context must not be null");
-            }
-            RateLimiter limiter = GetRateLimiter(context);
+            var limiter = GetRateLimiter(context);
             return limiter == null ? 0 : limiter.MbPerSec;
         }
     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/eef03863/src/Lucene.Net.Core/Store/RateLimiter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/RateLimiter.cs b/src/Lucene.Net.Core/Store/RateLimiter.cs
index 9d66c68..886bd31 100644
--- a/src/Lucene.Net.Core/Store/RateLimiter.cs
+++ b/src/Lucene.Net.Core/Store/RateLimiter.cs
@@ -52,7 +52,7 @@ namespace Lucene.Net.Store
         /// </summary>
         public class SimpleRateLimiter : RateLimiter
         {
-            internal double MbPerSec_Renamed;
+            internal double mbPerSec;
             internal double NsPerByte;
             internal long LastNS;
 
@@ -74,12 +74,15 @@ namespace Lucene.Net.Store
             {
                 set
                 {
-                    this.MbPerSec_Renamed = value;
-                    NsPerByte = 1000000000.0 / (1024 * 1024 * value);
+                    this.mbPerSec = value;
+                    if (value == 0)
+                        NsPerByte = 0;
+                    else
+                        NsPerByte = 1000000000.0 / (1024 * 1024 * value);
                 }
                 get
                 {
-                    return this.MbPerSec_Renamed;
+                    return this.mbPerSec;
                 }
             }
 
@@ -102,9 +105,9 @@ namespace Lucene.Net.Store
 
                 // TODO: this is purely instantaneous rate; maybe we
                 // should also offer decayed recent history one?
-                long targetNS = LastNS = LastNS + ((long)(bytes * NsPerByte));
+                var targetNS = LastNS = LastNS + ((long)(bytes * NsPerByte));
                 long startNS;
-                long curNS = startNS = DateTime.UtcNow.Ticks * 100 /* ns */;
+                var curNS = startNS = DateTime.UtcNow.Ticks * 100 /* ns */;
                 if (LastNS < curNS)
                 {
                     LastNS = curNS;
@@ -114,7 +117,7 @@ namespace Lucene.Net.Store
                 // enough:
                 while (true)
                 {
-                    long pauseNS = targetNS - curNS;
+                    var pauseNS = targetNS - curNS;
                     if (pauseNS > 0)
                     {
                         try


Mime
View raw message