@@ -41,7 +41,7 @@ class ServerMonitor {
41
41
42
42
private static final Logger LOGGER = Loggers .getLogger ("cluster" );
43
43
44
- private ServerAddress serverAddress ;
44
+ private final ServerAddress serverAddress ;
45
45
private final ChangeListener <ServerDescription > serverStateListener ;
46
46
private final SocketSettings socketSettings ;
47
47
private final ServerSettings settings ;
@@ -85,7 +85,7 @@ public void run() {
85
85
Throwable previousException = currentException ;
86
86
try {
87
87
if (connection == null ) {
88
- connection = new DBPort (serverAddress , getOptions ());
88
+ connection = new DBPort (serverAddress , mongo , getOptions ());
89
89
}
90
90
try {
91
91
currentServerDescription = lookupServerDescription (connection );
@@ -99,7 +99,7 @@ public void run() {
99
99
connection = null ;
100
100
connectionProvider .invalidate ();
101
101
}
102
- connection = new DBPort (serverAddress , getOptions ());
102
+ connection = new DBPort (serverAddress , mongo , getOptions ());
103
103
try {
104
104
currentServerDescription = lookupServerDescription (connection );
105
105
} catch (IOException e1 ) {
@@ -234,16 +234,15 @@ private ServerDescription lookupServerDescription(final DBPort connection) throw
234
234
count ++;
235
235
elapsedNanosSum += System .nanoTime () - startNanoTime ;
236
236
237
- final CommandResult buildInfoResult = connection .runCommand (mongo .getDB ("admin" ), new BasicDBObject ("buildinfo" , 1 ));
238
- return createDescription (isMasterResult , buildInfoResult , elapsedNanosSum / count );
237
+ return createDescription (isMasterResult , connection .getServerVersion (), elapsedNanosSum / count );
239
238
}
240
239
241
240
@ SuppressWarnings ("unchecked" )
242
- private ServerDescription createDescription (final CommandResult commandResult , final CommandResult buildInfoResult ,
241
+ private ServerDescription createDescription (final CommandResult commandResult , final ServerVersion serverVersion ,
243
242
final long averageLatencyNanos ) {
244
243
return ServerDescription .builder ()
245
244
.state (ServerConnectionState .Connected )
246
- .version (getVersion ( buildInfoResult ) )
245
+ .version (serverVersion )
247
246
.address (commandResult .getServerUsed ())
248
247
.type (getServerType (commandResult ))
249
248
.hosts (listToSet ((List <String >) commandResult .get ("hosts" )))
@@ -262,11 +261,6 @@ private ServerDescription createDescription(final CommandResult commandResult, f
262
261
.ok (commandResult .ok ()).build ();
263
262
}
264
263
265
- @ SuppressWarnings ("unchecked" )
266
- static ServerVersion getVersion (final CommandResult buildInfoResult ) {
267
- return new ServerVersion (((List <Integer >) buildInfoResult .get ("versionArray" )).subList (0 , 3 ));
268
- }
269
-
270
264
private Set <String > listToSet (final List <String > list ) {
271
265
if (list == null || list .isEmpty ()) {
272
266
return Collections .emptySet ();
0 commit comments