當前位置: 首頁>>代碼示例>>Java>>正文


Java ReadPreference.secondaryPreferred方法代碼示例

本文整理匯總了Java中com.mongodb.ReadPreference.secondaryPreferred方法的典型用法代碼示例。如果您正苦於以下問題:Java ReadPreference.secondaryPreferred方法的具體用法?Java ReadPreference.secondaryPreferred怎麽用?Java ReadPreference.secondaryPreferred使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mongodb.ReadPreference的用法示例。


在下文中一共展示了ReadPreference.secondaryPreferred方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readPreference

import com.mongodb.ReadPreference; //導入方法依賴的package包/類
/**
 * Prepares {@link ReadPreference} from given {@link ReadPreferenceEnum}
 *
 * @param readPreferenceEnum    Read preference enum value provided in config
 * @return  Read preference for mongo client options
 */
public static ReadPreference readPreference(ReadPreferenceEnum readPreferenceEnum) {
    switch (readPreferenceEnum) {
        case NEAREST:
            return ReadPreference.nearest();

        case PRIMARY:
            return ReadPreference.primary();

        case SECONDARY:
            return ReadPreference.secondary();

        case PRIMARY_PREFERRED:
            return ReadPreference.primaryPreferred();

        case SECONDARY_PREFERRED:
            return ReadPreference.secondaryPreferred();

        default:
            return null;
    }
}
 
開發者ID:AdeptJ,項目名稱:adeptj-modules,代碼行數:28,代碼來源:Utils.java

示例2: getBlob

import com.mongodb.ReadPreference; //導入方法依賴的package包/類
private MongoBlob getBlob(String id, long lastMod) {
    DBObject query = getBlobQuery(id, lastMod);

    // try the secondary first
    // TODO add a configuration option for whether to try reading from secondary
    ReadPreference pref = ReadPreference.secondaryPreferred();
    DBObject fields = new BasicDBObject();
    fields.put(MongoBlob.KEY_DATA, 1);
    MongoBlob blob = (MongoBlob) getBlobCollection().findOne(query, fields, pref);
    if (blob == null) {
        // not found in the secondary: try the primary
        pref = ReadPreference.primary();
        blob = (MongoBlob) getBlobCollection().findOne(query, fields, pref);
    }
    return blob;
}
 
開發者ID:denismo,項目名稱:jackrabbit-dynamodb-store,代碼行數:17,代碼來源:MongoBlobStore.java

示例3: parse

import com.mongodb.ReadPreference; //導入方法依賴的package包/類
public static ReadPreference parse(String value) {
    value = value.trim();
    int paren = value.indexOf('(');
    String pref;
    List<TagSet> tags;
    if (paren != -1) {
        pref = value.substring(0, paren).trim();
        String argsStr = value.substring(paren + 1).trim();
        if (!argsStr.endsWith(")")) {
            throw new InvalidReadPreference(value);
        }
        tags = parseArgs(argsStr.substring(0, argsStr.length() - 1));
    } else {
        pref = value;
        tags = null;
    }
    switch (pref) {
        case READ_PREFERENCE_NEAREST:
            if (tags == null) {
                return ReadPreference.nearest();
            } else {
                return ReadPreference.nearest(tags);
            }
        case READ_PREFERENCE_PRIMARY:
            return ReadPreference.primary();
        case READ_PREFERENCE_PRIMARY_PREFERRED:
            if (tags == null) {
                return ReadPreference.primaryPreferred();
            } else {
                return ReadPreference.primaryPreferred(tags);
            }
        case READ_PREFERENCE_SECONDARY:
            if (tags == null) {
                return ReadPreference.secondary();
            } else {
                return ReadPreference.secondary(tags);
            }
        case READ_PREFERENCE_SECONDARY_PREFERRED:
            if (tags == null) {
                return ReadPreference.secondaryPreferred();
            } else {
                return ReadPreference.secondaryPreferred(tags);
            }
        default:
            throw new InvalidReadPreference(value);
    }
}
 
開發者ID:lightblue-platform,項目名稱:lightblue-mongo,代碼行數:48,代碼來源:MongoReadPreference.java

示例4: SecondaryBlogDao

import com.mongodb.ReadPreference; //導入方法依賴的package包/類
public SecondaryBlogDao() {
    super(Blog.class);
    //set ReadPreference to secondaryPreferred
    super.setReadPreference(ReadPreference.secondaryPreferred());
}
 
開發者ID:xbwen,項目名稱:bugu-mongo,代碼行數:6,代碼來源:SecondaryBlogDao.java


注:本文中的com.mongodb.ReadPreference.secondaryPreferred方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。