本文整理匯總了Java中com.mongodb.ReadPreference.secondary方法的典型用法代碼示例。如果您正苦於以下問題:Java ReadPreference.secondary方法的具體用法?Java ReadPreference.secondary怎麽用?Java ReadPreference.secondary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mongodb.ReadPreference
的用法示例。
在下文中一共展示了ReadPreference.secondary方法的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;
}
}
示例2: testMongoReadPreferencesWithAge
import com.mongodb.ReadPreference; //導入方法依賴的package包/類
@Test
public void testMongoReadPreferencesWithAge() throws Exception{
//Change the default
ReadPreference testPref = ReadPreference.secondary();
mongoDS.getDBCollection(NODES).getDB().setReadPreference(testPref);
NodeBuilder b1 = nodeStore.getRoot().builder();
b1.child("x").child("y");
nodeStore.merge(b1, EmptyHook.INSTANCE, CommitInfo.EMPTY);
String id = Utils.getIdFromPath("/x/y");
String parentId = Utils.getParentId(id);
mongoDS.invalidateCache(NODES,id);
//For modifiedTime < replicationLag primary should be preferred
assertEquals(ReadPreference.primaryPreferred(),
mongoDS.getMongoReadPreference(NODES,parentId, DocumentReadPreference.PREFER_SECONDARY_IF_OLD_ENOUGH));
//Going into future to make parent /x old enough
clock.waitUntil(Revision.getCurrentTimestamp() + replicationLag);
mongoDS.setClock(clock);
//For old modified nodes secondaries should be preferred
assertEquals(testPref,
mongoDS.getMongoReadPreference(NODES, parentId, DocumentReadPreference.PREFER_SECONDARY_IF_OLD_ENOUGH));
}
示例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);
}
}