private MongoClient onSetMongoServerProperties ( String contactNode , String defaultPort , String poolSize , List < ServerAddress > addrs , List < MongoCredential > credentials ) { MongoClientOptions mo ; MongoDBSchemaMetadata metadata = MongoDBPropertyReader . msmd ; ClientProperties cp = metadata != null ? metadata . getClientProperties ( ) : null ; Properties propsFromCp = null ; if ( cp != null ) { DataStore dataStore = metadata != null ? metadata . getDataStore ( ) : null ; List < Server > servers = dataStore != null && dataStore . getConnection ( ) != null ? dataStore . getConnection ( ) . getServers ( ) : null ; if ( servers != null && ! servers . isEmpty ( ) ) { for ( Server server : servers ) { addrs . add ( new ServerAddress ( server . getHost ( ) . trim ( ) , Integer . parseInt ( server . getPort ( ) . trim ( ) ) ) ) ; } } propsFromCp = dataStore != null && dataStore . getConnection ( ) != null ? dataStore . getConnection ( ) . getProperties ( ) : null ; } else { for ( String node : contactNode . split ( Constants . COMMA ) ) { if ( StringUtils . countMatches ( node , Constants . COLON ) == 1 ) { // node is given with hostname and port // count == 1 is to exclude IPv6 addresses String host = node . split ( ":" ) [ 0 ] ; int port = Integer . parseInt ( node . split ( Constants . COLON ) [ 1 ] ) ; addrs . add ( new ServerAddress ( host . trim ( ) , port ) ) ; } else { addrs . add ( new ServerAddress ( node . trim ( ) , Integer . parseInt ( defaultPort . trim ( ) ) ) ) ; } } } MongoClientOptions . Builder b = new PopulateMongoOptions ( propsFromCp , externalProperties ) . prepareBuilder ( ) ; mo = b . build ( ) ; if ( mo . getConnectionsPerHost ( ) <= 0 && ! StringUtils . isEmpty ( poolSize ) ) { mo = b . connectionsPerHost ( Integer . parseInt ( poolSize ) ) . build ( ) ; } return new MongoClient ( addrs , credentials , mo ) ; }
On set mongo server properties .