/** * 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); }
/** * 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); }
.readPreference(ReadPreference.secondaryPreferred()) .clusterSettings(ClusterSettings.builder().applyConnectionString(connectionString).build());
.readPreference(ReadPreference.secondaryPreferred()) .clusterSettings(ClusterSettings.builder().applyConnectionString(connectionString).build());
static MongoClientSettings.Builder settings(final ConnectionString cstr, final Config conf) { MongoClientSettings.Builder settings = MongoClientSettings.builder(); settings.clusterSettings(cluster(cstr, conf)); settings.connectionPoolSettings(pool(cstr, conf)); settings.heartbeatSocketSettings(socket("heartbeat", cstr, conf)); withStr("readConcern", conf, v -> settings.readConcern(readConcern(v))); withStr("readPreference", conf, v -> settings.readPreference(ReadPreference.valueOf(v))); settings.serverSettings(server(conf)); settings.socketSettings(socket("socket", cstr, conf)); settings.sslSettings(ssl(cstr, conf)); withStr("writeConcern", conf, v -> settings.writeConcern(writeConcern(v))); return settings; }
@Override protected MongoClientSettings createInstance() throws Exception { return MongoClientSettings.builder() // .readPreference(readPreference) // .writeConcern(writeConcern) // .readConcern(readConcern) // .credentialList(credentialList) // .streamFactoryFactory(streamFactoryFactory) // .codecRegistry(codecRegistry) // .clusterSettings(clusterSettings) // .socketSettings(socketSettings) // .heartbeatSocketSettings(heartbeatSocketSettings) // .connectionPoolSettings(connectionPoolSettings) // .serverSettings(serverSettings) // .sslSettings(sslSettings) // .build(); } }
@Override protected MongoClientSettings createInstance() throws Exception { return MongoClientSettings.builder() // .readPreference(readPreference) // .writeConcern(writeConcern) // .readConcern(readConcern) // .credentialList(credentialList) // .streamFactoryFactory(streamFactoryFactory) // .codecRegistry(codecRegistry) // .clusterSettings(clusterSettings) // .socketSettings(socketSettings) // .heartbeatSocketSettings(heartbeatSocketSettings) // .connectionPoolSettings(connectionPoolSettings) // .serverSettings(serverSettings) // .sslSettings(sslSettings) // .build(); } }
static MongoClientSettings.Builder settings(final ConnectionString cstr, final Config conf) { MongoClientSettings.Builder settings = MongoClientSettings.builder(); settings.clusterSettings(cluster(cstr, conf)); settings.connectionPoolSettings(pool(cstr, conf)); settings.heartbeatSocketSettings(socket("heartbeat", cstr, conf)); withStr("readConcern", conf, v -> settings.readConcern(readConcern(v))); withStr("readPreference", conf, v -> settings.readPreference(ReadPreference.valueOf(v))); settings.serverSettings(server(conf)); settings.socketSettings(socket("socket", cstr, conf)); settings.sslSettings(ssl(cstr, conf)); withStr("writeConcern", conf, v -> settings.writeConcern(writeConcern(v))); return settings; }