@Immutable public abstract class TaggableReadPreference extends ReadPreference
Modifier and Type | Class and Description |
---|---|
(package private) static class |
TaggableReadPreference.NearestReadPreference
Read from nearest node respective of tags.
|
(package private) static class |
TaggableReadPreference.PrimaryPreferredReadPreference
Read from primary if available, otherwise a secondary.
|
(package private) static class |
TaggableReadPreference.SecondaryPreferredReadPreference
Read from secondary if available, otherwise from primary, irrespective of tags.
|
(package private) static class |
TaggableReadPreference.SecondaryReadPreference
Read from secondary
|
Modifier and Type | Field and Description |
---|---|
private static int |
IDLE_WRITE_PERIOD_MS |
private java.lang.Long |
maxStalenessMS |
private static int |
SMALLEST_MAX_STALENESS_MS |
private java.util.List<TagSet> |
tagSetList |
Constructor and Description |
---|
TaggableReadPreference() |
TaggableReadPreference(java.util.List<TagSet> tagSetList,
java.lang.Long maxStaleness,
java.util.concurrent.TimeUnit timeUnit) |
Modifier and Type | Method and Description |
---|---|
protected java.util.List<ServerDescription> |
chooseForNonReplicaSet(ClusterDescription clusterDescription) |
protected static ClusterDescription |
copyClusterDescription(ClusterDescription clusterDescription,
java.util.List<ServerDescription> selectedServers) |
boolean |
equals(java.lang.Object o) |
private ServerDescription |
findMostUpToDateSecondary(ClusterDescription clusterDescription) |
private ServerDescription |
findPrimary(ClusterDescription clusterDescription) |
java.lang.Long |
getMaxStaleness(java.util.concurrent.TimeUnit timeUnit)
Gets the maximum acceptable staleness of a secondary in order to be considered for read operations.
|
private long |
getStalenessOfSecondaryRelativeToPrimary(ServerDescription primary,
ServerDescription serverDescription,
long heartbeatFrequencyMS) |
java.util.List<TagSet> |
getTagSetList()
Gets the list of tag sets as a list of
TagSet instances. |
int |
hashCode() |
boolean |
isSlaveOk()
True if this read preference allows reading from a secondary member of a replica set.
|
protected java.util.List<ServerDescription> |
selectFreshServers(ClusterDescription clusterDescription,
java.util.List<ServerDescription> servers) |
private boolean |
serversAreAllThreeDotFour(ClusterDescription clusterDescription) |
private BsonArray |
tagsListToBsonArray() |
BsonDocument |
toDocument()
Gets a document representing this read preference in the wire protocol.
|
private BsonDocument |
toDocument(TagSet tagSet) |
java.lang.String |
toString() |
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
private static final int SMALLEST_MAX_STALENESS_MS
private static final int IDLE_WRITE_PERIOD_MS
private final java.util.List<TagSet> tagSetList
private final java.lang.Long maxStalenessMS
TaggableReadPreference()
TaggableReadPreference(java.util.List<TagSet> tagSetList, java.lang.Long maxStaleness, java.util.concurrent.TimeUnit timeUnit)
public boolean isSlaveOk()
ReadPreference
isSlaveOk
in class ReadPreference
public BsonDocument toDocument()
ReadPreference
toDocument
in class ReadPreference
public java.util.List<TagSet> getTagSetList()
TagSet
instances.public java.lang.Long getMaxStaleness(java.util.concurrent.TimeUnit timeUnit)
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.
timeUnit
- the time unit in which to return the valuepublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
protected java.util.List<ServerDescription> chooseForNonReplicaSet(ClusterDescription clusterDescription)
chooseForNonReplicaSet
in class ReadPreference
protected static ClusterDescription copyClusterDescription(ClusterDescription clusterDescription, java.util.List<ServerDescription> selectedServers)
protected java.util.List<ServerDescription> selectFreshServers(ClusterDescription clusterDescription, java.util.List<ServerDescription> servers)
private long getStalenessOfSecondaryRelativeToPrimary(ServerDescription primary, ServerDescription serverDescription, long heartbeatFrequencyMS)
private ServerDescription findPrimary(ClusterDescription clusterDescription)
private ServerDescription findMostUpToDateSecondary(ClusterDescription clusterDescription)
private boolean serversAreAllThreeDotFour(ClusterDescription clusterDescription)
private BsonArray tagsListToBsonArray()
private BsonDocument toDocument(TagSet tagSet)