/** * Creates a builder instance. * * @param clusterSettings existing ClusterSettings to default the builder settings on. * @return a builder * @since 3.5 */ public static Builder builder(final ClusterSettings clusterSettings) { return builder().applySettings(clusterSettings); }
private ClusterSettings getClusterSettings(final ClusterSettings settings, final ClusterListener clusterListener) { return ClusterSettings.builder(settings).addClusterListener(clusterListener).build(); }
static ClusterSettings cluster(final ConnectionString cstr, final Config conf) { ClusterSettings.Builder cluster = ClusterSettings.builder().applyConnectionString(cstr); withConf("cluster", conf, c -> { withInt("maxWaitQueueSize", c, cluster::maxWaitQueueSize); withStr("replicaSetName", c, cluster::requiredReplicaSetName); withStr("requiredClusterType", c, v -> cluster.requiredClusterType(ClusterType.valueOf(v.toUpperCase()))); withMs("serverSelectionTimeout", c, s -> cluster.serverSelectionTimeout(s, TimeUnit.MILLISECONDS)); }); return cluster.build(); }
private static ClusterSettings getClusterSettings(final List<ServerAddress> seedList, final MongoClientOptions options, final ClusterConnectionMode clusterConnectionMode) { ClusterSettings.Builder builder = ClusterSettings.builder() .hosts(new ArrayList<ServerAddress>(seedList)) .mode(clusterConnectionMode) .requiredReplicaSetName(options.getRequiredReplicaSetName()) .serverSelectionTimeout(options.getServerSelectionTimeout(), MILLISECONDS) .localThreshold(options.getLocalThreshold(), MILLISECONDS) .serverSelector(options.getServerSelector()) .description(options.getDescription()) .maxWaitQueueSize(options.getConnectionPoolSettings().getMaxWaitQueueSize()); for (ClusterListener clusterListener: options.getClusterListeners()) { builder.addClusterListener(clusterListener); } return builder.build(); }
/** * Creates a builder instance. * * @param clusterSettings existing ClusterSettings to default the builder settings on. * @return a builder * @since 3.5 */ public static Builder builder(final ClusterSettings clusterSettings) { return builder().applySettings(clusterSettings); }
private ClusterSettings getClusterSettings(final ClusterSettings settings, final ClusterListener clusterListener) { return ClusterSettings.builder(settings).addClusterListener(clusterListener).build(); }
EmbeddedCluster(final MongoClientSettings mongoClientSettings) { this.server = new EmbeddedServer(mongoClientSettings); this.clusterSettings = ClusterSettings.builder().hosts(singletonList(new ServerAddress())).build(); this.clusterDescription = new ClusterDescription(ClusterConnectionMode.SINGLE, ClusterType.STANDALONE, singletonList(server.getDescription())); }
static ClusterSettings cluster(final ConnectionString cstr, final Config conf) { ClusterSettings.Builder cluster = ClusterSettings.builder().applyConnectionString(cstr); withConf("cluster", conf, c -> { withInt("maxWaitQueueSize", c, cluster::maxWaitQueueSize); withStr("replicaSetName", c, cluster::requiredReplicaSetName); withStr("requiredClusterType", c, v -> cluster.requiredClusterType(ClusterType.valueOf(v.toUpperCase()))); withMs("serverSelectionTimeout", c, s -> cluster.serverSelectionTimeout(s, TimeUnit.MILLISECONDS)); }); return cluster.build(); }
/** * Initializes the persistence with a passed in parameters. Does NOT allow to specify credentials, is useful for * testing purposes. * * @param host the host name of the mongoDB * @param port the port of the mongoDB * @param dbName the database of the mongoDB * @param maxPoolSize the max pool size of the db. * @param maxPoolWaitQueueSize the max queue size of the pool. * @param maxPoolWaitTimeSecs the max wait time in the pool. * @return a new {@code MongoClientWrapper} object. * @see #newInstance(Config) for production purposes */ public static MongoClientWrapper newInstance(final String host, final int port, final String dbName, final int maxPoolSize, final int maxPoolWaitQueueSize, final long maxPoolWaitTimeSecs) { final MongoClientSettings.Builder builder = MongoClientSettings.builder() .readPreference(ReadPreference.secondaryPreferred()) .clusterSettings(ClusterSettings.builder() .hosts(Collections.singletonList(new ServerAddress(host, port))) .build()); final MongoClientSettings mongoClientSettings = buildClientSettings(builder, maxPoolSize, maxPoolWaitQueueSize, Duration.of(maxPoolWaitTimeSecs, ChronoUnit.SECONDS), false, null); return new MongoClientWrapper(dbName, mongoClientSettings); }
@Bean public MongoClient mongoClient() { MongoClient mongoClient; if ((this.configuration.getUri() != null) && (!this.configuration.getUri().isEmpty())) { mongoClient = MongoClients.create(this.configuration.getUri()); } else { ServerAddress serverAddress = new ServerAddress(this.configuration.getHost(), this.configuration.getPort()); ClusterSettings clusterSettings = ClusterSettings.builder().hosts(asList(serverAddress)).build(); MongoClientSettings.Builder settings = MongoClientSettings.builder().clusterSettings(clusterSettings); if (this.configuration.isEnableCredentials()) { MongoCredential credential = MongoCredential.createCredential(this.configuration .getUsernameCredentials(), this.configuration .getDatabaseCredentials(), this.configuration .getPasswordCredentials().toCharArray()); settings.credential(credential); } mongoClient = MongoClients.create(settings.build()); } return mongoClient; }
@Bean public MongoClient mongoClient() { MongoClient mongoClient; if ((this.configuration.getUri() != null) && (!this.configuration.getUri().isEmpty())) { mongoClient = MongoClients.create(this.configuration.getUri()); } else { ServerAddress serverAddress = new ServerAddress(this.configuration.getHost(), this.configuration.getPort()); ClusterSettings clusterSettings = ClusterSettings.builder().hosts(asList(serverAddress)).build(); MongoClientSettings.Builder settings = MongoClientSettings.builder().clusterSettings(clusterSettings); if (this.configuration.isEnableCredentials()) { MongoCredential credential = MongoCredential.createCredential(this.configuration .getUsernameCredentials(), this.configuration .getDatabaseCredentials(), this.configuration .getPasswordCredentials().toCharArray()); settings.credential(credential); } mongoClient = MongoClients.create(settings.build()); } return mongoClient; }
/** * Initializes the persistence with a passed in parameters. Does NOT allow to specify credentials, is useful for * testing purposes. * * @param host the host name of the mongoDB * @param port the port of the mongoDB * @param dbName the database of the mongoDB * @param maxPoolSize the max pool size of the db. * @param maxPoolWaitQueueSize the max queue size of the pool. * @param maxPoolWaitTimeSecs the max wait time in the pool. * @return a new {@code MongoClientWrapper} object. * @see #newInstance(Config) for production purposes */ public static MongoClientWrapper newInstance(final String host, final int port, final String dbName, final int maxPoolSize, final int maxPoolWaitQueueSize, final long maxPoolWaitTimeSecs) { final MongoClientSettings.Builder builder = MongoClientSettings.builder() .readPreference(ReadPreference.secondaryPreferred()) .clusterSettings(ClusterSettings.builder() .hosts(Collections.singletonList(new ServerAddress(host, port))) .build()); final MongoClientSettings mongoClientSettings = buildClientSettings(builder, maxPoolSize, maxPoolWaitQueueSize, Duration.of(maxPoolWaitTimeSecs, ChronoUnit.SECONDS), false, null); return new MongoClientWrapper(dbName, mongoClientSettings); }
/** * Create an asynchronous MongoDB client * @return the client */ private com.mongodb.async.client.MongoClient createAsyncClient() { ClusterSettings clusterSettings = ClusterSettings.builder() .hosts(Arrays.asList(mongoConnector.serverAddress)) .build(); MongoClientSettings settings = MongoClientSettings.builder() .clusterSettings(clusterSettings).build(); return MongoClients.create(settings); }
private static ClusterSettings getClusterSettings(final List<ServerAddress> seedList, final MongoClientOptions options, final ClusterConnectionMode clusterConnectionMode) { ClusterSettings.Builder builder = ClusterSettings.builder() .hosts(new ArrayList<ServerAddress>(seedList)) .mode(clusterConnectionMode) .requiredReplicaSetName(options.getRequiredReplicaSetName()) .serverSelectionTimeout(options.getServerSelectionTimeout(), MILLISECONDS) .localThreshold(options.getLocalThreshold(), MILLISECONDS) .serverSelector(options.getServerSelector()) .description(options.getDescription()) .maxWaitQueueSize(options.getConnectionPoolSettings().getMaxWaitQueueSize()); for (ClusterListener clusterListener: options.getClusterListeners()) { builder.addClusterListener(clusterListener); } return builder.build(); }
ClusterSettings.Builder clusterBuilder = ClusterSettings.builder(); ConnectionPoolSettings.Builder connectionPoolBuilder = ConnectionPoolSettings.builder(); ServerSettings.Builder serverBuilder = ServerSettings.builder();
MongoClientSettings.builder() .readPreference(ReadPreference.secondaryPreferred()) .clusterSettings(ClusterSettings.builder().applyConnectionString(connectionString).build());
MongoClientSettings.builder() .readPreference(ReadPreference.secondaryPreferred()) .clusterSettings(ClusterSettings.builder().applyConnectionString(connectionString).build());