@@ -62,7 +62,7 @@ public static class Builder {
6262 private int heartbeatConnectTimeout = Integer .parseInt (System .getProperty ("com.mongodb.updaterConnectTimeoutMS" , "20000" ));
6363 private int heartbeatSocketTimeout = Integer .parseInt (System .getProperty ("com.mongodb.updaterSocketTimeoutMS" , "20000" ));
6464 private int heartbeatThreadCount ;
65- private int acceptableLatencyDifference = Integer .parseInt (System .getProperty ("com.mongodb.slaveAcceptableLatencyMS" , "15" ));
65+ private int localThreshold = Integer .parseInt (System .getProperty ("com.mongodb.slaveAcceptableLatencyMS" , "15" ));
6666 private String requiredReplicaSetName ;
6767
6868 /**
@@ -167,6 +167,24 @@ public Builder heartbeatThreadCount(final int heartbeatThreadCount) {
167167 return this ;
168168 }
169169
170+ /**
171+ * Sets the local threshold.
172+ *
173+ * @param localThreshold the threshold in milliseconds
174+ * @return {@code this}
175+ * @throws IllegalArgumentException if localThreshold < 0
176+ * @see com.mongodb.MongoClientOptions#getLocalThreshold()
177+ * @since 2.13.0
178+ */
179+ @ Deprecated
180+ public Builder localThreshold (final int localThreshold ) {
181+ if (localThreshold < 0 ) {
182+ throw new IllegalArgumentException ("localThreshold must be greater than or equal to 0" );
183+ }
184+ this .localThreshold = localThreshold ;
185+ return this ;
186+ }
187+
170188 /**
171189 * Sets the acceptable latency difference.
172190 *
@@ -175,12 +193,14 @@ public Builder heartbeatThreadCount(final int heartbeatThreadCount) {
175193 * @throws IllegalArgumentException if acceptableLatencyDifference < 0
176194 * @see com.mongodb.MongoClientOptions#getAcceptableLatencyDifference()
177195 * @since 2.12.0
196+ * @deprecated Use {@link #localThreshold(int)}
178197 */
198+ @ Deprecated
179199 public Builder acceptableLatencyDifference (final int acceptableLatencyDifference ) {
180200 if (acceptableLatencyDifference < 0 ) {
181201 throw new IllegalArgumentException ("acceptableLatencyDifference must be greater than or equal to 0" );
182202 }
183- this .acceptableLatencyDifference = acceptableLatencyDifference ;
203+ this .localThreshold = acceptableLatencyDifference ;
184204 return this ;
185205 }
186206
@@ -808,6 +828,27 @@ public int getHeartbeatThreadCount() {
808828 return heartbeatThreadCount ;
809829 }
810830
831+ /**
832+ * <p>Gets the local threshold. When choosing among multiple MongoDB servers to send a request, the MongoClient will only
833+ * send that request to a server whose ping time is less than or equal to the server with the fastest ping time plus the local
834+ * threshold.</p>
835+ *
836+ * <p>For example, let's say that the client is choosing a server to send a query when the read preference is {@code
837+ * ReadPreference.secondary()}, and that there are three secondaries, server1, server2, and server3, whose ping times are 10, 15, and 16
838+ * milliseconds, respectively. With a local threshold of 5 milliseconds, the client will send the query to either
839+ * server1 or server2 (randomly selecting between the two).
840+ * </p>
841+ *
842+ * <p> The default value is 15 milliseconds.</p>
843+ *
844+ * @return the local threshold, in milliseconds
845+ * @since 2.13.0
846+ * @mongodb.driver.manual reference/program/mongos/#cmdoption--localThreshold Local Threshold
847+ */
848+ public int getLocalThreshold () {
849+ return localThreshold ;
850+ }
851+
811852 /**
812853 * <p>Gets the acceptable latency difference. When choosing among multiple MongoDB servers to send a request, the MongoClient will only
813854 * send that request to a server whose ping time is less than or equal to the server with the fastest ping time plus the acceptable
@@ -820,9 +861,11 @@ public int getHeartbeatThreadCount() {
820861 *
821862 * @return the acceptable latency difference, in milliseconds
822863 * @since 2.12.0
864+ * @deprecated Use {@link MongoClientOptions#getLocalThreshold()} instead
823865 */
866+ @ Deprecated
824867 public int getAcceptableLatencyDifference () {
825- return acceptableLatencyDifference ;
868+ return localThreshold ;
826869 }
827870
828871 /**
@@ -850,7 +893,7 @@ public boolean equals(final Object o) {
850893
851894 MongoClientOptions that = (MongoClientOptions ) o ;
852895
853- if (acceptableLatencyDifference != that .acceptableLatencyDifference ) {
896+ if (localThreshold != that .localThreshold ) {
854897 return false ;
855898 }
856899 if (alwaysUseMBeans != that .alwaysUseMBeans ) {
@@ -959,7 +1002,7 @@ public int hashCode() {
9591002 result = 31 * result + heartbeatConnectTimeout ;
9601003 result = 31 * result + heartbeatSocketTimeout ;
9611004 result = 31 * result + heartbeatThreadCount ;
962- result = 31 * result + acceptableLatencyDifference ;
1005+ result = 31 * result + localThreshold ;
9631006 result = 31 * result + (requiredReplicaSetName != null ? requiredReplicaSetName .hashCode () : 0 );
9641007 return result ;
9651008 }
@@ -988,7 +1031,7 @@ public String toString() {
9881031 + ", heartbeatConnectTimeout=" + heartbeatConnectTimeout
9891032 + ", heartbeatSocketTimeout=" + heartbeatSocketTimeout
9901033 + ", heartbeatThreadCount=" + heartbeatThreadCount
991- + ", acceptableLatencyDifference =" + acceptableLatencyDifference
1034+ + ", localThreshold =" + localThreshold
9921035 + ", requiredReplicaSetName=" + requiredReplicaSetName
9931036 + '}' ;
9941037 }
@@ -1018,7 +1061,7 @@ private MongoClientOptions(final Builder builder) {
10181061 heartbeatConnectTimeout = builder .heartbeatConnectTimeout ;
10191062 heartbeatSocketTimeout = builder .heartbeatSocketTimeout ;
10201063 heartbeatThreadCount = builder .heartbeatThreadCount ;
1021- acceptableLatencyDifference = builder .acceptableLatencyDifference ;
1064+ localThreshold = builder .localThreshold ;
10221065 requiredReplicaSetName = builder .requiredReplicaSetName ;
10231066 }
10241067
@@ -1047,6 +1090,6 @@ private MongoClientOptions(final Builder builder) {
10471090 private final int heartbeatConnectTimeout ;
10481091 private final int heartbeatSocketTimeout ;
10491092 private final int heartbeatThreadCount ;
1050- private final int acceptableLatencyDifference ;
1093+ private final int localThreshold ;
10511094 private final String requiredReplicaSetName ;
10521095}
0 commit comments