Example usage for com.mongodb MongoClientOptions.Builder alwaysUseMBeans

List of usage examples for com.mongodb MongoClientOptions.Builder alwaysUseMBeans

Introduction

In this page you can find the example usage for com.mongodb MongoClientOptions.Builder alwaysUseMBeans.

Prototype

boolean alwaysUseMBeans

To view the source code for com.mongodb MongoClientOptions.Builder alwaysUseMBeans.

Click Source Link

Usage

From source file:org.craftercms.commons.mongo.MongoClientOptionsFactory.java

License:Open Source License

@Override
protected MongoClientOptions createInstance() throws Exception {
    MongoClientOptions.Builder builder = MongoClientOptions.builder();
    builder.alwaysUseMBeans(this.alwaysUseMBeans);
    builder.connectionsPerHost(this.connectionsPerHost);
    builder.cursorFinalizerEnabled(this.cursorFinalizerEnabled);
    builder.connectTimeout(this.connectTimeout);
    builder.maxWaitTime(this.maxWaitTime);

    switch (this.readPreference) {
    case PRIMARY_READ_PREFERENCE:
        builder.readPreference(ReadPreference.primary());
        break;/*from   w w w .ja  va  2 s.com*/
    case NEAREST_READ_PREFERENCE:
        builder.readPreference(ReadPreference.nearest());
        break;
    case SECONDARY_READ_PREFERENCE:
        builder.readPreference(ReadPreference.secondary());
        break;
    default:
        builder.readPreference(ReadPreference.primary());
        break;
    }
    builder.writeConcern(WriteConcern.valueOf(this.writeConcern));
    builder.threadsAllowedToBlockForConnectionMultiplier(this.threadsAllowedToBlockForConnectionMultiplier);
    return builder.build();

}

From source file:org.craftercms.studio.impl.repository.mongodb.data.ClientOptionsFactory.java

License:Open Source License

public void init() {
    MongoClientOptions.Builder builder = MongoClientOptions.builder();
    builder.alwaysUseMBeans(this.alwaysUseMBeans);
    builder.autoConnectRetry(this.autoConnectRetry);
    builder.connectionsPerHost(this.connectionsPerHost);
    builder.cursorFinalizerEnabled(this.cursorFinalizerEnabled);
    builder.connectTimeout(this.connectTimeout);
    builder.maxAutoConnectRetryTime(this.maxAutoConnectRetryTime);
    builder.maxWaitTime(this.maxWaitTime);

    switch (this.readPreference) {
    case PRIMARY_READ_PREFERENCE:
        builder.readPreference(ReadPreference.primary());
        break;/*www . java  2  s.  com*/
    case NEAREST_READ_PREFERENCE:
        builder.readPreference(ReadPreference.nearest());
        break;
    case SECONDARY_READ_PREFERENCE:
        builder.readPreference(ReadPreference.secondary());
        break;
    default:
        builder.readPreference(ReadPreference.primary());
        break;
    }
    builder.socketKeepAlive(this.socketKeepAlive);
    builder.writeConcern(WriteConcern.valueOf(this.writeConcern));
    builder.threadsAllowedToBlockForConnectionMultiplier(this.threadsAllowedToBlockForConnectionMultiplier);
    this.clientOptions = builder.build();
}

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

License:Apache License

private MongoClientOptions.Builder options(final Config config) {
    MongoClientOptions.Builder builder = MongoClientOptions.builder();

    builder.connectionsPerHost(config.getInt("connectionsPerHost"));
    builder.threadsAllowedToBlockForConnectionMultiplier(
            config.getInt("threadsAllowedToBlockForConnectionMultiplier"));
    builder.maxWaitTime((int) config.getDuration("maxWaitTime", TimeUnit.MILLISECONDS));
    builder.connectTimeout((int) config.getDuration("connectTimeout", TimeUnit.MILLISECONDS));
    builder.socketTimeout((int) config.getDuration("socketTimeout", TimeUnit.MILLISECONDS));
    builder.socketKeepAlive(config.getBoolean("socketKeepAlive"));
    builder.cursorFinalizerEnabled(config.getBoolean("cursorFinalizerEnabled"));
    builder.alwaysUseMBeans(config.getBoolean("alwaysUseMBeans"));
    builder.heartbeatFrequency(config.getInt("heartbeatFrequency"));
    builder.minHeartbeatFrequency(config.getInt("minHeartbeatFrequency"));
    builder.heartbeatConnectTimeout((int) config.getDuration("heartbeatConnectTimeout", TimeUnit.MILLISECONDS));
    builder.heartbeatSocketTimeout((int) config.getDuration("heartbeatSocketTimeout", TimeUnit.MILLISECONDS));

    return builder;
}