Java 类com.mongodb.DBAddress 实例源码

项目:jackrabbit-dynamodb-store    文件:BlobThroughPutTest.java   
@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();
}
项目:jackrabbit-dynamodb-store    文件:BlobThroughPutTest.java   
@Ignore
@Test
public void performBenchMark() throws UnknownHostException, InterruptedException {
    Mongo local = new Mongo(new DBAddress(localServer));
    Mongo remote = new Mongo(new DBAddress(remoteServer));

    run(local, false, false);
    run(local, true, false);
    run(remote, false, true);
    run(remote, true, true);

    dumpResult();
}
项目:rhq-plugins    文件:MongoDBServerDiscovery.java   
@Override
public Set<DiscoveredResourceDetails> discoverResources(
        ResourceDiscoveryContext context)
        throws InvalidPluginConfigurationException, Exception {

    Set<DiscoveredResourceDetails> details = new HashSet<DiscoveredResourceDetails>();
    List<ProcessScanResult> processes = context.getAutoDiscoveredProcesses();
    for (ProcessScanResult p : processes) {
        String[] cl = p.getProcessInfo().getCommandLine();
        int port = DBAddress.defaultPort();
        String host = "localhost";
        for (int i = 1; i < cl.length; i++) { // 0 = command
            if (cl[i].equals("--port"))
                port = Integer.parseInt(cl[++i]);
            if (cl[i].equals("--bind_ip"))
                host = cl[++i].split(",")[0];
        }
        // load conf file?
        log.debug("connecting to " + port);
        MongoClient client = new MongoClient(host, port);
        try {
            log.debug("databases " + client.getDatabaseNames());
            discover(context, details, client);
        } catch (Exception e) {
            log.warn("failed connection to " + port, e);
            continue;
        } finally {
            client.close();
        }
    }
    return details;
}
项目:hat-vldb2014-code    文件:MongoDbClient.java   
/**
 * Initialize any state for this DB. Called once per DB instance; there is
 * one DB instance per client thread.
 */
public void init() throws DBException {
    // initialize MongoDb driver
    Properties props = getProperties();
    String url = props.getProperty("mongodb.url");
    database = props.getProperty("mongodb.database");
    String writeConcernType = props.getProperty("mongodb.writeConcern");

    if ("none".equals(writeConcernType)) {
        writeConcern = WriteConcern.NONE;
    } else if ("strict".equals(writeConcernType)) {
        writeConcern = WriteConcern.SAFE;
    } else if ("normal".equals(writeConcernType)) {
        writeConcern = WriteConcern.NORMAL;
    }

    try {
        // strip out prefix since Java driver doesn't currently support
        // standard connection format URL yet
        // http://www.mongodb.org/display/DOCS/Connections
        if (url.startsWith("mongodb://")) {
            url = url.substring(10);
        }

        // need to append db to url.
        url += "/"+database;
        System.out.println("new database url = "+url);
        mongo = new Mongo(new DBAddress(url));
        System.out.println("mongo connection created with "+url);
    } catch (Exception e1) {
        System.err.println(
                "Could not initialize MongoDB connection pool for Loader: "
                        + e1.toString());
        e1.printStackTrace();
        return;
    }

}
项目:indenica-repository    文件:PluginMongoDB.java   
public PluginMongoDB(String host) {
    try {
        address = new DBAddress(host, dbName);
    } catch(UnknownHostException e) {
        throw new RuntimeException(e);
    }
}
项目:pp-db-collector-template    文件:EndToEndTest.java   
private void resetBackdropDataSet() throws UnknownHostException {
    DB db = Mongo.connect(new DBAddress("localhost", 27037, "backdrop"));
    db.getCollection("test_test").remove(new BasicDBObject());
}
项目:trends-observatory    文件:MongoConnection.java   
public void connect() throws UnknownHostException {
    db = Mongo.connect(new DBAddress(host, dbname)); 
    db.authenticate(user, pwd.toCharArray());
}
项目:bolton-sigmod2013-code    文件:MongoDbClient.java   
@Override
/**
 * Initialize any state for this DB.
 * Called once per DB instance; there is one DB instance per client thread.
 */
public void init() throws DBException {
    // initialize MongoDb driver
    Properties props = getProperties();
    String url = props.getProperty("mongodb.url", "mongodb://localhost:27017");
    database = props.getProperty("mongodb.database", "ycsb");
    String writeConcernType = props.getProperty("mongodb.writeConcern", "safe").toLowerCase();

    if ("none".equals(writeConcernType)) {
        writeConcern = WriteConcern.NONE;
    } else if ("safe".equals(writeConcernType)) {
        writeConcern = WriteConcern.SAFE;
    } else if ("normal".equals(writeConcernType)) {
        writeConcern = WriteConcern.NORMAL;
    } else if ("fsync_safe".equals(writeConcernType)) {
        writeConcern = WriteConcern.FSYNC_SAFE;
    } else if ("replicas_safe".equals(writeConcernType)) {
        writeConcern = WriteConcern.REPLICAS_SAFE;
    } else {
        System.err.println("ERROR: Invalid writeConcern: '" + writeConcernType + "'. " +
            "Must be [ none | safe | normal | fsync_safe | replicas_safe ]");
        System.exit(1);
    }

    try {
        // strip out prefix since Java driver doesn't currently support
        // standard connection format URL yet
        // http://www.mongodb.org/display/DOCS/Connections
        if (url.startsWith("mongodb://")) {
            url = url.substring(10);
        }

        // need to append db to url.
        url += "/"+database;
        System.out.println("new database url = "+url);
        mongo = new Mongo(new DBAddress(url));
        System.out.println("mongo connection created with "+url);
    } catch (Exception e1) {
        System.err.println(
                "Could not initialize MongoDB connection pool for Loader: "
                        + e1.toString());
        e1.printStackTrace();
        return;
    }

}