Example usage for com.mongodb MongoClientOptions.Builder description

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

Introduction

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

Prototype

String description

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

Click Source Link

Usage

From source file:com.github.nlloyd.hornofmongo.adaptor.Mongo.java

License:Open Source License

private void initMongoConnection() throws UnknownHostException {
    if ((innerMongo == null)) {
        MongoClientOptions.Builder builder = MongoClientOptions.builder();
        if (mongoOptions != null) {
            //Restore previous options
            builder.description(mongoOptions.description);
            builder.connectionsPerHost(mongoOptions.connectionsPerHost);
            builder.threadsAllowedToBlockForConnectionMultiplier(
                    mongoOptions.threadsAllowedToBlockForConnectionMultiplier);
            builder.maxWaitTime(mongoOptions.maxWaitTime);
            builder.connectTimeout(mongoOptions.connectTimeout);
            builder.socketTimeout(mongoOptions.socketTimeout);
            builder.socketKeepAlive(mongoOptions.socketKeepAlive);
        }/*from www .  j a  v a  2s . c o m*/
        MongoClientOptions clientOptions = builder.dbEncoderFactory(HornOfMongoBSONEncoder.FACTORY).build();
        this.innerMongo = new com.mongodb.MongoClient(this.hosts, clientOptions);
        if (options != 0)
            this.innerMongo.setOptions(options);
    }
    if (mongoScope.useMongoShellWriteConcern())
        innerMongo.setWriteConcern(WriteConcern.UNACKNOWLEDGED);
}

From source file:io.gravitee.repository.mongodb.common.MongoFactory.java

License:Apache License

private MongoClientOptions.Builder builder() {
    MongoClientOptions.Builder builder = MongoClientOptions.builder();

    builder.writeConcern(WriteConcern.SAFE);

    Integer connectionsPerHost = readPropertyValue(propertyPrefix + "connectionsPerHost", Integer.class);
    Integer connectTimeout = readPropertyValue(propertyPrefix + "connectTimeout", Integer.class, 500);
    Integer maxWaitTime = readPropertyValue(propertyPrefix + "maxWaitTime", Integer.class);
    Integer socketTimeout = readPropertyValue(propertyPrefix + "socketTimeout", Integer.class, 500);
    Boolean socketKeepAlive = readPropertyValue(propertyPrefix + "socketKeepAlive", Boolean.class);
    Integer maxConnectionLifeTime = readPropertyValue(propertyPrefix + "maxConnectionLifeTime", Integer.class);
    Integer maxConnectionIdleTime = readPropertyValue(propertyPrefix + "maxConnectionIdleTime", Integer.class);

    // We do not want to wait for a server
    Integer serverSelectionTimeout = readPropertyValue(propertyPrefix + "serverSelectionTimeout", Integer.class,
            0);/*  w  ww  .  j  a v  a2  s .c o  m*/
    Integer minHeartbeatFrequency = readPropertyValue(propertyPrefix + "minHeartbeatFrequency", Integer.class);
    String description = readPropertyValue(propertyPrefix + "description", String.class, "gravitee.io");
    Integer heartbeatConnectTimeout = readPropertyValue(propertyPrefix + "heartbeatConnectTimeout",
            Integer.class, 1000);
    Integer heartbeatFrequency = readPropertyValue(propertyPrefix + "heartbeatFrequency", Integer.class);
    Integer heartbeatSocketTimeout = readPropertyValue(propertyPrefix + "heartbeatSocketTimeout",
            Integer.class);
    Integer localThreshold = readPropertyValue(propertyPrefix + "localThreshold", Integer.class);
    Integer minConnectionsPerHost = readPropertyValue(propertyPrefix + "minConnectionsPerHost", Integer.class);
    Boolean sslEnabled = readPropertyValue(propertyPrefix + "sslEnabled", Boolean.class);
    Integer threadsAllowedToBlockForConnectionMultiplier = readPropertyValue(
            propertyPrefix + "threadsAllowedToBlockForConnectionMultiplier", Integer.class);
    Boolean cursorFinalizerEnabled = readPropertyValue(propertyPrefix + "cursorFinalizerEnabled",
            Boolean.class);

    if (connectionsPerHost != null)
        builder.connectionsPerHost(connectionsPerHost);
    if (maxWaitTime != null)
        builder.maxWaitTime(maxWaitTime);
    if (connectTimeout != null)
        builder.connectTimeout(connectTimeout);
    if (socketTimeout != null)
        builder.socketTimeout(socketTimeout);
    if (socketKeepAlive != null)
        builder.socketKeepAlive(socketKeepAlive);
    if (maxConnectionLifeTime != null)
        builder.maxConnectionLifeTime(maxConnectionLifeTime);
    if (maxConnectionIdleTime != null)
        builder.maxConnectionIdleTime(maxConnectionIdleTime);
    if (minHeartbeatFrequency != null)
        builder.minHeartbeatFrequency(minHeartbeatFrequency);
    if (description != null)
        builder.description(description);
    if (heartbeatConnectTimeout != null)
        builder.heartbeatConnectTimeout(heartbeatConnectTimeout);
    if (heartbeatFrequency != null)
        builder.heartbeatFrequency(heartbeatFrequency);
    if (heartbeatSocketTimeout != null)
        builder.heartbeatSocketTimeout(heartbeatSocketTimeout);
    if (localThreshold != null)
        builder.localThreshold(localThreshold);
    if (minConnectionsPerHost != null)
        builder.minConnectionsPerHost(minConnectionsPerHost);
    if (sslEnabled != null)
        builder.sslEnabled(sslEnabled);
    if (threadsAllowedToBlockForConnectionMultiplier != null)
        builder.threadsAllowedToBlockForConnectionMultiplier(threadsAllowedToBlockForConnectionMultiplier);
    if (cursorFinalizerEnabled != null)
        builder.cursorFinalizerEnabled(cursorFinalizerEnabled);
    if (serverSelectionTimeout != null)
        builder.serverSelectionTimeout(serverSelectionTimeout);

    return builder;
}

From source file:org.eclipselabs.emongo.components.MongoClientProviderComponent.java

License:Open Source License

private MongoClientOptions createMongoClientOptions(Map<String, Object> properties) {
    MongoClientOptions.Builder optionsBuilder = new MongoClientOptions.Builder();

    String description = (String) properties.get(PROP_DESCRIPTION);

    if (description != null)
        optionsBuilder.description(description);

    Integer connectionsPerHost = (Integer) properties.get(PROP_CONNECTIONS_PER_HOST);

    if (connectionsPerHost != null)
        optionsBuilder.connectionsPerHost(connectionsPerHost);

    Integer threadsAllowedToBlockForConnectionMultiplier = (Integer) properties
            .get(PROP_THREADS_ALLOWED_TO_BLOCK_FOR_CONNECTION_MULTIPLIER);

    if (threadsAllowedToBlockForConnectionMultiplier != null)
        optionsBuilder// w w  w  . j  a  va  2s  . c om
                .threadsAllowedToBlockForConnectionMultiplier(threadsAllowedToBlockForConnectionMultiplier);

    Integer maxWaitTime = (Integer) properties.get(PROP_MAX_WAIT_TIME);

    if (maxWaitTime != null)
        optionsBuilder.maxWaitTime(maxWaitTime);

    Integer connectTimeout = (Integer) properties.get(PROP_CONNECT_TIMEOUT);

    if (connectTimeout != null)
        optionsBuilder.connectTimeout(connectTimeout);

    Integer socketTimeout = (Integer) properties.get(PROP_SOCKET_TIMEOUT);

    if (socketTimeout != null)
        optionsBuilder.socketTimeout(socketTimeout);

    Boolean socketKeepAlive = (Boolean) properties.get(PROP_SOCKET_KEEP_ALIVE);

    if (socketKeepAlive != null)
        optionsBuilder.socketKeepAlive(socketKeepAlive);

    Boolean autoConnectRetry = (Boolean) properties.get(PROP_AUTO_CONNECT_RETRY);

    if (autoConnectRetry != null)
        optionsBuilder.autoConnectRetry(autoConnectRetry);

    Long maxAutoConnectRetryTime = (Long) properties.get(PROP_MAX_AUTO_CONNECT_RETRY_TIME);

    if (maxAutoConnectRetryTime != null)
        optionsBuilder.maxAutoConnectRetryTime(maxAutoConnectRetryTime);

    Boolean continueOnInsertError = (Boolean) properties.get(PROP_CONTINUE_ON_INSERT_ERROR);

    if (continueOnInsertError == null)
        continueOnInsertError = Boolean.FALSE;

    Integer w = (Integer) properties.get(PROP_W);

    if (w == null)
        w = Integer.valueOf(1);

    Integer wtimeout = (Integer) properties.get(PROP_WTIMEOUT);

    if (wtimeout == null)
        wtimeout = Integer.valueOf(0);

    Boolean fsync = (Boolean) properties.get(PROP_FSYNC);

    if (fsync == null)
        fsync = Boolean.FALSE;

    Boolean j = (Boolean) properties.get(PROP_J);

    if (j == null)
        j = Boolean.FALSE;

    WriteConcern writeConcern = new WriteConcern(w, wtimeout, fsync, j, continueOnInsertError);
    optionsBuilder.writeConcern(writeConcern);

    return optionsBuilder.build();
}