Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions driver-core/src/main/com/mongodb/ErrorCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum ErrorCategory {
/**
* An execution timeout error
*
* @see MongoExecutionTimeoutException
* @mongodb.driver.manual reference/operator/meta/maxTimeMS/ maxTimeMS
*/
EXECUTION_TIMEOUT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,18 @@

package com.mongodb;

import com.mongodb.annotations.Alpha;
import com.mongodb.annotations.Reason;
import org.bson.BsonDocument;

/**
* Exception indicating that the execution of the current operation timed out as a result of the maximum operation time being exceeded.
* Exception indicating that the execution of the current command timed out by the server
* as a result of the {@linkplain ErrorCategory#EXECUTION_TIMEOUT maximum operation time being exceeded}.
*
* @see MongoTimeoutException
* @since 2.12
*/
public class MongoExecutionTimeoutException extends MongoException {
private static final long serialVersionUID = 5955669123800274594L;

/**
* Construct a new instance.
*
* @param message the error message
* @since 5.2
*/
@Alpha(Reason.CLIENT)
public MongoExecutionTimeoutException(final String message) {
super(message);

}

/**
* Construct a new instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
* Exception thrown to indicate that a MongoDB operation has exceeded the specified timeout for
* the full execution of operation.
*
* <p>The {@code MongoOperationTimeoutException} might provide information about the underlying
* <p>The {@link MongoOperationTimeoutException} might provide information about the underlying
* cause of the timeout, if available. For example, if retries are attempted due to transient failures,
* and a timeout occurs in any of the attempts, the exception from one of the retries may be appended
* as the cause to this {@code MongoOperationTimeoutException}.
* as the cause to this {@link MongoOperationTimeoutException}.
*
* <p>The key difference between {@code MongoOperationTimeoutException} and {@code MongoExecutionTimeoutException}
* lies in the nature of these exceptions. {@code MongoExecutionTimeoutException} indicates a server-side timeout
* capped by a user-specified number. These server errors are transformed into the new {@code MongoOperationTimeoutException}.
* On the other hand, {@code MongoOperationExecutionException} denotes a timeout during the execution of the entire operation.
* <p>The key difference between {@link MongoOperationTimeoutException} and {@link MongoExecutionTimeoutException}
* lies in the nature of these exceptions. {@link MongoExecutionTimeoutException} indicates a server-side timeout
* capped by a user-specified number. These server errors are transformed into the new {@link MongoOperationTimeoutException}.
* On the other hand, {@link MongoOperationTimeoutException} denotes a timeout during the execution of the entire operation.
*
* @see MongoClientSettings.Builder#timeout(long, TimeUnit)
* @see MongoClientSettings#getTimeout(TimeUnit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import com.mongodb.lang.Nullable;

/**
* An exception indicating that the driver has timed out waiting for either a server or a connection to become available.
* An exception indicating that the driver has timed out doing something.
*
* @see MongoExecutionTimeoutException
*/
public class MongoTimeoutException extends MongoClientException {

Expand Down
13 changes: 11 additions & 2 deletions driver-core/src/main/com/mongodb/internal/TimeoutContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import static com.mongodb.assertions.Assertions.assertNotNull;
import static com.mongodb.assertions.Assertions.assertNull;
import static com.mongodb.assertions.Assertions.assertTrue;
import static com.mongodb.assertions.Assertions.isTrue;
import static com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE;
import static com.mongodb.internal.time.Timeout.ZeroSemantics.ZERO_DURATION_MEANS_INFINITE;
Expand All @@ -41,6 +42,9 @@
public class TimeoutContext {
private static final int NO_ROUND_TRIP_TIME_MS = 0;
private final TimeoutSettings timeoutSettings;
/**
* Is {@code null} iff {@link #timeoutSettings}{@code .}{@link TimeoutSettings#getTimeoutMS() getTimeoutMS()} is {@code null}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems hard to understand / read. As we don't publish this as API docs would

Is {@code null} iff {@link #timeoutSettings} is {@code null}.

Suffice? Or is there some way to get the IntelliJ to display as javadoc by default rather than text?

*/
@Nullable
private final Timeout timeout;
@Nullable
Expand Down Expand Up @@ -139,6 +143,7 @@ private TimeoutContext(final boolean isMaintenanceContext,
final TimeoutSettings timeoutSettings,
@Nullable final MaxTimeSupplier maxTimeSupplier,
@Nullable final Timeout timeout) {
assertTrue((timeoutSettings.getTimeoutMS() == null) == (timeout == null));
this.isMaintenanceContext = isMaintenanceContext;
this.timeoutSettings = timeoutSettings;
this.minRoundTripTimeMS = minRoundTripTimeMS;
Expand All @@ -149,7 +154,8 @@ private TimeoutContext(final boolean isMaintenanceContext,
/**
* Allows for the differentiation between users explicitly setting a global operation timeout via {@code timeoutMS}.
*
* @return true if a timeout has been set.
* @return true iff {@link #getTimeoutSettings()}{@code .}{@link TimeoutSettings#getTimeoutMS() getTimeoutMS()} is not {@code null}.
* @see #getTimeout()
*/
public boolean hasTimeoutMS() {
return timeoutSettings.getTimeoutMS() != null;
Expand All @@ -170,7 +176,6 @@ public Timeout timeoutIncludingRoundTrip() {

/**
* Returns the remaining {@code timeoutMS} if set or the {@code alternativeTimeoutMS}.
*
* zero means infinite timeout.
*
* @param alternativeTimeoutMS the alternative timeout.
Expand All @@ -191,6 +196,10 @@ public TimeoutSettings getTimeoutSettings() {
return timeoutSettings;
}

/**
* @return {@code null} iff {@link #hasTimeoutMS()} is {@code false}.
* @see #hasTimeoutMS()
*/
@Nullable
public Timeout getTimeout() {
return timeout;
Expand Down