Example usage for com.mongodb MongoClientSettings.Builder socketSettings

List of usage examples for com.mongodb MongoClientSettings.Builder socketSettings

Introduction

In this page you can find the example usage for com.mongodb MongoClientSettings.Builder socketSettings.

Prototype

SocketSettings socketSettings

To view the source code for com.mongodb MongoClientSettings.Builder socketSettings.

Click Source Link

Usage

From source file:org.jooby.mongodb.MongoRx.java

License:Apache License

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(Match(v.toUpperCase())
                    .option(Case("DEFAULT", ReadConcern.DEFAULT), Case("LOCAL", ReadConcern.LOCAL),
                            Case("MAJORITY", ReadConcern.MAJORITY))
                    .getOrElseThrow(() -> new IllegalArgumentException("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(Match(v.toUpperCase())
                    .option(Case("W1", WriteConcern.W1), Case("W2", WriteConcern.W2),
                            Case("W3", WriteConcern.W3), Case("ACKNOWLEDGED", WriteConcern.ACKNOWLEDGED),
                            Case("JOURNALED", WriteConcern.JOURNALED), Case("MAJORITY", WriteConcern.MAJORITY))
                    .getOrElseThrow(() -> new IllegalArgumentException("writeConcern=" + v))));

    return settings;
}