use of com.mongodb.MongoClientOptions.Builder in project mongo-java-driver by mongodb.
the class MongoOptions method toClientOptions.
MongoClientOptions toClientOptions() {
Builder builder = MongoClientOptions.builder().requiredReplicaSetName(requiredReplicaSetName).connectionsPerHost(connectionsPerHost).connectTimeout(connectTimeout).dbDecoderFactory(dbDecoderFactory).dbEncoderFactory(dbEncoderFactory).description(description).maxWaitTime(maxWaitTime).socketFactory(socketFactory).socketKeepAlive(socketKeepAlive).socketTimeout(socketTimeout).threadsAllowedToBlockForConnectionMultiplier(threadsAllowedToBlockForConnectionMultiplier).cursorFinalizerEnabled(cursorFinalizerEnabled).alwaysUseMBeans(alwaysUseMBeans);
builder.writeConcern(getWriteConcern());
if (readPreference != null) {
builder.readPreference(getReadPreference());
}
return builder.build();
}
use of com.mongodb.MongoClientOptions.Builder in project spring-cloud-connectors by spring-cloud.
the class MongoDbFactoryCreator method getMongoOptions.
private MongoClientOptions.Builder getMongoOptions(MongoDbFactoryConfig config) {
MongoClientOptions.Builder builder;
Method builderMethod = ClassUtils.getMethodIfAvailable(MongoClientOptions.class, "builder");
if (builderMethod != null) {
builder = (Builder) ReflectionUtils.invokeMethod(builderMethod, null);
} else {
Constructor<Builder> builderConstructor = ClassUtils.getConstructorIfAvailable(MongoClientOptions.Builder.class);
try {
builder = builderConstructor.newInstance(new Object[0]);
} catch (InstantiationException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (IllegalArgumentException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(e);
}
}
if (config != null) {
if (config.getConnectionsPerHost() != null) {
builder.connectionsPerHost(config.getConnectionsPerHost());
}
if (config.getMaxWaitTime() != null) {
builder.maxWaitTime(config.getMaxWaitTime());
}
if (config.getWriteConcern() != null) {
builder.writeConcern(new WriteConcern(config.getWriteConcern()));
}
}
return builder;
}
Aggregations