@@ -226,13 +226,18 @@ public void close() {
226226 }
227227
228228 void init () {
229- if (this .state () != OPEN ) {
229+ String cName = this .connection .name ();
230+ LOGGER .debug ("Trying to initialize management for connection {}" , cName );
231+ State state = this .state ();
232+ if (state != OPEN ) {
230233 if (!this .initializing ) {
231234 try {
232235 initializationLock .lock ();
233- if (!this .initializing && this .state () != OPEN ) {
236+ boolean initInProgress = this .initializing ;
237+ state = this .state ();
238+ if (!initInProgress && state != OPEN ) {
234239 this .initializing = true ;
235- LOGGER .debug ("Initializing management ({})." , this );
240+ LOGGER .debug ("Initializing management for connection {} ({})." , cName , this );
236241 this .markUnavailable ();
237242 try {
238243 if (this .receiveLoop != null ) {
@@ -267,15 +272,27 @@ void init() {
267272 this .receiver .openFuture ().get (this .rpcTimeout .toMillis (), MILLISECONDS );
268273 LOGGER .debug ("Management receiver created ({})." , this );
269274 this .state (OPEN );
270- this .initializing = false ;
271275 } catch (Exception e ) {
276+ LOGGER .info ("Error during management {} initialization: {}" , cName , e .getMessage ());
272277 throw new AmqpException (e );
278+ } finally {
279+ this .initializing = false ;
273280 }
281+ } else {
282+ LOGGER .debug (
283+ "Not initializing management {}: init in progress {}, state {}" ,
284+ cName ,
285+ initInProgress ,
286+ state );
274287 }
275288 } finally {
276289 initializationLock .unlock ();
277290 }
291+ } else {
292+ LOGGER .debug ("Not initializing management {} because it is already initializing" , cName );
278293 }
294+ } else {
295+ LOGGER .debug ("Not initializing management {} because state is {}" , cName , state );
279296 }
280297 }
281298
0 commit comments