Code example for Cache

Methods: getIfPresentputsize

0
  public synchronized static MongoClient getClient( 
      List<ServerAddress> addresses, MongoClientOptions clientOptions)
      throws UnknownHostException {
    // Take the first replica from the replicated servers 
    ServerAddress serverAddress = addresses.get(0);
    MongoClient client = addressClientMap.getIfPresent(serverAddress);
    if (client == null) {
      client = new MongoClient(addresses, clientOptions);
      addressClientMap.put(serverAddress, client);
      logger.debug("Created connection to {}.", serverAddress.toString());
      logger.debug("Number of connections opened are {}.", 
          addressClientMap.size());
    } 
    return client;
  } 
}