@@ -478,25 +478,30 @@ public UsageTrackingInternalConnection create() {
478478
479479 @ Override
480480 public void close (final UsageTrackingInternalConnection connection ) {
481+ if (!closed ) {
482+ connectionPoolListener .connectionRemoved (new ConnectionEvent (getId (connection )));
483+ }
484+ if (LOGGER .isInfoEnabled ()) {
485+ LOGGER .info (format ("Closed connection [%s] to %s because %s." , getId (connection ), serverId .getAddress (),
486+ getReasonForClosing (connection )));
487+ }
488+ connection .close ();
489+ }
490+
491+ private String getReasonForClosing (final UsageTrackingInternalConnection connection ) {
481492 String reason ;
482- if (fromPreviousGeneration (connection )) {
493+ if (connection .isClosed ()) {
494+ reason = "there was a socket exception raised by this connection" ;
495+ } else if (fromPreviousGeneration (connection )) {
483496 reason = "there was a socket exception raised on another connection from this pool" ;
484497 } else if (pastMaxLifeTime (connection )) {
485498 reason = "it is past its maximum allowed life time" ;
486499 } else if (pastMaxIdleTime (connection )) {
487500 reason = "it is past its maximum allowed idle time" ;
488- } else if (connection .isClosed ()) {
489- reason = "the underlying connection was closed" ;
490501 } else {
491502 reason = "the pool has been closed" ;
492503 }
493- if (!closed ) {
494- connectionPoolListener .connectionRemoved (new ConnectionEvent (getId (connection )));
495- }
496- if (LOGGER .isInfoEnabled ()) {
497- LOGGER .info (format ("Closed connection [%s] to %s because %s." , getId (connection ), serverId .getAddress (), reason ));
498- }
499- connection .close ();
504+ return reason ;
500505 }
501506
502507 @ Override
0 commit comments