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(); }
@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)); }
/** * 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); }
public ServerSettings settings() { return settings; }