Example usage for com.mongodb MongoClientURI getHosts

List of usage examples for com.mongodb MongoClientURI getHosts

Introduction

In this page you can find the example usage for com.mongodb MongoClientURI getHosts.

Prototype

public List<String> getHosts() 

Source Link

Document

Gets the list of hosts

Usage

From source file:org.netbeans.modules.mongodb.ui.components.MongoURIEditorPanel.java

License:Open Source License

public void setMongoURI(MongoClientURI uri) {
    hostsListModel.clear();/*from  w ww.ja v a  2 s  . c  o m*/
    optionsListModel.clear();
    for (String string : uri.getHosts()) {
        final String[] rawHost = string.split(":");
        final String hostname = urlDecode(rawHost[0]);
        final Integer port = rawHost.length > 1 ? Integer.parseInt(rawHost[1]) : null;
        hostsListModel.addElement(new Host(hostname, port));
    }
    usernameField.setText(uri.getUsername());
    if (uri.getPassword() != null) {
        passwordField.setText(new String(uri.getPassword()));
    }
    databaseField.setText(uri.getDatabase());
    final List<Option> options = decodeOptions(uri);
    optionsListModel.clear();
    for (Option option : options) {
        optionsListModel.addElement(option);
    }
    updateURIField();
}

From source file:rapture.mongodb.MongoDBFactory.java

License:Open Source License

private Mongo getMongoFromLocalConfig(String instanceName) {
    String mongoHost = MultiValueConfigLoader.getConfig("MONGODB-" + instanceName);
    log.info("Host is " + mongoHost);
    if (StringUtils.isBlank(mongoHost)) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST,
                mongoMsgCatalog.getMessage("NoHost"));
    }//from w ww.  j  a  v  a  2 s .co  m
    MongoClientURI uri = new MongoClientURI(mongoHost);
    log.info("Username is " + uri.getUsername());
    log.info("Host is " + uri.getHosts().toString());
    log.info("DBName is " + uri.getDatabase());
    log.info("Collection is " + uri.getCollection());
    try {
        MongoClient mongo = new MongoClient(uri);
        mongoDBs.put(instanceName, mongo.getDB(uri.getDatabase()));
        mongoDatabases.put(instanceName, mongo.getDatabase(uri.getDatabase()));
        mongoInstances.put(instanceName, mongo);
        return mongo;
    } catch (MongoException e) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, new ExceptionToString(e));
    }
}

From source file:rapture.repo.integration.LocalTestSetup.java

License:Open Source License

public static void createUser() throws IOException, InterruptedException {
    String mongoHost = MultiValueConfigLoader.getConfig("MONGODB-integrationTest");
    log.info("Host is " + mongoHost);
    if (mongoHost != null) {
        MongoClientURI uri = new MongoClientURI(mongoHost);
        List<String> hosts = uri.getHosts();
        for (String host : hosts) {
            String[] cmdarray = createSetupCommand(host, uri.getDatabase(), uri.getUsername(),
                    new String(uri.getPassword()));
            Process process = Runtime.getRuntime().exec(cmdarray);
            int retVal = process.waitFor();
            log.info(String.format("retVal=%s", retVal));
            log.info("output is " + IOUtils.toString(process.getInputStream()));
            if (retVal != 0) {
                log.info("error is " + IOUtils.toString(process.getErrorStream()));
            }/*from   ww w. j  a  v a  2s.  c o  m*/
        }
    } else {
        log.error("mongo host is not defined!");
    }
}