Example usage for com.mongodb ReadPreference primaryPreferred

List of usage examples for com.mongodb ReadPreference primaryPreferred

Introduction

In this page you can find the example usage for com.mongodb ReadPreference primaryPreferred.

Prototype

public static ReadPreference primaryPreferred(final long maxStaleness, final TimeUnit timeUnit) 

Source Link

Document

Gets a read preference that forces reads to the primary if available, otherwise to a secondary.

Usage

From source file:com.github.maasdi.mongo.NamedReadPreference.java

License:Apache License

public ReadPreference getTaggableReadPreference(DBObject firstTagSet, DBObject... remainingTagSets) {

    switch (this) {
    case PRIMARY_PREFERRED:
        return ReadPreference.primaryPreferred(firstTagSet, remainingTagSets);
    case SECONDARY:
        return ReadPreference.secondary(firstTagSet, remainingTagSets);
    case SECONDARY_PREFERRED:
        return ReadPreference.secondaryPreferred(firstTagSet, remainingTagSets);
    case NEAREST:
        return ReadPreference.nearest(firstTagSet, remainingTagSets);
    default:/*from   w  w w  .j  a  va 2  s . co m*/
        return (pref instanceof TaggableReadPreference) ? pref : null;
    }
}