Skip to content

Commit

Permalink
logging connection pool events
Browse files Browse the repository at this point in the history
  • Loading branch information
petretiandrea committed Feb 26, 2024
1 parent e79fccd commit 3f09dac
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package it.gov.pagopa.rtd.ms.rtdmssenderauth;

import com.mongodb.event.ConnectionCheckOutFailedEvent;
import com.mongodb.event.ConnectionCheckOutStartedEvent;
import com.mongodb.event.ConnectionCheckedInEvent;
import com.mongodb.event.ConnectionCheckedOutEvent;
import com.mongodb.event.ConnectionClosedEvent;
import com.mongodb.event.ConnectionCreatedEvent;
import com.mongodb.event.ConnectionPoolClosedEvent;
import com.mongodb.event.ConnectionPoolCreatedEvent;
import com.mongodb.event.ConnectionPoolListener;
import com.mongodb.event.ServerHeartbeatFailedEvent;
import com.mongodb.event.ServerHeartbeatStartedEvent;
import com.mongodb.event.ServerHeartbeatSucceededEvent;
Expand Down Expand Up @@ -28,6 +37,7 @@ public MongoClientSettingsBuilderCustomizer mongoConnectionPoolConfiguration() {
pool.maxWaitTime(COSMOS_MONGO_MAX_WAIT_TIME, TimeUnit.MILLISECONDS);
pool.maxConnectionLifeTime(COSMOS_MONGO_MAX_LIFE_TIME_MS, TimeUnit.MILLISECONDS);
pool.maxConnectionIdleTime(COSMOS_MONGO_MAX_IDLE_TIME_MS, TimeUnit.MILLISECONDS);
pool.addConnectionPoolListener(new ConnectionPoolLogger());
})
.applyToSocketSettings(socket -> {
socket.readTimeout(COSMOS_MONGO_SOCKET_TIMEOUT_MS, TimeUnit.MILLISECONDS);
Expand All @@ -44,5 +54,56 @@ public void serverHeartbeatFailed(ServerHeartbeatFailedEvent event) {
log.info(event.toString());
}
}

@Slf4j
private static final class ConnectionPoolLogger implements ConnectionPoolListener {
@Override
public void connectionPoolCreated(ConnectionPoolCreatedEvent event) {
ConnectionPoolListener.super.connectionPoolCreated(event);
log.info(event.toString());
}

@Override
public void connectionPoolClosed(ConnectionPoolClosedEvent event) {
ConnectionPoolListener.super.connectionPoolClosed(event);
log.info(event.toString());
}

@Override
public void connectionCheckOutStarted(ConnectionCheckOutStartedEvent event) {
ConnectionPoolListener.super.connectionCheckOutStarted(event);
log.info(event.toString());
}

@Override
public void connectionCheckedOut(ConnectionCheckedOutEvent event) {
ConnectionPoolListener.super.connectionCheckedOut(event);
log.info(event.toString());
}

@Override
public void connectionCheckOutFailed(ConnectionCheckOutFailedEvent event) {
ConnectionPoolListener.super.connectionCheckOutFailed(event);
log.info(event.toString());
}

@Override
public void connectionCreated(ConnectionCreatedEvent event) {
ConnectionPoolListener.super.connectionCreated(event);
log.info(event.toString());
}

@Override
public void connectionClosed(ConnectionClosedEvent event) {
ConnectionPoolListener.super.connectionClosed(event);
log.info(event.toString());
}

@Override
public void connectionCheckedIn(ConnectionCheckedInEvent event) {
ConnectionPoolListener.super.connectionCheckedIn(event);
log.info(event.toString());
}
}
}

0 comments on commit 3f09dac

Please sign in to comment.