Search in sources :

Example 1 with DBAddress

use of com.mongodb.DBAddress in project sling by apache.

the class MongoDBResourceProviderFactory method activate.

@Activate
protected void activate(final Map<String, Object> props) throws Exception {
    final String[] roots = PropertiesUtil.toStringArray(props.get(ResourceProvider.ROOTS));
    if (roots == null || roots.length == 0) {
        throw new Exception("Roots configuration is missing.");
    }
    if (roots.length > 1) {
        throw new Exception("Only a single root should be configured.");
    }
    if (roots[0] == null || roots[0].trim().length() == 0) {
        throw new Exception("Roots configuration is missing.");
    }
    final String host = PropertiesUtil.toString(props.get(PROP_HOST), DEFAULT_HOST);
    final int port = PropertiesUtil.toInteger(props.get(PROP_PORT), DEFAULT_PORT);
    final String db = PropertiesUtil.toString(props.get(PROP_DB), DEFAULT_DB);
    logger.info("Starting MongoDB resource provider with host={}, port={}, db={}", new Object[] { host, port, db });
    final DBAddress address = new DBAddress(host, port, db);
    final MongoOptions options = new MongoOptions();
    options.connectionsPerHost = PropertiesUtil.toInteger(props.get(PROP_NUM_CONNECTIONS), DEFAULT_NUMCONNECTIONS);
    options.threadsAllowedToBlockForConnectionMultiplier = PropertiesUtil.toInteger(props.get(PROP_THREAD_MULTIPLIER), DEFAULT_THREAD_MULTIPLIER);
    final Mongo m = new Mongo(address, options);
    final DB database = m.getDB(db);
    logger.info("Connected to database {}", database);
    this.context = new MongoDBContext(database, roots[0], PropertiesUtil.toStringArray(props.get(PROP_FILTER_COLLECTIONS)), this.eventAdmin);
}
Also used : Mongo(com.mongodb.Mongo) MongoOptions(com.mongodb.MongoOptions) DBAddress(com.mongodb.DBAddress) LoginException(org.apache.sling.api.resource.LoginException) DB(com.mongodb.DB) Activate(org.apache.felix.scr.annotations.Activate)

Example 2 with DBAddress

use of com.mongodb.DBAddress in project jackrabbit-oak by apache.

the class BlobThroughPutTest method performBenchMark_WriteConcern.

@Ignore
@Test
public void performBenchMark_WriteConcern() throws UnknownHostException, InterruptedException {
    Mongo mongo = new Mongo(new DBAddress(remoteServer));
    final DB db = mongo.getDB(TEST_DB1);
    final DBCollection nodes = db.getCollection("nodes");
    final DBCollection blobs = db.getCollection("blobs");
    int readers = 0;
    int writers = 2;
    for (WriteConcern wc : namedConcerns.keySet()) {
        prepareDB(nodes, blobs);
        final Benchmark b = new Benchmark(nodes, blobs);
        Result r = b.run(readers, writers, true, wc);
        results.add(r);
    }
    prepareDB(nodes, blobs);
    dumpResult();
}
Also used : DBCollection(com.mongodb.DBCollection) Mongo(com.mongodb.Mongo) WriteConcern(com.mongodb.WriteConcern) DBAddress(com.mongodb.DBAddress) DB(com.mongodb.DB) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with DBAddress

use of com.mongodb.DBAddress in project jackrabbit-oak by apache.

the class BlobThroughPutTest method performBenchMark.

@Ignore
@Test
public void performBenchMark() throws UnknownHostException, InterruptedException {
    MongoClient local = new MongoClient(new DBAddress(localServer));
    MongoClient remote = new MongoClient(new DBAddress(remoteServer));
    run(local, false, false);
    run(local, true, false);
    run(remote, false, true);
    run(remote, true, true);
    dumpResult();
}
Also used : MongoClient(com.mongodb.MongoClient) DBAddress(com.mongodb.DBAddress) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DBAddress (com.mongodb.DBAddress)3 DB (com.mongodb.DB)2 Mongo (com.mongodb.Mongo)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 DBCollection (com.mongodb.DBCollection)1 MongoClient (com.mongodb.MongoClient)1 MongoOptions (com.mongodb.MongoOptions)1 WriteConcern (com.mongodb.WriteConcern)1 Activate (org.apache.felix.scr.annotations.Activate)1 LoginException (org.apache.sling.api.resource.LoginException)1