Package com.mongodb
Class TaggableReadPreference
- java.lang.Object
-
- com.mongodb.ReadPreference
-
- com.mongodb.TaggableReadPreference
-
@Immutable public abstract class TaggableReadPreference extends ReadPreference
Abstract class for all preference which can be combined with tags
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected List<ServerDescription>
chooseForNonReplicaSet(ClusterDescription clusterDescription)
protected static ClusterDescription
copyClusterDescription(ClusterDescription clusterDescription, List<ServerDescription> selectedServers)
boolean
equals(Object o)
ReadPreferenceHedgeOptions
getHedgeOptions()
Gets the hedge options.Long
getMaxStaleness(TimeUnit timeUnit)
Gets the maximum acceptable staleness of a secondary in order to be considered for read operations.List<TagSet>
getTagSetList()
Gets the list of tag sets as a list ofTagSet
instances.int
hashCode()
boolean
isSlaveOk()
True if this read preference allows reading from a secondary member of a replica set.protected List<ServerDescription>
selectFreshServers(ClusterDescription clusterDescription, List<ServerDescription> servers)
BsonDocument
toDocument()
Gets a document representing this read preference in the wire protocol.String
toString()
abstract TaggableReadPreference
withHedgeOptions(ReadPreferenceHedgeOptions hedgeOptions)
Create a new ReadPreference instance with hedge options.abstract TaggableReadPreference
withMaxStalenessMS(Long maxStalenessMS, TimeUnit timeUnit)
Create a new ReadPreference instance with the maximum acceptable staleness of a secondary in order to be considered for read operations.abstract TaggableReadPreference
withTagSet(TagSet tagSet)
Create a new ReadPreference instance with a new tag set.abstract TaggableReadPreference
withTagSetList(List<TagSet> tagSet)
Create a new ReadPreference instance with a new tag set list.-
Methods inherited from class com.mongodb.ReadPreference
choose, chooseForReplicaSet, getName, nearest, nearest, nearest, nearest, nearest, nearest, primary, primaryPreferred, primaryPreferred, primaryPreferred, primaryPreferred, primaryPreferred, primaryPreferred, secondary, secondary, secondary, secondary, secondary, secondary, secondaryPreferred, secondaryPreferred, secondaryPreferred, secondaryPreferred, secondaryPreferred, secondaryPreferred, valueOf, valueOf, valueOf
-
-
-
-
Method Detail
-
withTagSet
public abstract TaggableReadPreference withTagSet(TagSet tagSet)
Description copied from class:ReadPreference
Create a new ReadPreference instance with a new tag set.Note: this method is not supported for a primary read preference.
- Specified by:
withTagSet
in classReadPreference
- Parameters:
tagSet
- the new tag set- Returns:
- a new ReadPreference instance with a new tag set
-
withTagSetList
public abstract TaggableReadPreference withTagSetList(List<TagSet> tagSet)
Description copied from class:ReadPreference
Create a new ReadPreference instance with a new tag set list.Note: this method is not supported for a primary read preference.
- Specified by:
withTagSetList
in classReadPreference
- Parameters:
tagSet
- the new tag set list- Returns:
- a new ReadPreference instance with a new tag set list
-
withMaxStalenessMS
public abstract TaggableReadPreference withMaxStalenessMS(Long maxStalenessMS, TimeUnit timeUnit)
Description copied from class:ReadPreference
Create a new ReadPreference instance with the maximum acceptable staleness of a secondary in order to be considered for read operations.Note: this method is not supported for a primary read preference.
- Specified by:
withMaxStalenessMS
in classReadPreference
- Parameters:
maxStalenessMS
- the max allowable staleness of secondaries. The minimum value is either 90 seconds, or the heartbeat frequency plus 10 seconds, whichever is greatest.timeUnit
- the time unit of maxStaleness- Returns:
- a new ReadPreference instance with a new maximum allowable staleness
-
withHedgeOptions
public abstract TaggableReadPreference withHedgeOptions(ReadPreferenceHedgeOptions hedgeOptions)
Description copied from class:ReadPreference
Create a new ReadPreference instance with hedge options.Note: this method is not supported for a primary read preference.
- Specified by:
withHedgeOptions
in classReadPreference
- Parameters:
hedgeOptions
- the hedge options- Returns:
- a new ReadPreference instance with hedge options
-
isSlaveOk
public boolean isSlaveOk()
Description copied from class:ReadPreference
True if this read preference allows reading from a secondary member of a replica set.- Specified by:
isSlaveOk
in classReadPreference
- Returns:
- if reading from a secondary is ok
-
toDocument
public BsonDocument toDocument()
Description copied from class:ReadPreference
Gets a document representing this read preference in the wire protocol.- Specified by:
toDocument
in classReadPreference
- Returns:
- the document
-
getTagSetList
public List<TagSet> getTagSetList()
Gets the list of tag sets as a list ofTagSet
instances.- Returns:
- the list of tag sets
- Since:
- 2.13
-
getMaxStaleness
@Nullable public Long getMaxStaleness(TimeUnit timeUnit)
Gets the maximum acceptable staleness of a secondary in order to be considered for read operations.The maximum staleness feature is designed to prevent badly-lagging servers from being selected. The staleness estimate is imprecise and shouldn't be used to try to select "up-to-date" secondaries.
The driver estimates the staleness of each secondary, based on lastWriteDate values provided in server isMaster responses, and selects only those secondaries whose staleness is less than or equal to maxStaleness.
- Parameters:
timeUnit
- the time unit in which to return the value- Returns:
- the maximum acceptable staleness in the given time unit, or null if the value is not set
- Since:
- 3.4
- Since server release
- 3.4
-
getHedgeOptions
@Nullable public ReadPreferenceHedgeOptions getHedgeOptions()
Gets the hedge options.- Returns:
- the hedge options
- Since:
- 4.1
- Since server release
- 4.4
-
chooseForNonReplicaSet
protected List<ServerDescription> chooseForNonReplicaSet(ClusterDescription clusterDescription)
- Specified by:
chooseForNonReplicaSet
in classReadPreference
-
copyClusterDescription
protected static ClusterDescription copyClusterDescription(ClusterDescription clusterDescription, List<ServerDescription> selectedServers)
-
selectFreshServers
protected List<ServerDescription> selectFreshServers(ClusterDescription clusterDescription, List<ServerDescription> servers)
-
-