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


Java ReadPreference.primaryPreferred方法代碼示例

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


在下文中一共展示了ReadPreference.primaryPreferred方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getMongoReadPreference

import com.mongodb.ReadPreference; //導入方法依賴的package包/類
<T extends Document> ReadPreference getMongoReadPreference(Collection<T> collection,
                                                           String parentId,
                                                           DocumentReadPreference preference) {
    switch(preference){
        case PRIMARY:
            return ReadPreference.primary();
        case PREFER_PRIMARY :
            return ReadPreference.primaryPreferred();
        case PREFER_SECONDARY :
            return getConfiguredReadPreference(collection);
        case PREFER_SECONDARY_IF_OLD_ENOUGH:
            if(collection != Collection.NODES){
                return ReadPreference.primary();
            }

            //Default to primary preferred such that in case primary is being elected
            //we can still read from secondary
            //TODO REVIEW Would that be safe
            ReadPreference readPreference = ReadPreference.primaryPreferred();
            if (parentId != null) {
                long replicationSafeLimit = getTime() - maxReplicationLagMillis;
                NodeDocument cachedDoc = (NodeDocument) getIfCached(collection, parentId);
                if (cachedDoc != null && !cachedDoc.hasBeenModifiedSince(replicationSafeLimit)) {

                    //If parent has been modified loooong time back then there children
                    //would also have not be modified. In that case we can read from secondary
                    readPreference = getConfiguredReadPreference(collection);
                }
            }
            return readPreference;
        default:
            throw new IllegalArgumentException("Unsupported usage " + preference);
    }
}
 
開發者ID:denismo,項目名稱:jackrabbit-dynamodb-store,代碼行數:35,代碼來源:MongoDocumentStore.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


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