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);
}
}
Aggregations