From 8accb02da56432af8a6ec2982a44cc827b4c5417 Mon Sep 17 00:00:00 2001 From: James Watson Date: Tue, 17 Apr 2018 23:21:54 +0100 Subject: [PATCH] Port necessary QuietDispose requests on Publications/Subscriptions --- src/Adaptive.Aeron/Counter.cs | 2 +- src/Adaptive.Agrona/CloseHelper.cs | 4 +--- .../Concurrent/Status/AtomicCounter.cs | 2 +- src/Adaptive.Archiver/AeronArchive.cs | 18 +++++++++--------- .../Service/ClusteredServiceContainer.cs | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Adaptive.Aeron/Counter.cs b/src/Adaptive.Aeron/Counter.cs index 4d7981bb..31409efd 100644 --- a/src/Adaptive.Aeron/Counter.cs +++ b/src/Adaptive.Aeron/Counter.cs @@ -53,7 +53,7 @@ public virtual long RegistrationId() /// This method is idempotent. /// /// - public virtual void Close() + public override void Dispose() { if (null != clientConductor) { diff --git a/src/Adaptive.Agrona/CloseHelper.cs b/src/Adaptive.Agrona/CloseHelper.cs index 7bacd6ee..ef5df1e7 100644 --- a/src/Adaptive.Agrona/CloseHelper.cs +++ b/src/Adaptive.Agrona/CloseHelper.cs @@ -18,10 +18,8 @@ namespace Adaptive.Agrona { - public class CloseHelper + public static class CloseHelper { - // Note Olivier: this is not really relevant in .NET since .Dispose should never throw but we want to keep the implementation close to the Java codebase - /// /// Quietly close a dealing with nulls and exceptions. /// diff --git a/src/Adaptive.Agrona/Concurrent/Status/AtomicCounter.cs b/src/Adaptive.Agrona/Concurrent/Status/AtomicCounter.cs index 78387485..abc486cc 100644 --- a/src/Adaptive.Agrona/Concurrent/Status/AtomicCounter.cs +++ b/src/Adaptive.Agrona/Concurrent/Status/AtomicCounter.cs @@ -151,7 +151,7 @@ public long GetWeak() /// /// Free the counter slot for reuse. /// - public void Dispose() + public virtual void Dispose() { if (!IsClosed) { diff --git a/src/Adaptive.Archiver/AeronArchive.cs b/src/Adaptive.Archiver/AeronArchive.cs index 21d1e8c3..7855f533 100644 --- a/src/Adaptive.Archiver/AeronArchive.cs +++ b/src/Adaptive.Archiver/AeronArchive.cs @@ -79,7 +79,7 @@ internal AeronArchive(Context ctx) recordingDescriptorPoller = new RecordingDescriptorPoller(subscription, FRAGMENT_LIMIT, controlSessionId); } - catch (Exception ex) + catch (Exception) { if (!ctx.OwnsAeronClient()) { @@ -89,7 +89,7 @@ internal AeronArchive(Context ctx) CloseHelper.QuietDispose(ctx); - throw ex; + throw; } } @@ -198,11 +198,11 @@ public static AsyncConnect ConnectAsync(Context ctx) { if (!ctx.OwnsAeronClient()) { - subscription?.Dispose(); - publication?.Dispose(); + CloseHelper.QuietDispose(subscription); + CloseHelper.QuietDispose(publication); } - ctx.Dispose(); + CloseHelper.QuietDispose(ctx); throw; } @@ -326,7 +326,7 @@ public Publication AddRecordedPublication(string channel, int streamId) } catch (Exception) { - publication?.Dispose(); + CloseHelper.QuietDispose(publication); throw; } finally @@ -359,7 +359,7 @@ public ExclusivePublication AddRecordedExclusivePublication(string channel, int } catch (Exception) { - publication?.Dispose(); + CloseHelper.QuietDispose(publication); throw; } finally @@ -505,7 +505,7 @@ public long StartReplay(long recordingId, long position, long length, string rep if (!archiveProxy.Replay(recordingId, position, length, replayChannel, replayStreamId, correlationId, controlSessionId)) { - throw new System.InvalidOperationException("failed to send replay request"); + throw new InvalidOperationException("failed to send replay request"); } return PollForResponse(correlationId); @@ -529,7 +529,7 @@ public void StopReplay(long replaySessionId) if (!archiveProxy.StopReplay(replaySessionId, correlationId, controlSessionId)) { - throw new System.InvalidOperationException("failed to send stop recording request"); + throw new InvalidOperationException("failed to send stop recording request"); } PollForResponse(correlationId); diff --git a/src/Adaptive.Cluster/Service/ClusteredServiceContainer.cs b/src/Adaptive.Cluster/Service/ClusteredServiceContainer.cs index decf9126..71c21d2d 100644 --- a/src/Adaptive.Cluster/Service/ClusteredServiceContainer.cs +++ b/src/Adaptive.Cluster/Service/ClusteredServiceContainer.cs @@ -1101,7 +1101,7 @@ public void DeleteDirectory() /// public void Dispose() { - markFile?.Dispose(); + CloseHelper.QuietDispose(markFile); if (ownsAeronClient) {