@@ -41,7 +41,7 @@ class ServerMonitor {
4141
4242 private static final Logger LOGGER = Loggers .getLogger ("cluster" );
4343
44- private ServerAddress serverAddress ;
44+ private final ServerAddress serverAddress ;
4545 private final ChangeListener <ServerDescription > serverStateListener ;
4646 private final SocketSettings socketSettings ;
4747 private final ServerSettings settings ;
@@ -85,7 +85,7 @@ public void run() {
8585 Throwable previousException = currentException ;
8686 try {
8787 if (connection == null ) {
88- connection = new DBPort (serverAddress , getOptions ());
88+ connection = new DBPort (serverAddress , mongo , getOptions ());
8989 }
9090 try {
9191 currentServerDescription = lookupServerDescription (connection );
@@ -99,7 +99,7 @@ public void run() {
9999 connection = null ;
100100 connectionProvider .invalidate ();
101101 }
102- connection = new DBPort (serverAddress , getOptions ());
102+ connection = new DBPort (serverAddress , mongo , getOptions ());
103103 try {
104104 currentServerDescription = lookupServerDescription (connection );
105105 } catch (IOException e1 ) {
@@ -234,16 +234,15 @@ private ServerDescription lookupServerDescription(final DBPort connection) throw
234234 count ++;
235235 elapsedNanosSum += System .nanoTime () - startNanoTime ;
236236
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 );
239238 }
240239
241240 @ SuppressWarnings ("unchecked" )
242- private ServerDescription createDescription (final CommandResult commandResult , final CommandResult buildInfoResult ,
241+ private ServerDescription createDescription (final CommandResult commandResult , final ServerVersion serverVersion ,
243242 final long averageLatencyNanos ) {
244243 return ServerDescription .builder ()
245244 .state (ServerConnectionState .Connected )
246- .version (getVersion ( buildInfoResult ) )
245+ .version (serverVersion )
247246 .address (commandResult .getServerUsed ())
248247 .type (getServerType (commandResult ))
249248 .hosts (listToSet ((List <String >) commandResult .get ("hosts" )))
@@ -262,11 +261,6 @@ private ServerDescription createDescription(final CommandResult commandResult, f
262261 .ok (commandResult .ok ()).build ();
263262 }
264263
265- @ SuppressWarnings ("unchecked" )
266- static ServerVersion getVersion (final CommandResult buildInfoResult ) {
267- return new ServerVersion (((List <Integer >) buildInfoResult .get ("versionArray" )).subList (0 , 3 ));
268- }
269-
270264 private Set <String > listToSet (final List <String > list ) {
271265 if (list == null || list .isEmpty ()) {
272266 return Collections .emptySet ();
0 commit comments