Search in sources :

Example 1 with WritableServerSelector

use of com.mongodb.selector.WritableServerSelector in project mongo-java-driver by mongodb.

the class ServerSelectionSelectionTest method getServerSelector.

private ServerSelector getServerSelector() {
    if (definition.getString("operation", new BsonString("read")).getValue().equals("write")) {
        return new WritableServerSelector();
    } else {
        BsonDocument readPreferenceDefinition = definition.getDocument("read_preference");
        ReadPreference readPreference;
        if (readPreferenceDefinition.getString("mode").getValue().equals("Primary")) {
            readPreference = ReadPreference.valueOf("Primary");
        } else if (readPreferenceDefinition.containsKey("maxStalenessSeconds")) {
            readPreference = ReadPreference.valueOf(readPreferenceDefinition.getString("mode", new BsonString("Primary")).getValue(), buildTagSets(readPreferenceDefinition.getArray("tag_sets", new BsonArray())), Math.round(readPreferenceDefinition.getNumber("maxStalenessSeconds").doubleValue() * 1000), TimeUnit.MILLISECONDS);
        } else {
            readPreference = ReadPreference.valueOf(readPreferenceDefinition.getString("mode", new BsonString("Primary")).getValue(), buildTagSets(readPreferenceDefinition.getArray("tag_sets", new BsonArray())));
        }
        return new ReadPreferenceServerSelector(readPreference);
    }
}
Also used : ReadPreference(com.mongodb.ReadPreference) WritableServerSelector(com.mongodb.selector.WritableServerSelector) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) ReadPreferenceServerSelector(com.mongodb.selector.ReadPreferenceServerSelector)

Aggregations

ReadPreference (com.mongodb.ReadPreference)1 ReadPreferenceServerSelector (com.mongodb.selector.ReadPreferenceServerSelector)1 WritableServerSelector (com.mongodb.selector.WritableServerSelector)1 BsonArray (org.bson.BsonArray)1 BsonDocument (org.bson.BsonDocument)1 BsonString (org.bson.BsonString)1