Example usage for com.mongodb MongoClientURI toString

List of usage examples for com.mongodb MongoClientURI toString

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.commercehub.jackson.datatype.mongo.ser.MongoClientURISerializer.java

License:Apache License

@Override
public void serialize(MongoClientURI value, JsonGenerator jsonGenerator, SerializerProvider provider)
        throws IOException {
    jsonGenerator.writeString(value.toString());
}

From source file:com.zjy.mongo.splitter.MongoCollectionSplitter.java

License:Apache License

/**
 * Takes an existing {@link MongoClientURI} and returns a new modified URI which replaces the original's server host + port with a
 * supplied new server host + port, but maintaining all the same original options. This is useful for generating distinct URIs for each
 * mongos instance so that large batch reads can all target them separately, distributing the load more evenly. It can also be used to
 * force a block of data to be read directly from the shard's servers directly, bypassing mongos entirely.
 *
 * @param originalUri  the URI to rewrite
 * @param newServerUri the new host(s) to target, e.g. server1:port1[,server2:port2,...]
 * @return the rewritten URI/*from  w  w  w . j av a2  s  .  c o  m*/
 */
protected static MongoClientURI rewriteURI(final MongoClientURI originalUri, final String newServerUri) {
    String originalUriString = originalUri.toString();
    originalUriString = originalUriString.substring(MongoURI.MONGODB_PREFIX.length());

    // uris look like: mongodb://fred:foobar@server1[,server2]/path?options
    //

    //Locate the last character of the original hostname
    int serverEnd;
    int idx = originalUriString.lastIndexOf("/");
    serverEnd = idx < 0 ? originalUriString.length() : idx;

    //Locate the first character of the original hostname
    idx = originalUriString.indexOf("@");
    int serverStart = idx > 0 ? idx + 1 : 0;

    StringBuilder sb = new StringBuilder(originalUriString);
    sb.replace(serverStart, serverEnd, newServerUri);
    return new MongoClientURI(MongoURI.MONGODB_PREFIX + sb);
}

From source file:com.zjy.mongo.util.MongoConfigUtil.java

License:Apache License

/**
 * Helper for providing a {@code MongoClientURI} as the value for a setting.
 * @param conf  the Configuration/*from  w w w .ja v  a2  s.c om*/
 * @param key   the key for the setting
 * @param value the value for the setting
 */
public static void setMongoURI(final Configuration conf, final String key, final MongoClientURI value) {
    conf.set(key, value.toString()); // todo - verify you can toString a
    // URI object
}

From source file:org.alfresco.mongo.MongoClientFactory.java

License:Open Source License

/**
 * Create a string that masks the username password from the uri
 * /*from  w  w w .  ja v a  2  s  .co m*/
 * @param mongoClientURI            a mongo client URI
 * @return                          a string that masks the username password
 */
public static String toStringSafe(MongoClientURI mongoClientURI) {
    String currentURI = mongoClientURI.toString();
    // Always starts with "mongodb://"
    int idx = currentURI.indexOf('@');
    if (idx < 0) {
        // There was no username passowrd
        return currentURI;
    }
    String newURI = "mongodb://" + "***:***" + (currentURI.substring(idx));
    return newURI;
}

From source file:org.graylog.plugins.metrics.mongodb.jadconfig.MongoClientURIConverter.java

License:Open Source License

@Override
public String convertTo(MongoClientURI value) {
    if (value == null) {
        throw new ParameterException("Couldn't convert \"null\" to string.");
    }//w w  w  . j av  a  2s .  c  o  m

    return value.toString();
}

From source file:org.netbeans.modules.mongodb.native_tools.MongoShellExecAction.java

License:Open Source License

@Override
protected String getDisplayName() {
    final MongoClientURI uri = getMongoURI();
    return Bundle.mongoShellOutputTitle(uri != null ? uri.toString() : "localhost");
}