Example usage for com.mongodb MongoClientOptions builder

List of usage examples for com.mongodb MongoClientOptions builder

Introduction

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

Prototype

public static Builder builder() 

Source Link

Document

Creates a builder instance.

Usage

From source file:io.prestosql.plugin.mongodb.MongoClientModule.java

License:Apache License

@Singleton
@Provides/*from w ww . j a  va 2s.  c  om*/
public static MongoSession createMongoSession(TypeManager typeManager, MongoClientConfig config) {
    requireNonNull(config, "config is null");

    MongoClientOptions.Builder options = MongoClientOptions.builder();

    options.connectionsPerHost(config.getConnectionsPerHost()).connectTimeout(config.getConnectionTimeout())
            .socketTimeout(config.getSocketTimeout()).socketKeepAlive(config.getSocketKeepAlive())
            .sslEnabled(config.getSslEnabled()).maxWaitTime(config.getMaxWaitTime())
            .minConnectionsPerHost(config.getMinConnectionsPerHost())
            .readPreference(config.getReadPreference().getReadPreference())
            .writeConcern(config.getWriteConcern().getWriteConcern());

    if (config.getRequiredReplicaSetName() != null) {
        options.requiredReplicaSetName(config.getRequiredReplicaSetName());
    }

    MongoClient client = new MongoClient(config.getSeeds(), config.getCredentials(), options.build());

    return new MongoSession(typeManager, client, config);
}

From source file:io.sip3.tapir.salto.configuration.MongoConfiguration.java

License:Apache License

@Bean
public MongoClientURI uri(@Value("${mongo.uri}") String uri) {
    return new MongoClientURI(uri, MongoClientOptions.builder().writeConcern(WriteConcern.UNACKNOWLEDGED));
}

From source file:io.sip3.tapir.twig.configuration.MongoConfiguration.java

License:Apache License

@Bean
public MongoClientURI uri(@Value("${mongo.uri}") String uri, CodecRegistry registry) {
    return new MongoClientURI(uri, MongoClientOptions.builder().codecRegistry(registry));
}

From source file:it.f2informatica.mongodb.MongoDBApplicationConfig.java

License:Apache License

private MongoClientOptions mongoClientOptions() {
    return MongoClientOptions.builder().connectionsPerHost(10).threadsAllowedToBlockForConnectionMultiplier(4)
            .connectTimeout(10000).maxWaitTime(5000).socketKeepAlive(true).socketTimeout(5000).build();
}

From source file:it.f2informatica.mongodb.MongoDBReplicaSetApplicationConfig.java

License:Apache License

private MongoClientOptions mongoOptions() {
    return MongoClientOptions.builder().connectionsPerHost(10).threadsAllowedToBlockForConnectionMultiplier(4)
            .connectTimeout(10000).maxWaitTime(5000).socketKeepAlive(true).socketTimeout(5000).build();
}

From source file:it.terrinoni.m101j.App.java

public static void main(String[] args) {
    MongoClientOptions options = MongoClientOptions.builder().connectionsPerHost(100).build();
    MongoClient client = new MongoClient(new ServerAddress(), options);

    MongoDatabase db = client.getDatabase("test").withReadPreference(ReadPreference.secondary());

    MongoCollection<BsonDocument> coll = db.getCollection("test", BsonDocument.class);
}

From source file:it.wami.map.mongodeploy.OsmToMongoDB.java

License:Apache License

/**
 * @param args/*from   w  w  w . j  av a 2 s  . c  o  m*/
 */
public static void main(String[] args) {

    if (args == null || args.length == 0 || args.length < 2) {
        System.out.println(Options.USAGE);
        return;
    }

    parseCommandOptions(args);

    MongoClientOptions mco = new MongoClientOptions.Builder().connectionsPerHost(150000)
            .threadsAllowedToBlockForConnectionMultiplier(10000).build();

    MongoClient mongoClient = createMongo(options.getHost(), options.getPort(), mco);

    DB db = mongoClient.getDB(options.getDbName());
    DBCollection nodes = db.createCollection(OsmSaxHandler.COLL_NODES, null);
    createNodesIndex(nodes);
    /*DBCollection ways = */
    DBCollection ways = db.createCollection(OsmSaxHandler.COLL_WAYS, null);
    createWaysIndex(ways);
    /*DBCollection relations = */
    DBCollection relations = db.createCollection(OsmSaxHandler.COLL_RELATIONS, null);
    createRelationsIndex(relations);
    db.createCollection(OsmSaxHandler.COLL_TAGS, null);

    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = null;
    try {
        saxParser = factory.newSAXParser();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }

    DefaultHandler handler = new OsmSaxHandler(db, options);

    try {
        if (options.getInput().contains(".bz2")) {
            try {
                saxParser.parse(getInputStreamForBZ2File(options.getInput()), handler);
            } catch (CompressorException e) {
                e.printStackTrace();
            }
        } else if (options.getInput().contains(".osm")) {
            saxParser.parse(options.getInput(), handler);
        } else {
            throw new IllegalArgumentException("input must be an osm file or a bz2.");
        }
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:joliex.mongodb.MongoDbConnector.java

@RequestResponse
public void connect(Value request) throws FaultException {
    try {/*from  ww  w . ja  v a  2s .  co m*/
        host = request.getFirstChild("host").strValue();
        port = request.getFirstChild("port").intValue();
        dbname = request.getFirstChild("dbname").strValue();
        timeZone = request.getFirstChild("timeZone").strValue();
        password = request.getFirstChild("password").strValue();
        username = request.getFirstChild("username").strValue();
        log = Logger.getLogger("org.mongodb.driver");
        log.setLevel(Level.OFF);
        if (request.hasChildren("jsonStringDebug")) {
            jsonDebuger = request.getFirstChild("jsonStringDebug").boolValue();
        }
        if (request.hasChildren("logStreamDebug")) {
            logStream = request.getFirstChild("logStreamDebug").boolValue();
            logString = "Processing Steps at " + System.currentTimeMillis();
        }
        if (System.getProperty("os.arch").contains("64")) {
            is64 = true;
        } else {
            is64 = false;
        }

        zone = DateTimeZone.forID(timeZone);

        ServerAddress serverAddress = new ServerAddress(host, port);
        MongoCredential credential = MongoCredential.createCredential(username, dbname, password.toCharArray());
        mongoClientOptions = MongoClientOptions.builder().build();

        if (null != mongoClient) {
            System.out.println("recovering client");
            db = mongoClient.getDatabase(dbname);
        } else {

            mongoClient = new MongoClient(serverAddress, credential, mongoClientOptions);
            db = mongoClient.getDatabase(dbname);
        }

    } catch (MongoException ex) {
        throw new FaultException("LoginConnection", ex);
    }
}

From source file:jp.co.ctc_g.jse.data.mongo.showcase.config.MongoContextConfig.java

License:Apache License

/**
 * MongoDB??????????????/* www .jav  a  2  s  .  c om*/
 * @return {@link MongoClientOptions.Builder} 
 */
protected MongoClientOptions.Builder config() {
    return MongoClientOptions.builder().connectionsPerHost(connectionsPerHost)
            .threadsAllowedToBlockForConnectionMultiplier(threadsAllowedToBlockForConnectionMultiplier)
            .connectTimeout(connectTimeout).maxWaitTime(maxWaitTime).autoConnectRetry(autoConnectRetry)
            .socketKeepAlive(socketKeepAlive);
}

From source file:jp.co.ctc_g.jse.data.mongo.showcase.config.MongoShowcaseContextConfig.java

License:Apache License

/**
 * MongoDB??????????????//from  w  ww  .ja v  a2 s  .co  m
 * @return {@link MongoClientOptions.Builder} 
 */
protected MongoClientOptions.Builder config() {

    return MongoClientOptions.builder().connectionsPerHost(connectionsPerHost)
            .threadsAllowedToBlockForConnectionMultiplier(threadsAllowedToBlockForConnectionMultiplier)
            .connectTimeout(connectTimeout).maxWaitTime(maxWaitTime).autoConnectRetry(autoConnectRetry)
            .socketKeepAlive(socketKeepAlive);

}