@@ -79,6 +79,8 @@ public AutorecoveringConnection(ConnectionFactory factory, string clientProvided
79
79
ClientProvidedName = clientProvidedName ;
80
80
}
81
81
82
+ private Connection Delegate => ! _disposed ? _delegate : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
83
+
82
84
public event EventHandler < EventArgs > RecoverySucceeded ;
83
85
public event EventHandler < ConnectionRecoveryErrorEventArgs > ConnectionRecoveryError ;
84
86
public event EventHandler < CallbackExceptionEventArgs > CallbackException
@@ -172,41 +174,41 @@ public event EventHandler<EventArgs> ConnectionUnblocked
172
174
173
175
public string ClientProvidedName { get ; }
174
176
175
- public ushort ChannelMax => ! _disposed ? _delegate . ChannelMax : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
177
+ public ushort ChannelMax => Delegate . ChannelMax ;
176
178
177
- public ConsumerWorkService ConsumerWorkService => ! _disposed ? _delegate . ConsumerWorkService : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
179
+ public ConsumerWorkService ConsumerWorkService => Delegate . ConsumerWorkService ;
178
180
179
- public IDictionary < string , object > ClientProperties => ! _disposed ? _delegate . ClientProperties : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
181
+ public IDictionary < string , object > ClientProperties => Delegate . ClientProperties ;
180
182
181
- public ShutdownEventArgs CloseReason => ! _disposed ? _delegate . CloseReason : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
183
+ public ShutdownEventArgs CloseReason => Delegate . CloseReason ;
182
184
183
- public AmqpTcpEndpoint Endpoint => ! _disposed ? _delegate . Endpoint : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
185
+ public AmqpTcpEndpoint Endpoint => Delegate . Endpoint ;
184
186
185
- public uint FrameMax => ! _disposed ? _delegate . FrameMax : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
187
+ public uint FrameMax => Delegate . FrameMax ;
186
188
187
- public TimeSpan Heartbeat => ! _disposed ? _delegate . Heartbeat : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
189
+ public TimeSpan Heartbeat => Delegate . Heartbeat ;
188
190
189
- public bool IsOpen => _delegate != null && _delegate . IsOpen ;
191
+ public bool IsOpen => _delegate ? . IsOpen ?? false ;
190
192
191
193
public AmqpTcpEndpoint [ ] KnownHosts
192
194
{
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 ;
195
197
}
196
198
197
- public int LocalPort => ! _disposed ? _delegate . LocalPort : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
199
+ public int LocalPort => Delegate . LocalPort ;
198
200
199
- public ProtocolBase Protocol => ! _disposed ? _delegate . Protocol : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
201
+ public ProtocolBase Protocol => Delegate . Protocol ;
200
202
201
203
public IDictionary < string , RecordedExchange > RecordedExchanges { get ; } = new ConcurrentDictionary < string , RecordedExchange > ( ) ;
202
204
203
205
public IDictionary < string , RecordedQueue > RecordedQueues { get ; } = new ConcurrentDictionary < string , RecordedQueue > ( ) ;
204
206
205
- public int RemotePort => ! _disposed ? _delegate . RemotePort : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
207
+ public int RemotePort => Delegate . RemotePort ;
206
208
207
- public IDictionary < string , object > ServerProperties => ! _disposed ? _delegate . ServerProperties : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
209
+ public IDictionary < string , object > ServerProperties => Delegate . ServerProperties ;
208
210
209
- public IList < ShutdownReportEntry > ShutdownReport => ! _disposed ? _delegate . ShutdownReport : throw new ObjectDisposedException ( GetType ( ) . FullName ) ;
211
+ public IList < ShutdownReportEntry > ShutdownReport => Delegate . ShutdownReport ;
210
212
211
213
IProtocol IConnection . Protocol => Endpoint . Protocol ;
212
214
@@ -247,18 +249,12 @@ private bool TryPerformAutomaticRecovery()
247
249
return false ;
248
250
}
249
251
250
- public void Close ( ShutdownEventArgs reason )
251
- {
252
- ThrowIfDisposed ( ) ;
253
- _delegate . Close ( reason ) ;
254
- }
252
+ public void Close ( ShutdownEventArgs reason ) => Delegate . Close ( reason ) ;
255
253
256
254
public RecoveryAwareModel CreateNonRecoveringModel ( )
257
255
{
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 } ;
262
258
result . _Private_ChannelOpen ( "" ) ;
263
259
return result ;
264
260
}
@@ -403,9 +399,7 @@ public void RecordQueue(string name, RecordedQueue q)
403
399
}
404
400
}
405
401
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 ( ) } )";
409
403
410
404
public void UnregisterModel ( AutorecoveringModel model )
411
405
{
@@ -415,10 +409,7 @@ public void UnregisterModel(AutorecoveringModel model)
415
409
}
416
410
}
417
411
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 } ) ) ;
422
413
423
414
public void Init ( IEndpointResolver endpoints )
424
415
{
@@ -559,22 +550,11 @@ public IModel CreateModel()
559
550
return m ;
560
551
}
561
552
562
- void IDisposable . Dispose ( )
563
- {
564
- Dispose ( true ) ;
565
- }
553
+ void IDisposable . Dispose ( ) => Dispose ( true ) ;
566
554
567
- public void HandleConnectionBlocked ( string reason )
568
- {
569
- ThrowIfDisposed ( ) ;
570
- _delegate . HandleConnectionBlocked ( reason ) ;
571
- }
555
+ public void HandleConnectionBlocked ( string reason ) => Delegate . HandleConnectionBlocked ( reason ) ;
572
556
573
- public void HandleConnectionUnblocked ( )
574
- {
575
- ThrowIfDisposed ( ) ;
576
- _delegate . HandleConnectionUnblocked ( ) ;
577
- }
557
+ public void HandleConnectionUnblocked ( ) => Delegate . HandleConnectionUnblocked ( ) ;
578
558
579
559
internal int RecordedExchangesCount
580
560
{
@@ -628,16 +608,9 @@ private void Dispose(bool disposing)
628
608
}
629
609
}
630
610
631
- private void EnsureIsOpen ( )
632
- {
633
- ThrowIfDisposed ( ) ;
634
- _delegate . EnsureIsOpen ( ) ;
635
- }
611
+ private void EnsureIsOpen ( ) => Delegate . EnsureIsOpen ( ) ;
636
612
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 ) ;
641
614
642
615
private void PropagateQueueNameChangeToBindings ( string oldName , string newName )
643
616
{
@@ -730,17 +703,9 @@ private bool TryRecoverConnectionDelegate()
730
703
return false ;
731
704
}
732
705
733
- private void RecoverConnectionShutdownHandlers ( )
734
- {
735
- ThrowIfDisposed ( ) ;
736
- _delegate . ConnectionShutdown += _recordedShutdownEventHandlers ;
737
- }
706
+ private void RecoverConnectionShutdownHandlers ( ) => Delegate . ConnectionShutdown += _recordedShutdownEventHandlers ;
738
707
739
- private void RecoverConnectionUnblockedHandlers ( )
740
- {
741
- ThrowIfDisposed ( ) ;
742
- _delegate . ConnectionUnblocked += _recordedUnblockedEventHandlers ;
743
- }
708
+ private void RecoverConnectionUnblockedHandlers ( ) => Delegate . ConnectionUnblocked += _recordedUnblockedEventHandlers ;
744
709
745
710
private void RecoverConsumers ( )
746
711
{
@@ -914,13 +879,10 @@ private void RunRecoveryEventHandlers()
914
879
}
915
880
}
916
881
917
- private bool ShouldTriggerConnectionRecovery ( ShutdownEventArgs args )
918
- {
919
- return args . Initiator == ShutdownInitiator . Peer ||
882
+ private bool ShouldTriggerConnectionRecovery ( ShutdownEventArgs args ) => args . Initiator == ShutdownInitiator . Peer ||
920
883
// happens when EOF is reached, e.g. due to RabbitMQ node
921
884
// connectivity loss or abrupt shutdown
922
885
args . Initiator == ShutdownInitiator . Library ;
923
- }
924
886
925
887
private enum RecoveryCommand
926
888
{
@@ -1056,12 +1018,9 @@ private void RecoveryLoopConnectedHandler(RecoveryCommand command)
1056
1018
/// <summary>
1057
1019
/// Schedule a background Task to signal the command queue when the retry duration has elapsed.
1058
1020
/// </summary>
1059
- private void ScheduleRecoveryRetry ( )
1060
- {
1061
- _ = Task
1021
+ private void ScheduleRecoveryRetry ( ) => _ = Task
1062
1022
. Delay ( _factory . NetworkRecoveryInterval )
1063
1023
. ContinueWith ( t => _recoveryLoopCommandQueue . Writer . TryWrite ( RecoveryCommand . PerformAutomaticRecovery ) ) ;
1064
- }
1065
1024
1066
1025
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1067
1026
private void ThrowIfDisposed ( )
0 commit comments