Skip to content

Commit fcaf87c

Browse files
committed
Add isMonitoringConnection boolean to InternalStreamConnection
This will let us ignore messages (for purposes of log message/event generation) for monitoring connections JAVA-4752 JAVA-4753
1 parent 4de305e commit fcaf87c

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

driver-core/src/main/com/mongodb/internal/connection/DefaultClusterableServerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public ClusterableServer create(final Cluster cluster, final ServerAddress serve
8080
SameObjectProvider<SdamServerDescriptionManager> sdamProvider = SameObjectProvider.uninitialized();
8181
ServerMonitor serverMonitor = new DefaultServerMonitor(serverId, serverSettings, cluster.getClock(),
8282
// no credentials, compressor list, or command listener for the server monitor factory
83-
new InternalStreamConnectionFactory(clusterMode, heartbeatStreamFactory, null, applicationName,
83+
new InternalStreamConnectionFactory(clusterMode, true, heartbeatStreamFactory, null, applicationName,
8484
mongoDriverInformation, emptyList(), null, serverApi),
8585
clusterMode, serverApi, sdamProvider);
8686
ConnectionPool connectionPool = new DefaultConnectionPool(serverId,

driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnection.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public class InternalStreamConnection implements InternalConnection {
108108
private static final Logger LOGGER = Loggers.getLogger("connection");
109109

110110
private final ClusterConnectionMode clusterConnectionMode;
111+
private final boolean isMonitoringConnection;
111112
private final ServerId serverId;
112113
private final ConnectionGenerationSupplier connectionGenerationSupplier;
113114
private final StreamFactory streamFactory;
@@ -139,10 +140,20 @@ static Set<String> getSecuritySensitiveHelloCommands() {
139140
}
140141

141142
public InternalStreamConnection(final ClusterConnectionMode clusterConnectionMode, final ServerId serverId,
143+
final ConnectionGenerationSupplier connectionGenerationSupplier,
144+
final StreamFactory streamFactory, final List<MongoCompressor> compressorList,
145+
final CommandListener commandListener, final InternalConnectionInitializer connectionInitializer) {
146+
this(clusterConnectionMode, false, serverId, connectionGenerationSupplier, streamFactory, compressorList, commandListener,
147+
connectionInitializer);
148+
}
149+
150+
public InternalStreamConnection(final ClusterConnectionMode clusterConnectionMode, final boolean isMonitoringConnection,
151+
final ServerId serverId,
142152
final ConnectionGenerationSupplier connectionGenerationSupplier,
143153
final StreamFactory streamFactory, final List<MongoCompressor> compressorList,
144154
final CommandListener commandListener, final InternalConnectionInitializer connectionInitializer) {
145155
this.clusterConnectionMode = clusterConnectionMode;
156+
this.isMonitoringConnection = isMonitoringConnection;
146157
this.serverId = notNull("serverId", serverId);
147158
this.connectionGenerationSupplier = notNull("connectionGeneration", connectionGenerationSupplier);
148159
this.streamFactory = notNull("streamFactory", streamFactory);

driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnectionFactory.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
class InternalStreamConnectionFactory implements InternalConnectionFactory {
3636
private final ClusterConnectionMode clusterConnectionMode;
37+
private final boolean isMonitoringConnection;
3738
private final StreamFactory streamFactory;
3839
private final BsonDocument clientMetadataDocument;
3940
private final List<MongoCompressor> compressorList;
@@ -42,12 +43,23 @@ class InternalStreamConnectionFactory implements InternalConnectionFactory {
4243
private final ServerApi serverApi;
4344
private final MongoCredentialWithCache credential;
4445

45-
InternalStreamConnectionFactory(final ClusterConnectionMode clusterConnectionMode, final StreamFactory streamFactory,
46+
InternalStreamConnectionFactory(final ClusterConnectionMode clusterConnectionMode,
47+
final StreamFactory streamFactory,
48+
@Nullable final MongoCredentialWithCache credential,
49+
@Nullable final String applicationName, final MongoDriverInformation mongoDriverInformation,
50+
final List<MongoCompressor> compressorList,
51+
@Nullable final CommandListener commandListener, @Nullable final ServerApi serverApi) {
52+
this(clusterConnectionMode, false, streamFactory, credential, applicationName, mongoDriverInformation, compressorList,
53+
commandListener, serverApi);
54+
}
55+
InternalStreamConnectionFactory(final ClusterConnectionMode clusterConnectionMode, final boolean isMonitoringConnection,
56+
final StreamFactory streamFactory,
4657
@Nullable final MongoCredentialWithCache credential,
4758
@Nullable final String applicationName, final MongoDriverInformation mongoDriverInformation,
4859
final List<MongoCompressor> compressorList,
4960
@Nullable final CommandListener commandListener, @Nullable final ServerApi serverApi) {
5061
this.clusterConnectionMode = clusterConnectionMode;
62+
this.isMonitoringConnection = isMonitoringConnection;
5163
this.streamFactory = notNull("streamFactory", streamFactory);
5264
this.compressorList = notNull("compressorList", compressorList);
5365
this.commandListener = commandListener;
@@ -59,9 +71,9 @@ class InternalStreamConnectionFactory implements InternalConnectionFactory {
5971
@Override
6072
public InternalConnection create(final ServerId serverId, final ConnectionGenerationSupplier connectionGenerationSupplier) {
6173
Authenticator authenticator = credential == null ? null : createAuthenticator(credential);
62-
return new InternalStreamConnection(clusterConnectionMode, serverId, connectionGenerationSupplier, streamFactory, compressorList,
63-
commandListener, new InternalStreamConnectionInitializer(clusterConnectionMode, authenticator, clientMetadataDocument,
64-
compressorList, serverApi));
74+
return new InternalStreamConnection(clusterConnectionMode, isMonitoringConnection, serverId, connectionGenerationSupplier,
75+
streamFactory, compressorList, commandListener, new InternalStreamConnectionInitializer(clusterConnectionMode,
76+
authenticator, clientMetadataDocument, compressorList, serverApi));
6577
}
6678

6779
private Authenticator createAuthenticator(final MongoCredentialWithCache credential) {

0 commit comments

Comments
 (0)