43
43
using RabbitMQ . Client . Impl ;
44
44
using System ;
45
45
using System . Collections . Generic ;
46
+ using System . Collections . Concurrent ;
46
47
using System . Linq ;
47
- using System . Net ;
48
48
using System . Threading ;
49
49
using System . Threading . Tasks ;
50
50
@@ -73,19 +73,20 @@ public class AutorecoveringConnection : IConnection, IRecoverable
73
73
74
74
protected List < AutorecoveringModel > m_models = new List < AutorecoveringModel > ( ) ;
75
75
76
- protected HashSet < RecordedBinding > m_recordedBindings = new HashSet < RecordedBinding > ( ) ;
76
+ protected IDictionary < RecordedBinding , byte > m_recordedBindings =
77
+ new ConcurrentDictionary < RecordedBinding , byte > ( ) ;
77
78
78
79
protected List < EventHandler < ConnectionBlockedEventArgs > > m_recordedBlockedEventHandlers =
79
80
new List < EventHandler < ConnectionBlockedEventArgs > > ( ) ;
80
81
81
82
protected IDictionary < string , RecordedConsumer > m_recordedConsumers =
82
- new Dictionary < string , RecordedConsumer > ( ) ;
83
+ new ConcurrentDictionary < string , RecordedConsumer > ( ) ;
83
84
84
85
protected IDictionary < string , RecordedExchange > m_recordedExchanges =
85
- new Dictionary < string , RecordedExchange > ( ) ;
86
+ new ConcurrentDictionary < string , RecordedExchange > ( ) ;
86
87
87
88
protected IDictionary < string , RecordedQueue > m_recordedQueues =
88
- new Dictionary < string , RecordedQueue > ( ) ;
89
+ new ConcurrentDictionary < string , RecordedQueue > ( ) ;
89
90
90
91
protected List < EventHandler < ShutdownEventArgs > > m_recordedShutdownEventHandlers =
91
92
new List < EventHandler < ShutdownEventArgs > > ( ) ;
@@ -398,7 +399,7 @@ public void DeleteRecordedBinding(RecordedBinding rb)
398
399
{
399
400
lock ( m_recordedEntitiesLock )
400
401
{
401
- m_recordedBindings . RemoveWhere ( b => b . Equals ( rb ) ) ;
402
+ m_recordedBindings . Remove ( rb ) ;
402
403
}
403
404
}
404
405
@@ -425,11 +426,10 @@ public void DeleteRecordedExchange(string name)
425
426
426
427
// find bindings that need removal, check if some auto-delete exchanges
427
428
// might need the same
428
- List < RecordedBinding > bs = m_recordedBindings . Where ( b => name . Equals ( b . Destination ) ) .
429
- ToList ( ) ;
430
- m_recordedBindings . RemoveWhere ( b => name . Equals ( b . Destination ) ) ;
429
+ var bs = m_recordedBindings . Keys . Where ( b => name . Equals ( b . Destination ) ) ;
431
430
foreach ( RecordedBinding b in bs )
432
431
{
432
+ m_recordedBindings . Remove ( b ) ;
433
433
MaybeDeleteRecordedAutoDeleteExchange ( b . Source ) ;
434
434
}
435
435
}
@@ -442,11 +442,10 @@ public void DeleteRecordedQueue(string name)
442
442
m_recordedQueues . Remove ( name ) ;
443
443
// find bindings that need removal, check if some auto-delete exchanges
444
444
// might need the same
445
- List < RecordedBinding > bs = m_recordedBindings . Where ( b => name . Equals ( b . Destination ) ) .
446
- ToList ( ) ;
447
- m_recordedBindings . RemoveWhere ( b => name . Equals ( b . Destination ) ) ;
445
+ var bs = m_recordedBindings . Keys . Where ( b => name . Equals ( b . Destination ) ) ;
448
446
foreach ( RecordedBinding b in bs )
449
447
{
448
+ m_recordedBindings . Remove ( b ) ;
450
449
MaybeDeleteRecordedAutoDeleteExchange ( b . Source ) ;
451
450
}
452
451
}
@@ -468,7 +467,7 @@ public void MaybeDeleteRecordedAutoDeleteExchange(string exchange)
468
467
{
469
468
lock ( m_recordedEntitiesLock )
470
469
{
471
- if ( ! HasMoreDestinationsBoundToExchange ( m_recordedBindings , exchange ) )
470
+ if ( ! HasMoreDestinationsBoundToExchange ( m_recordedBindings . Keys , exchange ) )
472
471
{
473
472
RecordedExchange rx ;
474
473
m_recordedExchanges . TryGetValue ( exchange , out rx ) ;
@@ -505,7 +504,7 @@ public void RecordBinding(RecordedBinding rb)
505
504
{
506
505
lock ( m_recordedEntitiesLock )
507
506
{
508
- m_recordedBindings . Add ( rb ) ;
507
+ m_recordedBindings . Add ( rb , 0 ) ;
509
508
}
510
509
}
511
510
@@ -752,8 +751,7 @@ protected void PropagateQueueNameChangeToBindings(string oldName, string newName
752
751
{
753
752
lock ( m_recordedBindings )
754
753
{
755
- IEnumerable < RecordedBinding > bs = m_recordedBindings .
756
- Where ( b => b . Destination . Equals ( oldName ) ) ;
754
+ var bs = m_recordedBindings . Keys . Where ( b => b . Destination . Equals ( oldName ) ) ;
757
755
foreach ( RecordedBinding b in bs )
758
756
{
759
757
b . Destination = newName ;
@@ -776,7 +774,7 @@ protected void PropagateQueueNameChangeToConsumers(string oldName, string newNam
776
774
777
775
protected void RecoverBindings ( )
778
776
{
779
- foreach ( RecordedBinding b in m_recordedBindings )
777
+ foreach ( var b in m_recordedBindings . Keys )
780
778
{
781
779
try
782
780
{
@@ -850,8 +848,7 @@ protected void RecoverConnectionUnblockedHandlers()
850
848
851
849
protected void RecoverConsumers ( )
852
850
{
853
- var dict = new Dictionary < string , RecordedConsumer > ( m_recordedConsumers ) ;
854
- foreach ( KeyValuePair < string , RecordedConsumer > pair in dict )
851
+ foreach ( KeyValuePair < string , RecordedConsumer > pair in m_recordedConsumers )
855
852
{
856
853
string tag = pair . Key ;
857
854
RecordedConsumer cons = pair . Value ;
@@ -938,8 +935,7 @@ protected void RecoverQueues()
938
935
{
939
936
lock ( m_recordedQueues )
940
937
{
941
- var rqs = new Dictionary < string , RecordedQueue > ( m_recordedQueues ) ;
942
- foreach ( KeyValuePair < string , RecordedQueue > pair in rqs )
938
+ foreach ( KeyValuePair < string , RecordedQueue > pair in m_recordedQueues )
943
939
{
944
940
string oldName = pair . Key ;
945
941
RecordedQueue rq = pair . Value ;
0 commit comments