@@ -59,10 +59,10 @@ public class AutorecoveringConnection implements Connection, Recoverable, Networ
5959 // Records topology changes
6060 private final Map <String , RecordedQueue > recordedQueues = new ConcurrentHashMap <String , RecordedQueue >();
6161 private final List <RecordedBinding > recordedBindings = new ArrayList <RecordedBinding >();
62- private Map <String , RecordedExchange > recordedExchanges = new ConcurrentHashMap <String , RecordedExchange >();
62+ private final Map <String , RecordedExchange > recordedExchanges = new ConcurrentHashMap <String , RecordedExchange >();
6363 private final Map <String , RecordedConsumer > consumers = new ConcurrentHashMap <String , RecordedConsumer >();
64- private List <ConsumerRecoveryListener > consumerRecoveryListeners = new ArrayList <ConsumerRecoveryListener >();
65- private List <QueueRecoveryListener > queueRecoveryListeners = new ArrayList <QueueRecoveryListener >();
64+ private final List <ConsumerRecoveryListener > consumerRecoveryListeners = new ArrayList <ConsumerRecoveryListener >();
65+ private final List <QueueRecoveryListener > queueRecoveryListeners = new ArrayList <QueueRecoveryListener >();
6666
6767 public AutorecoveringConnection (ConnectionParams params , FrameHandlerFactory f , Address [] addrs ) {
6868 this .cf = new RecoveryAwareAMQConnectionFactory (params , f , addrs );
@@ -651,12 +651,36 @@ void maybeDeleteRecordedAutoDeleteQueue(String queue) {
651651 RecordedQueue q = this .recordedQueues .get (queue );
652652 // last consumer on this connection is gone, remove recorded queue
653653 // if it is auto-deleted. See bug 26364.
654- if (q .isAutoDelete ()) { this .recordedQueues .remove (queue ); }
654+ if (( q != null ) && q .isAutoDelete ()) { this .recordedQueues .remove (queue ); }
655655 }
656656 }
657657 }
658658 }
659659
660+ void maybeDeleteRecordedAutoDeleteExchange (String exchange ) {
661+ synchronized (this .recordedExchanges ) {
662+ synchronized (this .consumers ) {
663+ if (!hasMoreDestinationsBoundToExchange (this .recordedBindings , exchange )) {
664+ RecordedExchange x = this .recordedExchanges .get (exchange );
665+ // last binding where this exchange is the source is gone, remove recorded exchange
666+ // if it is auto-deleted. See bug 26364.
667+ if ((x != null ) && x .isAutoDelete ()) { this .recordedExchanges .remove (exchange ); }
668+ }
669+ }
670+ }
671+ }
672+
673+ boolean hasMoreDestinationsBoundToExchange (List <RecordedBinding > bindings , String exchange ) {
674+ boolean result = false ;
675+ for (RecordedBinding b : bindings ) {
676+ if (exchange .equals (b .getSource ())) {
677+ result = true ;
678+ break ;
679+ }
680+ }
681+ return result ;
682+ }
683+
660684 boolean hasMoreConsumersOnQueue (Collection <RecordedConsumer > consumers , String queue ) {
661685 boolean result = false ;
662686 for (RecordedConsumer c : consumers ) {
@@ -671,4 +695,8 @@ boolean hasMoreConsumersOnQueue(Collection<RecordedConsumer> consumers, String q
671695 public Map <String , RecordedQueue > getRecordedQueues () {
672696 return recordedQueues ;
673697 }
698+
699+ public Map <String , RecordedExchange > getRecordedExchanges () {
700+ return recordedExchanges ;
701+ }
674702}
0 commit comments