Commit 6c44a771 authored by Nick Craver's avatar Nick Craver

Cleanup: ConnectionMultiplexer partials

parent 8748d222
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
partial class ConnectionMultiplexer public partial class ConnectionMultiplexer
{ {
private IProfiler profiler; private IProfiler profiler;
...@@ -16,13 +16,13 @@ partial class ConnectionMultiplexer ...@@ -16,13 +16,13 @@ partial class ConnectionMultiplexer
/// IProfiledCommand with. See BeginProfiling(object) and FinishProfiling(object) /// IProfiledCommand with. See BeginProfiling(object) and FinishProfiling(object)
/// for more details. /// for more details.
/// </summary> /// </summary>
/// <param name="profiler">The profiler to register.</param>
public void RegisterProfiler(IProfiler profiler) public void RegisterProfiler(IProfiler profiler)
{ {
if (profiler == null) throw new ArgumentNullException(nameof(profiler));
if (this.profiler != null) throw new InvalidOperationException("IProfiler already registered for this ConnectionMultiplexer"); if (this.profiler != null) throw new InvalidOperationException("IProfiler already registered for this ConnectionMultiplexer");
this.profiler = profiler; this.profiler = profiler ?? throw new ArgumentNullException(nameof(profiler));
this.profiledCommands = new ProfileContextTracker(); profiledCommands = new ProfileContextTracker();
} }
/// <summary> /// <summary>
...@@ -35,6 +35,7 @@ public void RegisterProfiler(IProfiler profiler) ...@@ -35,6 +35,7 @@ public void RegisterProfiler(IProfiler profiler)
/// ///
/// Note that forContext cannot be a WeakReference or a WeakReference&lt;T&gt; /// Note that forContext cannot be a WeakReference or a WeakReference&lt;T&gt;
/// </summary> /// </summary>
/// <param name="forContext">The context to begin profiling.</param>
public void BeginProfiling(object forContext) public void BeginProfiling(object forContext)
{ {
if (profiler == null) throw new InvalidOperationException("Cannot begin profiling if no IProfiler has been registered with RegisterProfiler"); if (profiler == null) throw new InvalidOperationException("Cannot begin profiling if no IProfiler has been registered with RegisterProfiler");
...@@ -52,13 +53,14 @@ public void BeginProfiling(object forContext) ...@@ -52,13 +53,14 @@ public void BeginProfiling(object forContext)
/// ///
/// By default this may do a sweep for dead profiling contexts, you can disable this by passing "allowCleanupSweep: false". /// By default this may do a sweep for dead profiling contexts, you can disable this by passing "allowCleanupSweep: false".
/// </summary> /// </summary>
/// <param name="forContext">The context to begin profiling.</param>
/// <param name="allowCleanupSweep">Whether to allow cleanup of old profiling sessions.</param>
public ProfiledCommandEnumerable FinishProfiling(object forContext, bool allowCleanupSweep = true) public ProfiledCommandEnumerable FinishProfiling(object forContext, bool allowCleanupSweep = true)
{ {
if (profiler == null) throw new InvalidOperationException("Cannot begin profiling if no IProfiler has been registered with RegisterProfiler"); if (profiler == null) throw new InvalidOperationException("Cannot begin profiling if no IProfiler has been registered with RegisterProfiler");
if (forContext == null) throw new ArgumentNullException(nameof(forContext)); if (forContext == null) throw new ArgumentNullException(nameof(forContext));
ProfiledCommandEnumerable ret; if (!profiledCommands.TryRemove(forContext, out ProfiledCommandEnumerable ret))
if (!profiledCommands.TryRemove(forContext, out ret))
{ {
throw ExceptionFactory.FinishedProfilingWithInvalidContext(forContext); throw ExceptionFactory.FinishedProfilingWithInvalidContext(forContext);
} }
......
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
partial class ConnectionMultiplexer public partial class ConnectionMultiplexer
{ {
internal SocketManager SocketManager => socketManager; internal SocketManager SocketManager => socketManager;
...@@ -29,6 +29,7 @@ internal void RequestWrite(PhysicalBridge bridge, bool forced) ...@@ -29,6 +29,7 @@ internal void RequestWrite(PhysicalBridge bridge, bool forced)
tmp.RequestWrite(bridge, forced); tmp.RequestWrite(bridge, forced);
} }
} }
partial void OnWriterCreated(); partial void OnWriterCreated();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment