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
@@ -71,19 +71,20 @@ public class AutorecoveringConnection : IConnection, IRecoverable
71
71
72
72
protected List < AutorecoveringModel > m_models = new List < AutorecoveringModel > ( ) ;
73
73
74
- protected HashSet < RecordedBinding > m_recordedBindings = new HashSet < RecordedBinding > ( ) ;
74
+ protected IDictionary < RecordedBinding , byte > m_recordedBindings =
75
+ new ConcurrentDictionary < RecordedBinding , byte > ( ) ;
75
76
76
77
protected List < EventHandler < ConnectionBlockedEventArgs > > m_recordedBlockedEventHandlers =
77
78
new List < EventHandler < ConnectionBlockedEventArgs > > ( ) ;
78
79
79
80
protected IDictionary < string , RecordedConsumer > m_recordedConsumers =
80
- new Dictionary < string , RecordedConsumer > ( ) ;
81
+ new ConcurrentDictionary < string , RecordedConsumer > ( ) ;
81
82
82
83
protected IDictionary < string , RecordedExchange > m_recordedExchanges =
83
- new Dictionary < string , RecordedExchange > ( ) ;
84
+ new ConcurrentDictionary < string , RecordedExchange > ( ) ;
84
85
85
86
protected IDictionary < string , RecordedQueue > m_recordedQueues =
86
- new Dictionary < string , RecordedQueue > ( ) ;
87
+ new ConcurrentDictionary < string , RecordedQueue > ( ) ;
87
88
88
89
protected List < EventHandler < ShutdownEventArgs > > m_recordedShutdownEventHandlers =
89
90
new List < EventHandler < ShutdownEventArgs > > ( ) ;
@@ -396,7 +397,7 @@ public void DeleteRecordedBinding(RecordedBinding rb)
396
397
{
397
398
lock ( m_recordedEntitiesLock )
398
399
{
399
- m_recordedBindings . RemoveWhere ( b => b . Equals ( rb ) ) ;
400
+ m_recordedBindings . Remove ( rb ) ;
400
401
}
401
402
}
402
403
@@ -423,11 +424,10 @@ public void DeleteRecordedExchange(string name)
423
424
424
425
// find bindings that need removal, check if some auto-delete exchanges
425
426
// might need the same
426
- List < RecordedBinding > bs = m_recordedBindings . Where ( b => name . Equals ( b . Destination ) ) .
427
- ToList ( ) ;
428
- m_recordedBindings . RemoveWhere ( b => name . Equals ( b . Destination ) ) ;
427
+ var bs = m_recordedBindings . Keys . Where ( b => name . Equals ( b . Destination ) ) ;
429
428
foreach ( RecordedBinding b in bs )
430
429
{
430
+ m_recordedBindings . Remove ( b ) ;
431
431
MaybeDeleteRecordedAutoDeleteExchange ( b . Source ) ;
432
432
}
433
433
}
@@ -440,11 +440,10 @@ public void DeleteRecordedQueue(string name)
440
440
m_recordedQueues . Remove ( name ) ;
441
441
// find bindings that need removal, check if some auto-delete exchanges
442
442
// might need the same
443
- List < RecordedBinding > bs = m_recordedBindings . Where ( b => name . Equals ( b . Destination ) ) .
444
- ToList ( ) ;
445
- m_recordedBindings . RemoveWhere ( b => name . Equals ( b . Destination ) ) ;
443
+ var bs = m_recordedBindings . Keys . Where ( b => name . Equals ( b . Destination ) ) ;
446
444
foreach ( RecordedBinding b in bs )
447
445
{
446
+ m_recordedBindings . Remove ( b ) ;
448
447
MaybeDeleteRecordedAutoDeleteExchange ( b . Source ) ;
449
448
}
450
449
}
@@ -466,7 +465,7 @@ public void MaybeDeleteRecordedAutoDeleteExchange(string exchange)
466
465
{
467
466
lock ( m_recordedEntitiesLock )
468
467
{
469
- if ( ! HasMoreDestinationsBoundToExchange ( m_recordedBindings , exchange ) )
468
+ if ( ! HasMoreDestinationsBoundToExchange ( m_recordedBindings . Keys , exchange ) )
470
469
{
471
470
RecordedExchange rx ;
472
471
m_recordedExchanges . TryGetValue ( exchange , out rx ) ;
@@ -503,7 +502,7 @@ public void RecordBinding(RecordedBinding rb)
503
502
{
504
503
lock ( m_recordedEntitiesLock )
505
504
{
506
- m_recordedBindings . Add ( rb ) ;
505
+ m_recordedBindings . Add ( rb , 0 ) ;
507
506
}
508
507
}
509
508
@@ -719,8 +718,7 @@ protected void PropagateQueueNameChangeToBindings(string oldName, string newName
719
718
{
720
719
lock ( m_recordedBindings )
721
720
{
722
- IEnumerable < RecordedBinding > bs = m_recordedBindings .
723
- Where ( b => b . Destination . Equals ( oldName ) ) ;
721
+ var bs = m_recordedBindings . Keys . Where ( b => b . Destination . Equals ( oldName ) ) ;
724
722
foreach ( RecordedBinding b in bs )
725
723
{
726
724
b . Destination = newName ;
@@ -743,7 +741,7 @@ protected void PropagateQueueNameChangeToConsumers(string oldName, string newNam
743
741
744
742
protected void RecoverBindings ( )
745
743
{
746
- foreach ( RecordedBinding b in m_recordedBindings )
744
+ foreach ( var b in m_recordedBindings . Keys )
747
745
{
748
746
try
749
747
{
@@ -815,8 +813,7 @@ protected void RecoverConnectionUnblockedHandlers()
815
813
816
814
protected void RecoverConsumers ( )
817
815
{
818
- var dict = new Dictionary < string , RecordedConsumer > ( m_recordedConsumers ) ;
819
- foreach ( KeyValuePair < string , RecordedConsumer > pair in dict )
816
+ foreach ( KeyValuePair < string , RecordedConsumer > pair in m_recordedConsumers )
820
817
{
821
818
string tag = pair . Key ;
822
819
RecordedConsumer cons = pair . Value ;
@@ -903,8 +900,7 @@ protected void RecoverQueues()
903
900
{
904
901
lock ( m_recordedQueues )
905
902
{
906
- var rqs = new Dictionary < string , RecordedQueue > ( m_recordedQueues ) ;
907
- foreach ( KeyValuePair < string , RecordedQueue > pair in rqs )
903
+ foreach ( KeyValuePair < string , RecordedQueue > pair in m_recordedQueues )
908
904
{
909
905
string oldName = pair . Key ;
910
906
RecordedQueue rq = pair . Value ;
0 commit comments