Skip to content

Commit 54b3ad6

Browse files
committed
Code cleanups.
1 parent 70a1f22 commit 54b3ad6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+565
-732
lines changed

projects/RabbitMQ.Client/client/api/PublicationAddress.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static bool TryParse(string uriLikeString, out PublicationAddress result)
112112
// Callers such as IBasicProperties.ReplyToAddress
113113
// expect null result for invalid input.
114114
// The regex.Match() throws on null arguments so we perform explicit check here
115-
if (uriLikeString == null)
115+
if (uriLikeString is null)
116116
{
117117
result = null;
118118
return false;
@@ -121,7 +121,7 @@ public static bool TryParse(string uriLikeString, out PublicationAddress result)
121121
{
122122
try
123123
{
124-
var res = Parse(uriLikeString);
124+
PublicationAddress res = Parse(uriLikeString);
125125
result = res;
126126
return true;
127127
}

projects/RabbitMQ.Client/client/exceptions/OperationInterruptedException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class OperationInterruptedException
5050
///<summary>Construct an OperationInterruptedException with
5151
///the passed-in explanation, if any.</summary>
5252
public OperationInterruptedException(ShutdownEventArgs reason)
53-
: base(reason == null ? "The AMQP operation was interrupted" :
53+
: base(reason is null ? "The AMQP operation was interrupted" :
5454
$"The AMQP operation was interrupted: {reason}")
5555
{
5656
ShutdownReason = reason;
@@ -59,7 +59,7 @@ public OperationInterruptedException(ShutdownEventArgs reason)
5959
///<summary>Construct an OperationInterruptedException with
6060
///the passed-in explanation and prefix, if any.</summary>
6161
public OperationInterruptedException(ShutdownEventArgs reason, string prefix)
62-
: base(reason == null ? $"{prefix}: The AMQP operation was interrupted" :
62+
: base(reason is null ? $"{prefix}: The AMQP operation was interrupted" :
6363
$"{prefix}: The AMQP operation was interrupted: {reason}")
6464
{
6565
ShutdownReason = reason;

projects/RabbitMQ.Client/client/framing/BasicProperties.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,20 @@ public BasicProperties()
202202

203203
internal override void ReadPropertiesFrom(ref ContentHeaderPropertyReader reader)
204204
{
205-
var contentType_present = reader.ReadPresence();
206-
var contentEncoding_present = reader.ReadPresence();
207-
var headers_present = reader.ReadPresence();
208-
var deliveryMode_present = reader.ReadPresence();
209-
var priority_present = reader.ReadPresence();
210-
var correlationId_present = reader.ReadPresence();
211-
var replyTo_present = reader.ReadPresence();
212-
var expiration_present = reader.ReadPresence();
213-
var messageId_present = reader.ReadPresence();
214-
var timestamp_present = reader.ReadPresence();
215-
var type_present = reader.ReadPresence();
216-
var userId_present = reader.ReadPresence();
217-
var appId_present = reader.ReadPresence();
218-
var clusterId_present = reader.ReadPresence();
205+
bool contentType_present = reader.ReadPresence();
206+
bool contentEncoding_present = reader.ReadPresence();
207+
bool headers_present = reader.ReadPresence();
208+
bool deliveryMode_present = reader.ReadPresence();
209+
bool priority_present = reader.ReadPresence();
210+
bool correlationId_present = reader.ReadPresence();
211+
bool replyTo_present = reader.ReadPresence();
212+
bool expiration_present = reader.ReadPresence();
213+
bool messageId_present = reader.ReadPresence();
214+
bool timestamp_present = reader.ReadPresence();
215+
bool type_present = reader.ReadPresence();
216+
bool userId_present = reader.ReadPresence();
217+
bool appId_present = reader.ReadPresence();
218+
bool clusterId_present = reader.ReadPresence();
219219
reader.FinishPresence();
220220
if (contentType_present) { _contentType = reader.ReadShortstr(); }
221221
if (contentEncoding_present) { _contentEncoding = reader.ReadShortstr(); }

projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs

Lines changed: 31 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public AutorecoveringConnection(ConnectionFactory factory, string clientProvided
7979
ClientProvidedName = clientProvidedName;
8080
}
8181

82+
private Connection Delegate => !_disposed ? _delegate : throw new ObjectDisposedException(GetType().FullName);
83+
8284
public event EventHandler<EventArgs> RecoverySucceeded;
8385
public event EventHandler<ConnectionRecoveryErrorEventArgs> ConnectionRecoveryError;
8486
public event EventHandler<CallbackExceptionEventArgs> CallbackException
@@ -172,41 +174,41 @@ public event EventHandler<EventArgs> ConnectionUnblocked
172174

173175
public string ClientProvidedName { get; }
174176

175-
public ushort ChannelMax => !_disposed ? _delegate.ChannelMax : throw new ObjectDisposedException(GetType().FullName);
177+
public ushort ChannelMax => Delegate.ChannelMax;
176178

177-
public ConsumerWorkService ConsumerWorkService => !_disposed ? _delegate.ConsumerWorkService : throw new ObjectDisposedException(GetType().FullName);
179+
public ConsumerWorkService ConsumerWorkService => Delegate.ConsumerWorkService;
178180

179-
public IDictionary<string, object> ClientProperties => !_disposed ? _delegate.ClientProperties : throw new ObjectDisposedException(GetType().FullName);
181+
public IDictionary<string, object> ClientProperties => Delegate.ClientProperties;
180182

181-
public ShutdownEventArgs CloseReason => !_disposed ? _delegate.CloseReason : throw new ObjectDisposedException(GetType().FullName);
183+
public ShutdownEventArgs CloseReason => Delegate.CloseReason;
182184

183-
public AmqpTcpEndpoint Endpoint => !_disposed ? _delegate.Endpoint : throw new ObjectDisposedException(GetType().FullName);
185+
public AmqpTcpEndpoint Endpoint => Delegate.Endpoint;
184186

185-
public uint FrameMax => !_disposed ? _delegate.FrameMax : throw new ObjectDisposedException(GetType().FullName);
187+
public uint FrameMax => Delegate.FrameMax;
186188

187-
public TimeSpan Heartbeat => !_disposed ? _delegate.Heartbeat : throw new ObjectDisposedException(GetType().FullName);
189+
public TimeSpan Heartbeat => Delegate.Heartbeat;
188190

189-
public bool IsOpen => _delegate != null && _delegate.IsOpen;
191+
public bool IsOpen => _delegate?.IsOpen ?? false;
190192

191193
public AmqpTcpEndpoint[] KnownHosts
192194
{
193-
get => _disposed ? throw new ObjectDisposedException(GetType().FullName) : _delegate.KnownHosts;
194-
set => _delegate.KnownHosts = !_disposed ? value : throw new ObjectDisposedException(GetType().FullName);
195+
get => Delegate.KnownHosts;
196+
set => Delegate.KnownHosts = value;
195197
}
196198

197-
public int LocalPort => !_disposed ? _delegate.LocalPort : throw new ObjectDisposedException(GetType().FullName);
199+
public int LocalPort => Delegate.LocalPort;
198200

199-
public ProtocolBase Protocol => !_disposed ? _delegate.Protocol : throw new ObjectDisposedException(GetType().FullName);
201+
public ProtocolBase Protocol => Delegate.Protocol;
200202

201203
public IDictionary<string, RecordedExchange> RecordedExchanges { get; } = new ConcurrentDictionary<string, RecordedExchange>();
202204

203205
public IDictionary<string, RecordedQueue> RecordedQueues { get; } = new ConcurrentDictionary<string, RecordedQueue>();
204206

205-
public int RemotePort => !_disposed ? _delegate.RemotePort : throw new ObjectDisposedException(GetType().FullName);
207+
public int RemotePort => Delegate.RemotePort;
206208

207-
public IDictionary<string, object> ServerProperties => !_disposed ? _delegate.ServerProperties : throw new ObjectDisposedException(GetType().FullName);
209+
public IDictionary<string, object> ServerProperties => Delegate.ServerProperties;
208210

209-
public IList<ShutdownReportEntry> ShutdownReport => !_disposed ? _delegate.ShutdownReport : throw new ObjectDisposedException(GetType().FullName);
211+
public IList<ShutdownReportEntry> ShutdownReport => Delegate.ShutdownReport;
210212

211213
IProtocol IConnection.Protocol => Endpoint.Protocol;
212214

@@ -247,18 +249,12 @@ private bool TryPerformAutomaticRecovery()
247249
return false;
248250
}
249251

250-
public void Close(ShutdownEventArgs reason)
251-
{
252-
ThrowIfDisposed();
253-
_delegate.Close(reason);
254-
}
252+
public void Close(ShutdownEventArgs reason) => Delegate.Close(reason);
255253

256254
public RecoveryAwareModel CreateNonRecoveringModel()
257255
{
258-
ThrowIfDisposed();
259-
ISession session = _delegate.CreateSession();
260-
var result = new RecoveryAwareModel(session);
261-
result.ContinuationTimeout = _factory.ContinuationTimeout;
256+
ISession session = Delegate.CreateSession();
257+
var result = new RecoveryAwareModel(session) { ContinuationTimeout = _factory.ContinuationTimeout };
262258
result._Private_ChannelOpen("");
263259
return result;
264260
}
@@ -403,9 +399,7 @@ public void RecordQueue(string name, RecordedQueue q)
403399
}
404400
}
405401

406-
public override string ToString() => !_disposed
407-
? $"AutorecoveringConnection({_delegate.Id},{Endpoint},{GetHashCode()})"
408-
: throw new ObjectDisposedException(GetType().FullName);
402+
public override string ToString() => $"AutorecoveringConnection({Delegate.Id},{Endpoint},{GetHashCode()})";
409403

410404
public void UnregisterModel(AutorecoveringModel model)
411405
{
@@ -415,10 +409,7 @@ public void UnregisterModel(AutorecoveringModel model)
415409
}
416410
}
417411

418-
public void Init()
419-
{
420-
Init(_factory.EndpointResolverFactory(new List<AmqpTcpEndpoint> { _factory.Endpoint }));
421-
}
412+
public void Init() => Init(_factory.EndpointResolverFactory(new List<AmqpTcpEndpoint> { _factory.Endpoint }));
422413

423414
public void Init(IEndpointResolver endpoints)
424415
{
@@ -559,22 +550,11 @@ public IModel CreateModel()
559550
return m;
560551
}
561552

562-
void IDisposable.Dispose()
563-
{
564-
Dispose(true);
565-
}
553+
void IDisposable.Dispose() => Dispose(true);
566554

567-
public void HandleConnectionBlocked(string reason)
568-
{
569-
ThrowIfDisposed();
570-
_delegate.HandleConnectionBlocked(reason);
571-
}
555+
public void HandleConnectionBlocked(string reason) => Delegate.HandleConnectionBlocked(reason);
572556

573-
public void HandleConnectionUnblocked()
574-
{
575-
ThrowIfDisposed();
576-
_delegate.HandleConnectionUnblocked();
577-
}
557+
public void HandleConnectionUnblocked() => Delegate.HandleConnectionUnblocked();
578558

579559
internal int RecordedExchangesCount
580560
{
@@ -628,16 +608,9 @@ private void Dispose(bool disposing)
628608
}
629609
}
630610

631-
private void EnsureIsOpen()
632-
{
633-
ThrowIfDisposed();
634-
_delegate.EnsureIsOpen();
635-
}
611+
private void EnsureIsOpen() => Delegate.EnsureIsOpen();
636612

637-
private void HandleTopologyRecoveryException(TopologyRecoveryException e)
638-
{
639-
ESLog.Error("Topology recovery exception", e);
640-
}
613+
private void HandleTopologyRecoveryException(TopologyRecoveryException e) => ESLog.Error("Topology recovery exception", e);
641614

642615
private void PropagateQueueNameChangeToBindings(string oldName, string newName)
643616
{
@@ -730,17 +703,9 @@ private bool TryRecoverConnectionDelegate()
730703
return false;
731704
}
732705

733-
private void RecoverConnectionShutdownHandlers()
734-
{
735-
ThrowIfDisposed();
736-
_delegate.ConnectionShutdown += _recordedShutdownEventHandlers;
737-
}
706+
private void RecoverConnectionShutdownHandlers() => Delegate.ConnectionShutdown += _recordedShutdownEventHandlers;
738707

739-
private void RecoverConnectionUnblockedHandlers()
740-
{
741-
ThrowIfDisposed();
742-
_delegate.ConnectionUnblocked += _recordedUnblockedEventHandlers;
743-
}
708+
private void RecoverConnectionUnblockedHandlers() => Delegate.ConnectionUnblocked += _recordedUnblockedEventHandlers;
744709

745710
private void RecoverConsumers()
746711
{
@@ -914,13 +879,10 @@ private void RunRecoveryEventHandlers()
914879
}
915880
}
916881

917-
private bool ShouldTriggerConnectionRecovery(ShutdownEventArgs args)
918-
{
919-
return args.Initiator == ShutdownInitiator.Peer ||
882+
private bool ShouldTriggerConnectionRecovery(ShutdownEventArgs args) => args.Initiator == ShutdownInitiator.Peer ||
920883
// happens when EOF is reached, e.g. due to RabbitMQ node
921884
// connectivity loss or abrupt shutdown
922885
args.Initiator == ShutdownInitiator.Library;
923-
}
924886

925887
private enum RecoveryCommand
926888
{
@@ -1056,12 +1018,9 @@ private void RecoveryLoopConnectedHandler(RecoveryCommand command)
10561018
/// <summary>
10571019
/// Schedule a background Task to signal the command queue when the retry duration has elapsed.
10581020
/// </summary>
1059-
private void ScheduleRecoveryRetry()
1060-
{
1061-
_ = Task
1021+
private void ScheduleRecoveryRetry() => _ = Task
10621022
.Delay(_factory.NetworkRecoveryInterval)
10631023
.ContinueWith(t => _recoveryLoopCommandQueue.Writer.TryWrite(RecoveryCommand.PerformAutomaticRecovery));
1064-
}
10651024

10661025
[MethodImpl(MethodImplOptions.AggressiveInlining)]
10671026
private void ThrowIfDisposed()

0 commit comments

Comments
 (0)