本文整理匯總了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;
}
}
示例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;
}
示例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);
}
}
示例4: SecondaryBlogDao
import com.mongodb.ReadPreference; //導入方法依賴的package包/類
public SecondaryBlogDao() {
super(Blog.class);
//set ReadPreference to secondaryPreferred
super.setReadPreference(ReadPreference.secondaryPreferred());
}