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


Java ReadPreference.valueOf方法代碼示例

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


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

示例1: setReadWriteMode

import com.mongodb.ReadPreference; //導入方法依賴的package包/類
@Override
public void setReadWriteMode(String readWriteMode) {
    if (readWriteMode == null || readWriteMode.equals(lastReadWriteMode)) {
        return;
    }
    lastReadWriteMode = readWriteMode;
    try {
        Map<String, String> map = Splitter.on(", ").withKeyValueSeparator(":").split(readWriteMode);
        String read = map.get("read");
        if (read != null) {
            ReadPreference readPref = ReadPreference.valueOf(read);
            if (!readPref.equals(this.readPreference)) {
                this.readPreference = readPref;
            }
        }
        String write = map.get("write");
        if (write != null) {
            WriteConcern writeConcern = WriteConcern.valueOf(write);
            if (!writeConcern.equals(this.writeConcern)) {
                this.writeConcern = writeConcern;
            }
        }
    } catch (Exception e) {
        // unsupported or parse error - ignore
    }
}
 
開發者ID:denismo,項目名稱:jackrabbit-dynamodb-store,代碼行數:27,代碼來源:MemoryDocumentStore.java

示例2: ReadPreferenceParser

import com.mongodb.ReadPreference; //導入方法依賴的package包/類
ReadPreferenceParser(ConnectionString connectionString, JsonObject config) {
  ReadPreference connStringReadPreference = connectionString != null ? connectionString.getReadPreference() : null;
  if (connStringReadPreference != null) {
    // Prefer connection string's read preference
    readPreference = connStringReadPreference;
  } else {
    ReadPreference rp;
    String rps = config.getString("readPreference");
    if (rps != null) {
      JsonArray readPreferenceTags = config.getJsonArray("readPreferenceTags");
      if (readPreferenceTags == null) {
        rp = ReadPreference.valueOf(rps);
        if (rp == null) throw new IllegalArgumentException("Invalid ReadPreference " + rps);
      } else {
        // Support advanced ReadPreference Tags
        List<TagSet> tagSet = new ArrayList<>();
        readPreferenceTags.forEach(o -> {
          String tagString = (String) o;
          List<Tag> tags = Stream.of(tagString.trim().split(","))
              .map(s -> s.split(":"))
              .filter(array -> {
                if (array.length != 2) {
                  throw new IllegalArgumentException("Invalid readPreferenceTags value '" + tagString + "'");
                }
                return true;
              }).map(array -> new Tag(array[0], array[1])).collect(Collectors.toList());

          tagSet.add(new TagSet(tags));
        });
        rp = ReadPreference.valueOf(rps, tagSet);
      }
    } else {
      rp = null;
    }

    readPreference = rp;
  }
}
 
開發者ID:vert-x3,項目名稱:vertx-mongo-client,代碼行數:39,代碼來源:ReadPreferenceParser.java

示例3: getMongoReadPreference

import com.mongodb.ReadPreference; //導入方法依賴的package包/類
public static ReadPreference getMongoReadPreference( String readPrefChoiceLiteral )
{
    if( readPrefChoiceLiteral == null || readPrefChoiceLiteral.trim().isEmpty() )
        return null;  // use MongoDB default

    try
    {
        return ReadPreference.valueOf( readPrefChoiceLiteral.trim() );
    }
    catch( IllegalArgumentException ex )
    {
        // ignore, falls back to return default
    }
    return DEFAULT_PREFERENCE;  // default
}
 
開發者ID:eclipse,項目名稱:birt,代碼行數:16,代碼來源:MongoDBDriver.java

示例4: getTaggableReadPreference

import com.mongodb.ReadPreference; //導入方法依賴的package包/類
ReadPreference getTaggableReadPreference()
  {
      ReadPreference readPref = getQueryReadPreference();
      if( readPref == ReadPreference.primary() )
          return readPref;    // primary read preference mode does not apply tags
      
      DBObject tagObjects = getReadPreferenceTagsAsParsedObject();
      
      if( tagObjects == null )
          return readPref;    // no tags in read preference

List<TagSet> tagsList = new ArrayList<TagSet>( );
if ( tagObjects instanceof BasicDBList )
{
	BasicDBList tagObjectList = (BasicDBList) tagObjects;
	for ( Object obj : tagObjectList )
	{
		if ( obj instanceof DBObject )
		{
			tagsList.add( toTags( (DBObject) obj ) );
		}
		else
		{ // ignore elements that are not DBObject
			logInvalidTagValue( obj );
		}
	}
}
else
{
	tagsList.add( toTags( tagObjects ) );
}
if ( tagsList.size( ) == 0 )
{
	return readPref;
}
      
      try
      {
          return ReadPreference.valueOf( readPref.getName( ), tagsList );
      }
      catch( RuntimeException ex )
      {
          // log and ignore tags
          getLogger().info( ex.getLocalizedMessage() );
      }
      return readPref;
  }
 
開發者ID:eclipse,項目名稱:birt,代碼行數:48,代碼來源:QueryProperties.java

示例5: setReadPreference

import com.mongodb.ReadPreference; //導入方法依賴的package包/類
/** 
 * Sets a MongoDB {@link ReadPreference} on the Mongo connection. Read preferences set directly on the connection will be
 * overridden by this setting.
 * <p/>
 * The {@link com.mongodb.ReadPreference#valueOf(String)} utility method is used to resolve the passed {@code readPreference}
 * value. Some examples for the possible values are {@code nearest}, {@code primary} or {@code secondary} etc.
 * 
 * @param readPreference the name of the read preference to set
 */
public void setReadPreference(String readPreference) {
    this.readPreference = ReadPreference.valueOf(readPreference);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:13,代碼來源:MongoDbEndpoint.java


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