Java 类com.mongodb.connection.ServerSettings 实例源码

项目:vertx-mongo-client    文件:ServerSettingsParser.java   
public ServerSettingsParser(JsonObject config) {
  ServerSettings.Builder settings = ServerSettings.builder();

  Long heartbeatFrequencyMS = config.getLong("heartbeatFrequencyMS");
  if (heartbeatFrequencyMS != null) {
    settings.heartbeatFrequency(heartbeatFrequencyMS, MILLISECONDS);
  }
  Long minHeartbeatFrequencyMS = config.getLong("minHeartbeatFrequencyMS");
  if (minHeartbeatFrequencyMS != null) {
    settings.minHeartbeatFrequency(minHeartbeatFrequencyMS, MILLISECONDS);
  }

  this.settings = settings.build();
}
项目:vertx-mongo-client    文件:ServerSettingsParserTest.java   
@Test
public void testServerSettings() {
  long heartbeatFrequencyMS = 1234;
  long minHeartbeatFrequencyMS = heartbeatFrequencyMS / 2;
  JsonObject config = new JsonObject();
  config.put("heartbeatFrequencyMS", heartbeatFrequencyMS);
  config.put("minHeartbeatFrequencyMS", minHeartbeatFrequencyMS);

  ServerSettings settings = new ServerSettingsParser(config).settings();
  assertEquals(heartbeatFrequencyMS, settings.getHeartbeatFrequency(TimeUnit.MILLISECONDS));
  assertEquals(minHeartbeatFrequencyMS, settings.getMinHeartbeatFrequency(TimeUnit.MILLISECONDS));
}
项目:dragoman    文件:MongoProviderImpl.java   
/**
 * Lazily instantiate the {@link MongoClient} instance.
 *
 * @return
 */
private MongoClient createMongoClient() {
  String host = applicationConfiguration.getMongoHost();
  int port = applicationConfiguration.getMongoPort();
  ConnectionString connectionString = new ConnectionString("mongodb://" + host + ":" + port);

  logger.info("Creating Mongo client for: {}:{}", host, port);

  MongoClientSettings mongoClientSettings =
      MongoClientSettings.builder()
          .applicationName("dragoman")
          .serverSettings(
              ServerSettings.builder()
                  .applyConnectionString(connectionString)
                  .addServerMonitorListener(new LoggingServerMonitorListener())
                  .addServerListener(new LoggingServerListener())
                  .build())
          .clusterSettings(
              ClusterSettings.builder()
                  .applyConnectionString(connectionString)
                  .serverSelectionTimeout(
                      applicationConfiguration.getMongoServerSelectionTimeout(), MILLISECONDS)
                  .addClusterListener(new LoggingClusterListener())
                  .build())
          .connectionPoolSettings(
              ConnectionPoolSettings.builder()
                  .applyConnectionString(connectionString)
                  .maxWaitTime(
                      applicationConfiguration.getConnectionPoolMaxWaitTime(), MILLISECONDS)
                  .minSize(applicationConfiguration.getConnectionPoolMinSize())
                  .maxSize(applicationConfiguration.getConnectionPoolMaxSize())
                  .addConnectionPoolListener(new LoggingConnectionPoolListener())
                  .build())
          .socketSettings(
              SocketSettings.builder()
                  .applyConnectionString(connectionString)
                  .connectTimeout(
                      applicationConfiguration.getMongoSocketConnectionTimeout(), MILLISECONDS)
                  .readTimeout(applicationConfiguration.getMongoReadTimeout(), MILLISECONDS)
                  .build())
          .build();

  return MongoClients.create(mongoClientSettings);
}
项目:vertx-mongo-client    文件:ServerSettingsParser.java   
public ServerSettings settings() {
  return settings;
}