use of com.mongodb.MongoClientURI in project jackrabbit-oak by apache.
the class MongoConnection method hasWriteConcern.
/**
* Returns {@code true} if the given {@code uri} has a write concern set.
* @param uri the URI to check.
* @return {@code true} if the URI has a write concern set, {@code false}
* otherwise.
*/
public static boolean hasWriteConcern(@Nonnull String uri) {
MongoClientOptions.Builder builder = MongoClientOptions.builder();
builder.writeConcern(WC_UNKNOWN);
WriteConcern wc = new MongoClientURI(checkNotNull(uri), builder).getOptions().getWriteConcern();
return !WC_UNKNOWN.equals(wc);
}
use of com.mongodb.MongoClientURI in project jackrabbit-oak by apache.
the class NodeCollectionProvider method prepareClientForHostname.
private MongoClient prepareClientForHostname(String hostname) throws UnknownHostException {
ServerAddress address;
if (hostname.contains(":")) {
String[] hostSplit = hostname.split(":");
if (hostSplit.length != 2) {
throw new IllegalArgumentException("Not a valid hostname: " + hostname);
}
address = new ServerAddress(hostSplit[0], Integer.parseInt(hostSplit[1]));
} else {
address = new ServerAddress(hostname);
}
MongoClientURI originalUri = new MongoClientURI(originalMongoUri);
List<MongoCredential> credentialList = new ArrayList<MongoCredential>(1);
if (originalUri.getCredentials() != null) {
credentialList.add(originalUri.getCredentials());
}
return new MongoClient(address, credentialList, originalUri.getOptions());
}
use of com.mongodb.MongoClientURI in project jackrabbit-oak by apache.
the class NodeCollectionProvider method get.
@SuppressWarnings("deprecation")
public DBCollection get(String hostname) throws UnknownHostException {
if (collections.containsKey(hostname)) {
return collections.get(hostname);
}
MongoClient client;
if (originalMongoUri == null) {
MongoClientURI uri = new MongoClientURI("mongodb://" + hostname);
client = new MongoClient(uri);
} else {
client = prepareClientForHostname(hostname);
}
DB db = client.getDB(dbName);
db.getMongo().slaveOk();
DBCollection collection = db.getCollection(Collection.NODES.toString());
collections.put(hostname, collection);
return collection;
}
use of com.mongodb.MongoClientURI in project jackrabbit-oak by apache.
the class DocumentMongoFixture method getDb.
protected DB getDb(String suffix) throws UnknownHostException {
String dbName = new MongoClientURI(uri).getDatabase();
MongoConnection connection = new MongoConnection(uri);
return connection.getDB(dbName + "-" + suffix);
}
use of com.mongodb.MongoClientURI in project jackrabbit-oak by apache.
the class MongoNodeStoreContainer method testMongoAvailability.
private static boolean testMongoAvailability() {
Mongo mongo = null;
try {
MongoClientURI uri = new MongoClientURI(MONGO_URI + "?connectTimeoutMS=3000");
mongo = new MongoClient(uri);
mongo.getDatabaseNames();
return true;
} catch (Exception e) {
return false;
} finally {
if (mongo != null) {
mongo.close();
}
}
}
Aggregations