Example usage for com.mongodb MongoOptions setConnectionsPerHost

List of usage examples for com.mongodb MongoOptions setConnectionsPerHost

Introduction

In this page you can find the example usage for com.mongodb MongoOptions setConnectionsPerHost.

Prototype

public synchronized void setConnectionsPerHost(final int connections) 

Source Link

Document

Sets the maximum number of connections allowed per host for this Mongo instance.

Usage

From source file:fr.cnes.sitools.datasource.mongodb.business.SitoolsMongoDBDataSourceFactory.java

License:Open Source License

/**
 * Setup a dataSource for "users". Usage is for all users for consultation functions.
 * //  w  ww . j ava2s.  c  o m
 * @param dataSource
 *          the DataSource to update
 * @return SitoolsDataSource the new DataSource
 */
public SitoolsMongoDBDataSource setupDataSourceForUsers(MongoDBDataSource dataSource) {
    String key = dataSource.getId();
    SitoolsMongoDBDataSource foundDatasource = dataSources.get(key);
    if (foundDatasource == null) {

        Mongo mongo = null;
        try {
            MongoOptions options = new MongoOptions();
            ServerAddress address = new ServerAddress(dataSource.getUrl(), dataSource.getPortNumber());
            options.setConnectionsPerHost(dataSource.getMaxActive());
            mongo = new Mongo(address, options);
        } catch (UnknownHostException e) {
            logger.log(Level.INFO, null, e);
        } catch (MongoException e) {
            logger.log(Level.INFO, null, e);
        }

        foundDatasource = new SitoolsMongoDBDataSource(dataSource, mongo);
        dataSources.put(key, foundDatasource);
    }
    return foundDatasource;
}

From source file:jp.co.ctc_g.rack.core.config.RackMongoContextConfig.java

License:Apache License

/**
 * MongoDI????//from w w  w .  ja v a2s .c o m
 * @return Mongo
 */
@Bean
public MongoOptions mongoOptions() {

    MongoOptions options = new MongoOptions();
    options.setConnectionsPerHost(connectionsPerHost);
    options.setThreadsAllowedToBlockForConnectionMultiplier(threadAllowedToBlockForConnectionMultiplier);
    options.setConnectTimeout(connectTimeout);
    options.setMaxWaitTime(maxWaitTime);
    options.setAutoConnectRetry(autoConnectRetry);
    options.setSocketKeepAlive(socketKeepAlive);
    options.setSocketTimeout(socketTimeout);
    options.setFsync(fsync);
    return options;
}

From source file:org.eclipse.birt.data.oda.mongodb.impl.MongoDBDriver.java

License:Open Source License

private static MongoOptions getURIOptions(MongoURI mongoUri) {
    MongoOptions uriOptions = mongoUri.getOptions();

    // explicitly adopts those default client options, which were overridden
    // by MongoClientOptions.Builder#legacyDefaults()
    uriOptions.setConnectionsPerHost(sm_defaultClientOptions.getConnectionsPerHost());
    uriOptions.setWriteConcern(sm_defaultClientOptions.getWriteConcern());

    return uriOptions;
}

From source file:org.springframework.data.mongodb.core.MongoOptionsFactoryBean.java

License:Apache License

@Override
protected MongoOptions createInstance() throws Exception {

    if (MongoClientVersion.isMongo3Driver()) {
        throw new IllegalArgumentException(String.format(
                "Usage of 'mongo-options' is no longer supported for MongoDB Java driver version 3 and above. Please use 'mongo-client-options' and refer to chapter 'MongoDB 3.0 Support' for details."));
    }//from   w  w  w . j  a va  2s. co m

    MongoOptions options = new MongoOptions();

    options.setConnectionsPerHost(connectionsPerHost);
    options.setThreadsAllowedToBlockForConnectionMultiplier(threadsAllowedToBlockForConnectionMultiplier);
    options.setMaxWaitTime(maxWaitTime);
    options.setConnectTimeout(connectTimeout);
    options.setSocketTimeout(socketTimeout);
    options.setSocketKeepAlive(socketKeepAlive);

    options.setW(writeNumber);
    options.setWtimeout(writeTimeout);
    options.setFsync(writeFsync);

    if (ssl) {
        options.setSocketFactory(sslSocketFactory != null ? sslSocketFactory : SSLSocketFactory.getDefault());
    }

    ReflectiveMongoOptionsInvoker.setAutoConnectRetry(options, autoConnectRetry);
    ReflectiveMongoOptionsInvoker.setMaxAutoConnectRetryTime(options, maxAutoConnectRetryTime);
    ReflectiveMongoOptionsInvoker.setSlaveOk(options, slaveOk);

    return options;
}