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

项目:vertx-mongo-client    文件:SocketSettingsParserTest.java   
@Test
public void testSocketSettings() {
  int connectTimeoutMS = Math.abs(TestUtils.randomInt());
  int socketTimeoutMS = Math.abs(TestUtils.randomInt());
  boolean keepAlive = TestUtils.randomBoolean();
  int receiveBufferSize = Math.abs(TestUtils.randomInt());
  int sendBufferSize = Math.abs(TestUtils.randomInt());

  JsonObject config = new JsonObject();
  config.put("connectTimeoutMS", connectTimeoutMS);
  config.put("socketTimeoutMS", socketTimeoutMS);
  config.put("keepAlive", keepAlive);
  config.put("receiveBufferSize", receiveBufferSize);
  config.put("sendBufferSize", sendBufferSize);

  SocketSettings settings = new SocketSettingsParser(null, config).settings();
  assertEquals(connectTimeoutMS, settings.getConnectTimeout(TimeUnit.MILLISECONDS));
  assertEquals(socketTimeoutMS, settings.getReadTimeout(TimeUnit.MILLISECONDS));
  assertEquals(keepAlive, settings.isKeepAlive());
  assertEquals(receiveBufferSize, settings.getReceiveBufferSize());
  assertEquals(sendBufferSize, settings.getSendBufferSize());
}
项目:vertx-mongo-client    文件:SocketSettingsParser.java   
public SocketSettingsParser(ConnectionString connectionString, JsonObject config) {
  SocketSettings.Builder settings = SocketSettings.builder();
  if (connectionString != null) {
    settings.applyConnectionString(connectionString);
  } else {
    Integer connectTimeoutMS = config.getInteger("connectTimeoutMS");
    if (connectTimeoutMS != null) {
      settings.connectTimeout(connectTimeoutMS, MILLISECONDS);
    }
    Integer socketTimeoutMS = config.getInteger("socketTimeoutMS");
    if (socketTimeoutMS != null) {
      settings.readTimeout(socketTimeoutMS, MILLISECONDS);
    }
    Boolean keepAlive = config.getBoolean("keepAlive");
    if (keepAlive != null) {
      settings.keepAlive(keepAlive);
    }
    Integer receiveBufferSize = config.getInteger("receiveBufferSize");
    if (receiveBufferSize != null) {
      settings.receiveBufferSize(receiveBufferSize);
    }
    Integer sendBufferSize = config.getInteger("sendBufferSize");
    if (sendBufferSize != null) {
      settings.sendBufferSize(sendBufferSize);
    }
  }

  this.settings = settings.build();
}
项目:jooby    文件:MongoRx.java   
static SocketSettings socket(final String path, final ConnectionString cstr,
    final Config dbconf) {
  SocketSettings.Builder settings = SocketSettings.builder().applyConnectionString(cstr);
  withConf(path, dbconf, c -> {
    withMs("connectTimeout", c,
        s -> settings.connectTimeout(s.intValue(), TimeUnit.MILLISECONDS));
    withBool("keepAlive", c, settings::keepAlive);
    withMs("readTimeout", c,
        s -> settings.readTimeout(s.intValue(), TimeUnit.MILLISECONDS));
    withInt("receiveBufferSize", c, settings::receiveBufferSize);
    withInt("sendBufferSize", c, settings::sendBufferSize);
  });
  return settings.build();
}
项目:jooby    文件:MongodbRxTest.java   
private Block socket(final String db) {
  return unit -> {
    SocketSettings settings = Try.apply(() -> unit.get(SocketSettings.class))
        .orElseGet(() -> unit.mock(SocketSettings.class));
    unit.registerMock(SocketSettings.class, settings);

    SocketSettings.Builder builder = Try.apply(() -> unit.get(SocketSettings.Builder.class))
        .orElseGet(() -> unit.mock(SocketSettings.Builder.class));
    expect(builder.applyConnectionString(new ConnectionString(db))).andReturn(builder).times(2);
    expect(builder.build()).andReturn(settings).times(2);

    expect(SocketSettings.builder()).andReturn(builder).times(2);
  };
}
项目: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    文件:SocketSettingsParser.java   
public SocketSettings settings() {
  return settings;
}