@Immutable public abstract class ReadPreference extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
java.util.List<ServerDescription> |
choose(ClusterDescription clusterDescription)
Chooses the servers from the given cluster than match this read preference.
|
protected abstract java.util.List<ServerDescription> |
chooseForNonReplicaSet(ClusterDescription clusterDescription) |
protected abstract java.util.List<ServerDescription> |
chooseForReplicaSet(ClusterDescription clusterDescription) |
abstract java.lang.String |
getName()
Gets the name of this read preference.
|
abstract boolean |
isSlaveOk()
True if this read preference allows reading from a secondary member of a replica set.
|
static ReadPreference |
nearest()
Gets a read preference that forces reads to a primary or a secondary.
|
static TaggableReadPreference |
nearest(java.util.List<TagSet> tagSetList)
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)
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 |
nearest(long maxStaleness,
java.util.concurrent.TimeUnit timeUnit)
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)
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)
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 ReadPreference |
primary()
Gets a read preference that forces read to the primary.
|
static ReadPreference |
primaryPreferred()
Gets a read preference that forces reads to the primary if available, otherwise to a secondary.
|
static TaggableReadPreference |
primaryPreferred(java.util.List<TagSet> tagSetList)
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)
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 |
primaryPreferred(long maxStaleness,
java.util.concurrent.TimeUnit timeUnit)
Gets a read preference that forces reads to the primary if available, otherwise to a secondary.
|
static TaggableReadPreference |
primaryPreferred(TagSet tagSet)
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)
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 ReadPreference |
secondary()
Gets a read preference that forces reads to a secondary.
|
static TaggableReadPreference |
secondary(java.util.List<TagSet> tagSetList)
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)
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 |
secondary(long maxStaleness,
java.util.concurrent.TimeUnit timeUnit)
Gets a read preference that forces reads to a secondary that is less stale than the given maximum.
|
static TaggableReadPreference |
secondary(TagSet tagSet)
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)
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 ReadPreference |
secondaryPreferred()
Gets a read preference that forces reads to a secondary if one is available, otherwise to the primary.
|
static TaggableReadPreference |
secondaryPreferred(java.util.List<TagSet> tagSetList)
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)
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(long maxStaleness,
java.util.concurrent.TimeUnit timeUnit)
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)
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)
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.
|
abstract BsonDocument |
toDocument()
Gets a document representing this read preference in the wire protocol.
|
static ReadPreference |
valueOf(java.lang.String name)
Creates a read preference from the given read preference name.
|
static TaggableReadPreference |
valueOf(java.lang.String name,
java.util.List<TagSet> tagSetList)
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)
Creates a taggable read preference from the given read preference name, list of tag sets, and max allowable staleness of secondaries.
|
public abstract boolean isSlaveOk()
public abstract java.lang.String getName()
public abstract BsonDocument toDocument()
public final java.util.List<ServerDescription> choose(ClusterDescription clusterDescription)
clusterDescription
- the cluster descriptionprotected abstract java.util.List<ServerDescription> chooseForNonReplicaSet(ClusterDescription clusterDescription)
protected abstract java.util.List<ServerDescription> chooseForReplicaSet(ClusterDescription clusterDescription)
public static ReadPreference primary()
public static ReadPreference primaryPreferred()
public static ReadPreference secondary()
public static ReadPreference secondaryPreferred()
public static ReadPreference nearest()
public static ReadPreference primaryPreferred(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static ReadPreference secondary(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static ReadPreference secondaryPreferred(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
*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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static ReadPreference nearest(long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static TaggableReadPreference primaryPreferred(TagSet tagSet)
tagSet
- the set of tags to limit the list of secondaries to.public static TaggableReadPreference secondary(TagSet tagSet)
tagSet
- the set of tags to limit the list of secondaries topublic static TaggableReadPreference secondaryPreferred(TagSet tagSet)
tagSet
- the set of tags to limit the list of secondaries topublic static TaggableReadPreference nearest(TagSet tagSet)
tagSet
- the set of tags to limit the list of secondaries topublic static TaggableReadPreference primaryPreferred(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static TaggableReadPreference secondary(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static TaggableReadPreference secondaryPreferred(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
*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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static TaggableReadPreference nearest(TagSet tagSet, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static TaggableReadPreference primaryPreferred(java.util.List<TagSet> tagSetList)
tagSetList
- the list of tag sets to limit the list of secondaries topublic static TaggableReadPreference secondary(java.util.List<TagSet> tagSetList)
tagSetList
- the list of tag sets to limit the list of secondaries topublic static TaggableReadPreference secondaryPreferred(java.util.List<TagSet> tagSetList)
tagSetList
- the list of tag sets to limit the list of secondaries topublic static TaggableReadPreference nearest(java.util.List<TagSet> tagSetList)
tagSetList
- the list of tag sets to limit the list of secondaries topublic static TaggableReadPreference primaryPreferred(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static TaggableReadPreference secondary(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static TaggableReadPreference secondaryPreferred(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static TaggableReadPreference nearest(java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)
public static ReadPreference valueOf(java.lang.String name)
name
- the name of the read preferencepublic static TaggableReadPreference valueOf(java.lang.String name, java.util.List<TagSet> tagSetList)
name
- the name of the read preferencetagSetList
- the list of tag setspublic static TaggableReadPreference valueOf(java.lang.String name, java.util.List<TagSet> tagSetList, long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
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.
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 maxStalenessTaggableReadPreference.getMaxStaleness(TimeUnit)