Class ReadPreference
- java.lang.Object
-
- com.mongodb.ReadPreference
-
- Direct Known Subclasses:
TaggableReadPreference
@Immutable @Deprecated(since="2021-05-27") public abstract class ReadPreference extends java.lang.Object
Deprecated.Usage of this API is not supported in AEM as a Cloud Service.A class that represents preferred replica set members to which a query or command can be sent.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.List<ServerDescription>
choose(ClusterDescription clusterDescription)
Deprecated.Chooses the servers from the given cluster than match this read preference.abstract java.lang.String
getName()
Deprecated.Gets the name of this read preference.abstract boolean
isSlaveOk()
Deprecated.True if this read preference allows reading from a secondary member of a replica set.static ReadPreference
nearest()
Deprecated.Gets a read preference that forces reads to a primary or a secondary.static ReadPreference
nearest(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a primary or a secondary that is less stale than the given maximum.static TaggableReadPreference
nearest(TagSet tagSet)
Deprecated.Gets a read preference that forces reads to the primary or a secondary with the given set of tags.static TaggableReadPreference
nearest(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to the primary or a secondary with the given set of tags that is less stale than the given maximum.static TaggableReadPreference
nearest(java.util.List<TagSet> tagSetList)
Deprecated.Gets a read preference that forces reads to the primary or a secondary with one of the given sets of tags.static TaggableReadPreference
nearest(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to the primary or a secondary with one of the given sets of tags that is less stale than the given maximum.static ReadPreference
primary()
Deprecated.Gets a read preference that forces read to the primary.static ReadPreference
primaryPreferred()
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary.static ReadPreference
primaryPreferred(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary.static TaggableReadPreference
primaryPreferred(TagSet tagSet)
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary with the given set of tags.static TaggableReadPreference
primaryPreferred(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary with the given set of tags that is less stale than the given maximum.static TaggableReadPreference
primaryPreferred(java.util.List<TagSet> tagSetList)
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary with one of the given sets of tags.static TaggableReadPreference
primaryPreferred(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary with one of the given sets of tags that is less stale than the given maximum.static ReadPreference
secondary()
Deprecated.Gets a read preference that forces reads to a secondary.static ReadPreference
secondary(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary that is less stale than the given maximum.static TaggableReadPreference
secondary(TagSet tagSet)
Deprecated.Gets a read preference that forces reads to a secondary with the given set of tags.static TaggableReadPreference
secondary(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary with the given set of tags that is less stale than the given maximum.static TaggableReadPreference
secondary(java.util.List<TagSet> tagSetList)
Deprecated.Gets a read preference that forces reads to a secondary with one of the given sets of tags.static TaggableReadPreference
secondary(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary with one of the given sets of tags that is less stale than the given maximum.static ReadPreference
secondaryPreferred()
Deprecated.Gets a read preference that forces reads to a secondary if one is available, otherwise to the primary.static ReadPreference
secondaryPreferred(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary that is less stale than the given maximumm if one is available, otherwise to the primary.static TaggableReadPreference
secondaryPreferred(TagSet tagSet)
Deprecated.Gets a read preference that forces reads to a secondary with the given set of tags, or the primary is none are available.static TaggableReadPreference
secondaryPreferred(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary with the given set of tags that is less stale than the given maximum, or the primary is none are available.static TaggableReadPreference
secondaryPreferred(java.util.List<TagSet> tagSetList)
Deprecated.Gets a read preference that forces reads to a secondary with one of the given sets of tags.static TaggableReadPreference
secondaryPreferred(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary with one of the given sets of tags that is less stale than the given maximum.abstract BsonDocument
toDocument()
Deprecated.Gets a document representing this read preference in the wire protocol.static ReadPreference
valueOf(java.lang.String name)
Deprecated.Creates a read preference from the given read preference name.static TaggableReadPreference
valueOf(java.lang.String name, java.util.List<TagSet> tagSetList)
Deprecated.Creates a taggable read preference from the given read preference name and list of tag sets.static TaggableReadPreference
valueOf(java.lang.String name, java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Creates a taggable read preference from the given read preference name, list of tag sets, and max allowable staleness of secondaries.
-
-
-
Method Detail
-
isSlaveOk
public abstract boolean isSlaveOk()
Deprecated.True if this read preference allows reading from a secondary member of a replica set.- Returns:
- if reading from a secondary is ok
-
getName
public abstract java.lang.String getName()
Deprecated.Gets the name of this read preference.- Returns:
- the name
-
toDocument
public abstract BsonDocument toDocument()
Deprecated.Gets a document representing this read preference in the wire protocol.- Returns:
- the document
-
choose
public final java.util.List<ServerDescription> choose(ClusterDescription clusterDescription)
Deprecated.Chooses the servers from the given cluster than match this read preference.- Parameters:
clusterDescription
- the cluster description- Returns:
- a list of matching server descriptions, which may be empty but may not be null
-
primary
public static ReadPreference primary()
Deprecated.Gets a read preference that forces read to the primary.- Returns:
- ReadPreference which reads from primary only
-
primaryPreferred
public static ReadPreference primaryPreferred()
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary.- Returns:
- ReadPreference which reads primary if available.
-
secondary
public static ReadPreference secondary()
Deprecated.Gets a read preference that forces reads to a secondary.- Returns:
- ReadPreference which reads secondary.
-
secondaryPreferred
public static ReadPreference secondaryPreferred()
Deprecated.Gets a read preference that forces reads to a secondary if one is available, otherwise to the primary.- Returns:
- ReadPreference which reads secondary if available, otherwise from primary.
-
nearest
public static ReadPreference nearest()
Deprecated.Gets a read preference that forces reads to a primary or a secondary.- Returns:
- ReadPreference which reads nearest
-
primaryPreferred
public static ReadPreference primaryPreferred(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary.- Parameters:
maxStaleness
- 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:
- ReadPreference which reads primary if available.
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
secondary
public static ReadPreference secondary(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary that is less stale than the given maximum.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:
maxStaleness
- 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:
- ReadPreference which reads secondary.
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
secondaryPreferred
public static ReadPreference secondaryPreferred(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary that is less stale than the given maximumm if one is available, otherwise to the primary.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:
maxStaleness
- 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:
- ReadPreference which reads secondary if available, otherwise from primary.
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
nearest
public static ReadPreference nearest(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a primary or a secondary that is less stale than the given maximum.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:
maxStaleness
- 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:
- ReadPreference which reads nearest
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
primaryPreferred
public static TaggableReadPreference primaryPreferred(TagSet tagSet)
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary with the given set of tags.- Parameters:
tagSet
- the set of tags to limit the list of secondaries to.- Returns:
- ReadPreference which reads primary if available, otherwise a secondary respective of tags.\
- Since:
- 2.13
-
secondary
public static TaggableReadPreference secondary(TagSet tagSet)
Deprecated.Gets a read preference that forces reads to a secondary with the given set of tags.- Parameters:
tagSet
- the set of tags to limit the list of secondaries to- Returns:
- ReadPreference which reads secondary respective of tags.
- Since:
- 2.13
-
secondaryPreferred
public static TaggableReadPreference secondaryPreferred(TagSet tagSet)
Deprecated.Gets a read preference that forces reads to a secondary with the given set of tags, or the primary is none are available.- Parameters:
tagSet
- the set of tags to limit the list of secondaries to- Returns:
- ReadPreference which reads secondary if available respective of tags, otherwise from primary irrespective of tags.
- Since:
- 2.13
-
nearest
public static TaggableReadPreference nearest(TagSet tagSet)
Deprecated.Gets a read preference that forces reads to the primary or a secondary with the given set of tags.- Parameters:
tagSet
- the set of tags to limit the list of secondaries to- Returns:
- ReadPreference which reads nearest node respective of tags.
- Since:
- 2.13
-
primaryPreferred
public static TaggableReadPreference primaryPreferred(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary with the given set of tags that is less stale than the given maximum.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:
tagSet
- the set of tags to limit the list of secondaries to.maxStaleness
- 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:
- ReadPreference which reads primary if available, otherwise a secondary respective of tags.\
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
secondary
public static TaggableReadPreference secondary(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary with the given set of tags that is less stale than the given maximum.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:
tagSet
- the set of tags to limit the list of secondaries tomaxStaleness
- 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:
- ReadPreference which reads secondary respective of tags.
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
secondaryPreferred
public static TaggableReadPreference secondaryPreferred(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary with the given set of tags that is less stale than the given maximum, or the primary is none are available.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:
tagSet
- the set of tags to limit the list of secondaries tomaxStaleness
- 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:
- ReadPreference which reads secondary if available respective of tags, otherwise from primary irrespective of tags.
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
nearest
public static TaggableReadPreference nearest(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to the primary or a secondary with the given set of tags that is less stale than the given maximum.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:
tagSet
- the set of tags to limit the list of secondaries tomaxStaleness
- 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:
- ReadPreference which reads nearest node respective of tags.
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
primaryPreferred
public static TaggableReadPreference primaryPreferred(java.util.List<TagSet> tagSetList)
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary with one of the given sets of tags. The driver will look for a secondary with each tag set in the given list, stopping after one is found, or failing if no secondary can be found that matches any of the tag sets in the list.- Parameters:
tagSetList
- the list of tag sets to limit the list of secondaries to- Returns:
- ReadPreference which reads primary if available, otherwise a secondary respective of tags.
- Since:
- 2.13
-
secondary
public static TaggableReadPreference secondary(java.util.List<TagSet> tagSetList)
Deprecated.Gets a read preference that forces reads to a secondary with one of the given sets of tags. The driver will look for a secondary with each tag set in the given list, stopping after one is found, or failing if no secondary can be found that matches any of the tag sets in the list.- Parameters:
tagSetList
- the list of tag sets to limit the list of secondaries to- Returns:
- ReadPreference which reads secondary respective of tags.
- Since:
- 2.13
-
secondaryPreferred
public static TaggableReadPreference secondaryPreferred(java.util.List<TagSet> tagSetList)
Deprecated.Gets a read preference that forces reads to a secondary with one of the given sets of tags. The driver will look for a secondary with each tag set in the given list, stopping after one is found, or the primary if none are available.- Parameters:
tagSetList
- the list of tag sets to limit the list of secondaries to- Returns:
- ReadPreference which reads secondary if available respective of tags, otherwise from primary irrespective of tags.
- Since:
- 2.13
-
nearest
public static TaggableReadPreference nearest(java.util.List<TagSet> tagSetList)
Deprecated.Gets a read preference that forces reads to the primary or a secondary with one of the given sets of tags. The driver will look for a secondary with each tag set in the given list, stopping after one is found, or the primary if none are available.- Parameters:
tagSetList
- the list of tag sets to limit the list of secondaries to- Returns:
- ReadPreference which reads nearest node respective of tags.
- Since:
- 2.13
-
primaryPreferred
public static TaggableReadPreference primaryPreferred(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to the primary if available, otherwise to a secondary with one of the given sets of tags that is less stale than the given maximum.The driver will look for a secondary with each tag set in the given list, stopping after one is found, or failing if no secondary can be found that matches any of the tag sets in the list.
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:
tagSetList
- the list of tag sets to limit the list of secondaries tomaxStaleness
- 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:
- ReadPreference which reads primary if available, otherwise a secondary respective of tags.
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
secondary
public static TaggableReadPreference secondary(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary with one of the given sets of tags that is less stale than the given maximum.The driver will look for a secondary with each tag set in the given list, stopping after one is found, or failing if no secondary can be found that matches any of the tag sets in the list.
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:
tagSetList
- the list of tag sets to limit the list of secondaries tomaxStaleness
- 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:
- ReadPreference which reads secondary respective of tags.
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
secondaryPreferred
public static TaggableReadPreference secondaryPreferred(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to a secondary with one of the given sets of tags that is less stale than the given maximum.The driver will look for a secondary with each tag set in the given list, stopping after one is found, or the primary if none are available.
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:
tagSetList
- the list of tag sets to limit the list of secondaries tomaxStaleness
- 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:
- ReadPreference which reads secondary if available respective of tags, otherwise from primary irrespective of tags.
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
nearest
public static TaggableReadPreference nearest(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Gets a read preference that forces reads to the primary or a secondary with one of the given sets of tags that is less stale than the given maximum.The driver will look for a secondary with each tag set in the given list, stopping after one is found, or the primary if none are available.
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:
tagSetList
- the list of tag sets to limit the list of secondaries tomaxStaleness
- 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:
- ReadPreference which reads nearest node respective of tags.
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
valueOf
public static ReadPreference valueOf(java.lang.String name)
Deprecated.Creates a read preference from the given read preference name.- Parameters:
name
- the name of the read preference- Returns:
- the read preference
-
valueOf
public static TaggableReadPreference valueOf(java.lang.String name, java.util.List<TagSet> tagSetList)
Deprecated.Creates a taggable read preference from the given read preference name and list of tag sets.- Parameters:
name
- the name of the read preferencetagSetList
- the list of tag sets- Returns:
- the taggable read preference
- Since:
- 2.13
-
valueOf
public static TaggableReadPreference valueOf(java.lang.String name, java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
Deprecated.Creates a taggable read preference from the given read preference name, list of tag sets, and max allowable staleness of 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:
name
- the name of the read preferencetagSetList
- the list of tag setsmaxStaleness
- 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:
- the taggable read preference
- Since:
- 3.4
- See Also:
TaggableReadPreference.getMaxStaleness(TimeUnit)
-
-