All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.ext.mongo.impl.config.ConnectionPoolSettingsParser Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR1
Show newest version
package io.vertx.ext.mongo.impl.config;

import com.mongodb.ConnectionString;
import com.mongodb.connection.ConnectionPoolSettings;
import io.vertx.core.json.JsonObject;

import static java.util.concurrent.TimeUnit.*;

/**
 * @author Nick Scavelli
 */
class ConnectionPoolSettingsParser {

  private final ConnectionPoolSettings settings;

  /*
  * The Default Mongo Driver maxWaitQueueSize @see maxWaitQueueSize
  */
  private final Integer DEFAULT_MONGO_DRIVER_WAIT_Q_SIZE = 500;

  public ConnectionPoolSettingsParser(ConnectionString connectionString, JsonObject config) {
    ConnectionPoolSettings.Builder settings = ConnectionPoolSettings.builder();
    if (connectionString != null) {
      settings.applyConnectionString(connectionString);
    } else {
      Integer maxPoolSize = config.getInteger("maxPoolSize");
      if (maxPoolSize != null) {
        settings.maxSize(maxPoolSize);
      }
      Integer minPoolSize = config.getInteger("minPoolSize");
      if (minPoolSize != null) {
        settings.minSize(minPoolSize);
      }
      Long maxIdleTimeMS = config.getLong("maxIdleTimeMS");
      if (maxIdleTimeMS != null) {
        settings.maxConnectionIdleTime(maxIdleTimeMS, MILLISECONDS);
      }
      Long maxLifeTimeMS = config.getLong("maxLifeTimeMS");
      if (maxLifeTimeMS != null) {
        settings.maxConnectionLifeTime(maxLifeTimeMS, MILLISECONDS);
      }
      Integer waitQueueMultiple = config.getInteger("waitQueueMultiple");
      if (waitQueueMultiple != null) {
	      Integer waitQueueSize = waitQueueMultiple * DEFAULT_MONGO_DRIVER_WAIT_Q_SIZE;
        settings.maxWaitQueueSize(waitQueueSize);
      }
      Long waitQueueTimeoutMS = config.getLong("waitQueueTimeoutMS");
      if (waitQueueTimeoutMS != null) {
        settings.maxWaitTime(waitQueueTimeoutMS, MILLISECONDS);
      }
      Long maintenanceInitialDelayMS = config.getLong("maintenanceInitialDelayMS");
      if (maintenanceInitialDelayMS != null) {
        settings.maintenanceInitialDelay(maintenanceInitialDelayMS, MILLISECONDS);
      }
      Long maintenanceFrequencyMS = config.getLong("maintenanceFrequencyMS");
      if (maintenanceFrequencyMS != null) {
        settings.maintenanceFrequency(maintenanceFrequencyMS, MILLISECONDS);
      }
    }

    this.settings = settings.build();
  }

  public ConnectionPoolSettings settings() {
    return settings;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy