Skip to content

Commit 3f41bf4

Browse files
vbabaninrozza
andauthored
Deprecate timeout options. (mongodb#1346)
JAVA-5290 Co-authored-by: Ross Lawley <[email protected]>
1 parent 92f5776 commit 3f41bf4

File tree

119 files changed

+734
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+734
-87
lines changed

config/detekt/baseline.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<CurrentIssues>
55
<ID>IteratorNotThrowingNoSuchElementException:MongoCursor.kt$MongoCursor&lt;T : Any> : IteratorCloseable</ID>
66
<ID>LargeClass:MongoCollectionTest.kt$MongoCollectionTest</ID>
7-
<ID>LongMethod:FindFlowTest.kt$FindFlowTest$@Test fun shouldCallTheUnderlyingMethods()</ID>
8-
<ID>LongMethod:FindIterableTest.kt$FindIterableTest$@Test fun shouldCallTheUnderlyingMethods()</ID>
7+
<ID>LongMethod:FindFlowTest.kt$FindFlowTest$@Test @Suppress("DEPRECATION") // maxTime fun shouldCallTheUnderlyingMethods()</ID>
8+
<ID>LongMethod:FindIterableTest.kt$FindIterableTest$@Test @Suppress("DEPRECATION") // maxTime fun shouldCallTheUnderlyingMethods()</ID>
99
<ID>LongMethod:KotlinSerializerCodecTest.kt$KotlinSerializerCodecTest$@Test fun testDataClassOptionalBsonValues()</ID>
1010
<ID>MaxLineLength:MapReduceFlow.kt$MapReduceFlow$*</ID>
1111
<ID>MaxLineLength:MapReduceIterable.kt$MapReduceIterable$*</ID>

driver-core/src/main/com/mongodb/ConnectionString.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ private ReadPreference buildReadPreference(@Nullable final String readPreference
10841084
}
10851085

10861086
@Nullable
1087+
@SuppressWarnings("deprecation") //wTimeout
10871088
private WriteConcern buildWriteConcern(@Nullable final Boolean safe, @Nullable final String w,
10881089
@Nullable final Integer wTimeout,
10891090
@Nullable final Boolean journal) {
@@ -1591,7 +1592,21 @@ public Integer getConnectTimeout() {
15911592
/**
15921593
* Gets the socket timeout specified in the connection string.
15931594
* @return the socket timeout
1595+
*
1596+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
1597+
*
1598+
* <ul>
1599+
* <li>{@link MongoClientSettings.Builder#getTimeout(TimeUnit)}</li>
1600+
* <li>{@code MongoDatabase#getTimeout(TimeUnit)}</li>
1601+
* <li>{@code MongoCollection#getTimeout(TimeUnit)}</li>
1602+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
1603+
* <li>{@link com.mongodb.TransactionOptions}</li>
1604+
* </ul>
1605+
*
1606+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this socket timeout
1607+
* irrelevant. If no timeout is specified at these levels, the socket timeout will be used.
15941608
*/
1609+
@Deprecated
15951610
@Nullable
15961611
public Integer getSocketTimeout() {
15971612
return socketTimeout;

driver-core/src/main/com/mongodb/MongoClientSettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ public static final class Builder {
241241
private Builder() {
242242
}
243243

244+
@SuppressWarnings("deprecation") //readTimeout
244245
private Builder(final MongoClientSettings settings) {
245246
notNull("settings", settings);
246247
applicationName = settings.getApplicationName();
@@ -1117,6 +1118,7 @@ public String toString() {
11171118
+ '}';
11181119
}
11191120

1121+
@SuppressWarnings("deprecation") //readTimeout
11201122
private MongoClientSettings(final Builder builder) {
11211123
isTrue("timeoutMS > 0 ", builder.timeoutMS == null || builder.timeoutMS >= 0);
11221124
readPreference = builder.readPreference;

driver-core/src/main/com/mongodb/WriteConcern.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,21 @@ public WriteConcern(final String w) {
170170
* @param wTimeoutMS the wTimeout in milliseconds, which must be &gt;= 0
171171
* @mongodb.driver.manual reference/write-concern/#w-option w option
172172
* @mongodb.driver.manual reference/write-concern/#wtimeout wtimeout option
173+
*
174+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
175+
*
176+
* <ul>
177+
* <li>{@link MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
178+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
179+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
180+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
181+
* <li>{@link com.mongodb.TransactionOptions}</li>
182+
* </ul>
183+
*
184+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering wTimeoutMS irrelevant.
185+
* If no timeout is specified at these levels, the wTimeoutMS will be used.
173186
*/
187+
@Deprecated
174188
public WriteConcern(final int w, final int wTimeoutMS) {
175189
this(w, wTimeoutMS, null);
176190
}
@@ -232,7 +246,21 @@ public String getWString() {
232246
* @see #withWTimeout(long, TimeUnit)
233247
* @since 3.2
234248
* @mongodb.driver.manual core/write-concern/#timeouts wTimeout
249+
*
250+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
251+
*
252+
* <ul>
253+
* <li>{@link MongoClientSettings.Builder#getTimeout(TimeUnit)}</li>
254+
* <li>{@code MongoDatabase#getTimeout(TimeUnit)}</li>
255+
* <li>{@code MongoCollection#getTimeout(TimeUnit)}</li>
256+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
257+
* <li>{@link com.mongodb.TransactionOptions}</li>
258+
* </ul>
259+
*
260+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this wTimeoutMS irrelevant.
261+
* If no timeout is specified at these levels, the wTimeoutMS will be used.
235262
*/
263+
@Deprecated
236264
@Nullable
237265
public Integer getWTimeout(final TimeUnit timeUnit) {
238266
notNull("timeUnit", timeUnit);
@@ -384,7 +412,21 @@ public WriteConcern withJournal(@Nullable final Boolean journal) {
384412
* @see #getWTimeout(TimeUnit)
385413
* @since 3.2
386414
* @mongodb.driver.manual reference/write-concern/#wtimeout wtimeout option
415+
*
416+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
417+
*
418+
* <ul>
419+
* <li>{@link MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
420+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
421+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
422+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
423+
* <li>{@link com.mongodb.TransactionOptions}</li>
424+
* </ul>
425+
*
426+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this wTimeoutMS irrelevant.
427+
* If no timeout is specified at these levels, the wTimeoutMS will be used.
387428
*/
429+
@Deprecated
388430
public WriteConcern withWTimeout(final long wTimeout, final TimeUnit timeUnit) {
389431
notNull("timeUnit", timeUnit);
390432
long newWTimeOutMS = TimeUnit.MILLISECONDS.convert(wTimeout, timeUnit);

driver-core/src/main/com/mongodb/client/model/CreateIndexOptions.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
import com.mongodb.CreateIndexCommitQuorum;
21+
import com.mongodb.MongoClientSettings;
2122
import com.mongodb.lang.Nullable;
2223

2324
import java.util.concurrent.TimeUnit;
@@ -39,7 +40,21 @@ public class CreateIndexOptions {
3940
*
4041
* @param timeUnit the time unit to return the result in
4142
* @return the maximum execution time in the given time unit
43+
*
44+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
45+
*
46+
* <ul>
47+
* <li>{@link MongoClientSettings.Builder#getTimeout(TimeUnit)}</li>
48+
* <li>{@code MongoDatabase#getTimeout(TimeUnit)}</li>
49+
* <li>{@code MongoCollection#getTimeout(TimeUnit)}</li>
50+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
51+
* <li>{@link com.mongodb.TransactionOptions}</li>
52+
* </ul>
53+
*
54+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
55+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used.
4256
*/
57+
@Deprecated
4358
public long getMaxTime(final TimeUnit timeUnit) {
4459
notNull("timeUnit", timeUnit);
4560
return timeUnit.convert(maxTimeMS, TimeUnit.MILLISECONDS);
@@ -51,7 +66,21 @@ public long getMaxTime(final TimeUnit timeUnit) {
5166
* @param maxTime the max time
5267
* @param timeUnit the time unit, which may not be null
5368
* @return this
69+
*
70+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
71+
*
72+
* <ul>
73+
* <li>{@link MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
74+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
75+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
76+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
77+
* <li>{@link com.mongodb.TransactionOptions}</li>
78+
* </ul>
79+
*
80+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
81+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used.
5482
*/
83+
@Deprecated
5584
public CreateIndexOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
5685
notNull("timeUnit", timeUnit);
5786
this.maxTimeMS = TimeUnit.MILLISECONDS.convert(maxTime, timeUnit);

driver-core/src/main/com/mongodb/client/model/DropIndexOptions.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.mongodb.client.model;
1818

1919

20+
import com.mongodb.MongoClientSettings;
21+
2022
import java.util.concurrent.TimeUnit;
2123

2224
import static com.mongodb.assertions.Assertions.notNull;
@@ -35,7 +37,20 @@ public class DropIndexOptions {
3537
*
3638
* @param timeUnit the time unit to return the result in
3739
* @return the maximum execution time in the given time unit
40+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
41+
*
42+
* <ul>
43+
* <li>{@link MongoClientSettings.Builder#getTimeout(TimeUnit)}</li>
44+
* <li>{@code MongoDatabase#getTimeout(TimeUnit)}</li>
45+
* <li>{@code MongoCollection#getTimeout(TimeUnit)}</li>
46+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
47+
* <li>{@link com.mongodb.TransactionOptions}</li>
48+
* </ul>
49+
*
50+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
51+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used.
3852
*/
53+
@Deprecated
3954
public long getMaxTime(final TimeUnit timeUnit) {
4055
notNull("timeUnit", timeUnit);
4156
return timeUnit.convert(maxTimeMS, TimeUnit.MILLISECONDS);
@@ -47,7 +62,20 @@ public long getMaxTime(final TimeUnit timeUnit) {
4762
* @param maxTime the max time
4863
* @param timeUnit the time unit, which may not be null
4964
* @return this
65+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
66+
*
67+
* <ul>
68+
* <li>{@link MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
69+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
70+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
71+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
72+
* <li>{@link com.mongodb.TransactionOptions}</li>
73+
* </ul>
74+
*
75+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum execution time
76+
* irrelevant. If no timeout is specified at these levels, the maximum execution time will be used.
5077
*/
78+
@Deprecated
5179
public DropIndexOptions maxTime(final long maxTime, final TimeUnit timeUnit) {
5280
notNull("timeUnit", timeUnit);
5381
this.maxTimeMS = TimeUnit.MILLISECONDS.convert(maxTime, timeUnit);

driver-core/src/main/com/mongodb/connection/ConnectionPoolSettings.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.mongodb.connection;
1818

1919
import com.mongodb.ConnectionString;
20+
import com.mongodb.MongoClientSettings;
2021
import com.mongodb.annotations.Immutable;
2122
import com.mongodb.annotations.NotThreadSafe;
2223
import com.mongodb.event.ConnectionCheckOutStartedEvent;
@@ -177,7 +178,21 @@ public Builder minSize(final int minSize) {
177178
* @param timeUnit the TimeUnit for this wait period
178179
* @return this
179180
* @see #getMaxWaitTime(TimeUnit)
181+
*
182+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
183+
*
184+
* <ul>
185+
* <li>{@link MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
186+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
187+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
188+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
189+
* <li>{@link com.mongodb.TransactionOptions}</li>
190+
* </ul>
191+
*
192+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum wait time
193+
* irrelevant. If no timeout is specified at these levels, the maximum wait time will be used.
180194
*/
195+
@Deprecated
181196
public Builder maxWaitTime(final long maxWaitTime, final TimeUnit timeUnit) {
182197
this.maxWaitTimeMS = MILLISECONDS.convert(maxWaitTime, timeUnit);
183198
return this;
@@ -382,7 +397,21 @@ public int getMinSize() {
382397
* @return the maximum amount of time to wait in the given TimeUnits
383398
* @see Builder#maxWaitTime(long, TimeUnit)
384399
* @see ConnectionString#getMaxWaitTime()
400+
*
401+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
402+
*
403+
* <ul>
404+
* <li>{@link MongoClientSettings.Builder#getTimeout(TimeUnit)}</li>
405+
* <li>{@code MongoDatabase#getTimeout(TimeUnit)}</li>
406+
* <li>{@code MongoCollection#getTimeout(TimeUnit)}</li>
407+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
408+
* <li>{@link com.mongodb.TransactionOptions}</li>
409+
* </ul>
410+
*
411+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this maximum wait time
412+
* irrelevant. If no timeout is specified at these levels, the maximum wait time will be used.
385413
*/
414+
@Deprecated
386415
public long getMaxWaitTime(final TimeUnit timeUnit) {
387416
return timeUnit.convert(maxWaitTimeMS, MILLISECONDS);
388417
}

driver-core/src/main/com/mongodb/connection/SocketSettings.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.mongodb.Block;
2020
import com.mongodb.ConnectionString;
21+
import com.mongodb.MongoClientSettings;
2122
import com.mongodb.annotations.Immutable;
2223

2324
import java.util.Objects;
@@ -113,7 +114,21 @@ public Builder connectTimeout(final long connectTimeout, final TimeUnit timeUnit
113114
* @param timeUnit the time unit
114115
* @return this
115116
* @see #getReadTimeout(TimeUnit)
117+
*
118+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
119+
*
120+
* <ul>
121+
* <li>{@link MongoClientSettings.Builder#timeout(long, TimeUnit)}</li>
122+
* <li>{@code MongoDatabase#withTimeout(long, TimeUnit)}</li>
123+
* <li>{@code MongoCollection#withTimeout(long, TimeUnit)}</li>
124+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
125+
* <li>{@link com.mongodb.TransactionOptions}</li>
126+
* </ul>
127+
*
128+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this read timeout irrelevant.
129+
* If no timeout is specified at these levels, the read timeout will be used.
116130
*/
131+
@Deprecated
117132
public Builder readTimeout(final long readTimeout, final TimeUnit timeUnit) {
118133
this.readTimeoutMS = timeoutArgumentToMillis(readTimeout, timeUnit);
119134
return this;
@@ -161,6 +176,7 @@ public SocketSettings.Builder applyToProxySettings(final Block<ProxySettings.Bui
161176
* @see com.mongodb.ConnectionString#getConnectTimeout()
162177
* @see com.mongodb.ConnectionString#getSocketTimeout()
163178
*/
179+
@SuppressWarnings("deprecation") // connectionString.getSocketTimeout
164180
public Builder applyConnectionString(final ConnectionString connectionString) {
165181
Integer connectTimeout = connectionString.getConnectTimeout();
166182
if (connectTimeout != null) {
@@ -202,7 +218,21 @@ public int getConnectTimeout(final TimeUnit timeUnit) {
202218
* @param timeUnit the time unit to get the timeout in
203219
* @return the read timeout in the requested time unit, or 0 if there is no timeout
204220
* @see Builder#readTimeout(long, TimeUnit)
221+
*
222+
* @deprecated Prefer using the operation execution timeout configuration options available at the following levels:
223+
*
224+
* <ul>
225+
* <li>{@link MongoClientSettings.Builder#getTimeout(TimeUnit)}</li>
226+
* <li>{@code MongoDatabase#getTimeout(TimeUnit)}</li>
227+
* <li>{@code MongoCollection#getTimeout(TimeUnit)}</li>
228+
* <li>{@link com.mongodb.ClientSessionOptions}</li>
229+
* <li>{@link com.mongodb.TransactionOptions}</li>
230+
* </ul>
231+
*
232+
* When executing an operation, any explicitly set timeout at these levels takes precedence, rendering this read timeout irrelevant.
233+
* If no timeout is specified at these levels, the read timeout will be used.
205234
*/
235+
@Deprecated
206236
public int getReadTimeout(final TimeUnit timeUnit) {
207237
return (int) timeUnit.convert(readTimeoutMS, MILLISECONDS);
208238
}

driver-core/src/main/com/mongodb/internal/TimeoutSettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class TimeoutSettings {
5151

5252
public static final TimeoutSettings DEFAULT = create(MongoClientSettings.builder().build());
5353

54+
@SuppressWarnings("deprecation")
5455
public static TimeoutSettings create(final MongoClientSettings settings) {
5556
return new TimeoutSettings(
5657
settings.getClusterSettings().getServerSelectionTimeout(TimeUnit.MILLISECONDS),
@@ -60,6 +61,7 @@ public static TimeoutSettings create(final MongoClientSettings settings) {
6061
settings.getConnectionPoolSettings().getMaxWaitTime(TimeUnit.MILLISECONDS));
6162
}
6263

64+
@SuppressWarnings("deprecation")
6365
public static TimeoutSettings createHeartbeatSettings(final MongoClientSettings settings) {
6466
return new TimeoutSettings(
6567
settings.getClusterSettings().getServerSelectionTimeout(TimeUnit.MILLISECONDS),

driver-core/src/main/com/mongodb/internal/capi/MongoCryptHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public static List<String> createMongocryptdSpawnArgs(final Map<String, Object>
173173
return spawnArgs;
174174
}
175175

176+
@SuppressWarnings("deprecation") // builder.readTimeout
176177
public static MongoClientSettings createMongocryptdClientSettings(@Nullable final String connectionString) {
177178

178179
return MongoClientSettings.builder()

driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public InternalConnection get(final OperationContext operationContext) {
207207
}
208208

209209
@Override
210+
@SuppressWarnings("deprecation") //maxWaitTime
210211
public void getAsync(final OperationContext operationContext, final SingleResultCallback<InternalConnection> callback) {
211212
StartTime checkoutStart = connectionCheckoutStarted(operationContext);
212213
Timeout maxWaitTimeout = checkoutStart.timeoutAfterOrInfiniteIfNegative(settings.getMaxWaitTime(NANOSECONDS), NANOSECONDS);
@@ -480,6 +481,7 @@ private boolean expired(final long startTime, final long curTime, final long max
480481
* Send both current and deprecated events in order to preserve backwards compatibility.
481482
* Must not throw {@link Exception}s.
482483
*/
484+
@SuppressWarnings("deprecation") // settings.getMaxWaitTime
483485
private void connectionPoolCreated(final ConnectionPoolListener connectionPoolListener, final ServerId serverId,
484486
final ConnectionPoolSettings settings) {
485487
ClusterId clusterId = serverId.getClusterId();

driver-core/src/main/com/mongodb/internal/operation/CommitTransactionOperation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ CommandCreator getCommandCreator() {
136136
}
137137

138138
@Override
139+
@SuppressWarnings("deprecation") //wTimeout
139140
protected Function<BsonDocument, BsonDocument> getRetryCommandModifier() {
140141
return command -> {
141142
WriteConcern retryWriteConcern = getWriteConcern().withW("majority");

0 commit comments

Comments
 (0)