diff --git a/bson/src/main/org/bson/ByteBuf.java b/bson/src/main/org/bson/ByteBuf.java index 4ef5b410a10..e44a97dfc67 100644 --- a/bson/src/main/org/bson/ByteBuf.java +++ b/bson/src/main/org/bson/ByteBuf.java @@ -434,7 +434,7 @@ public interface ByteBuf { ByteBuffer asNIO(); /** - * Gets the current reference count, which starts at 0. + * Gets the current reference count, which is 1 for a new {@link ByteBuf}. * * @return the current count, which must be greater than or equal to 0 */ diff --git a/bson/src/main/org/bson/io/OutputBuffer.java b/bson/src/main/org/bson/io/OutputBuffer.java index c733032bad1..8793acad9a2 100644 --- a/bson/src/main/org/bson/io/OutputBuffer.java +++ b/bson/src/main/org/bson/io/OutputBuffer.java @@ -122,7 +122,10 @@ public int size() { * Get a list of byte buffers that are prepared to be read from; in other words, whose position is 0 and whose limit is the number of * bytes that should read.
Note that the byte buffers may be read-only.
* - * @return the non-null list of byte buffers, in LITTLE_ENDIAN order + * @return the non-null list of byte buffers, in LITTLE_ENDIAN order. The returned {@link ByteBuf}s must eventually be + * {@linkplain ByteBuf#release() released} explicitly, calling {@link OutputBuffer#close()} may be not enough to release them. + * The caller must not use the {@link ByteBuf}s after closing this {@link OutputBuffer}, + * though releasing them is allowed to be done after closing this {@link OutputBuffer}. */ public abstract ListConnection pool configuration:
*Default is {@code WriteConcern.ACKNOWLEDGED}.
* * @return the write concern - * @see WriteConcern#ACKNOWLEDGED + * @see Builder#writeConcern(WriteConcern) */ public WriteConcern getWriteConcern() { return writeConcern; @@ -765,6 +766,7 @@ public CodecRegistry getCodecRegistry() { * Gets the factory to use to create a {@code StreamFactory}. * * @return the stream factory factory + * @see Builder#streamFactoryFactory(StreamFactoryFactory) */ @Nullable public StreamFactoryFactory getStreamFactoryFactory() { @@ -789,6 +791,7 @@ public ListDefault is null.
* * @return the application name, which may be null + * @see Builder#applicationName(String) * @mongodb.server.release 3.4 */ @Nullable @@ -926,7 +929,7 @@ public SocketSettings getHeartbeatSocketSettings() { * * @return a ConnectionPoolSettings populated with the settings from this {@code MongoClientSettings} instance that relate to the * connection provider. - * @see ConnectionPoolSettings + * @see Builder#applyToConnectionPoolSettings(Block) */ public ConnectionPoolSettings getConnectionPoolSettings() { return connectionPoolSettings; diff --git a/driver-core/src/main/com/mongodb/MongoInterruptedException.java b/driver-core/src/main/com/mongodb/MongoInterruptedException.java index 386560512ec..e1aa7d79447 100644 --- a/driver-core/src/main/com/mongodb/MongoInterruptedException.java +++ b/driver-core/src/main/com/mongodb/MongoInterruptedException.java @@ -33,7 +33,7 @@ public class MongoInterruptedException extends MongoException { * @param message the message * @param e the cause */ - public MongoInterruptedException(@Nullable final String message, final Exception e) { + public MongoInterruptedException(@Nullable final String message, @Nullable final Exception e) { super(message, e); } } diff --git a/driver-core/src/main/com/mongodb/WriteConcern.java b/driver-core/src/main/com/mongodb/WriteConcern.java index 904602a217e..61c8e510b90 100644 --- a/driver-core/src/main/com/mongodb/WriteConcern.java +++ b/driver-core/src/main/com/mongodb/WriteConcern.java @@ -229,6 +229,7 @@ public String getWString() { * * @param timeUnit the non-null time unit for the result * @return the WTimeout, which may be null if a wTimeout has not been specified + * @see #withWTimeout(long, TimeUnit) * @since 3.2 * @mongodb.driver.manual core/write-concern/#timeouts wTimeout */ @@ -380,6 +381,7 @@ public WriteConcern withJournal(@Nullable final Boolean journal) { * @param wTimeout the wTimeout, which must be >= 0 and <= Integer.MAX_VALUE after conversion to milliseconds * @param timeUnit the non-null time unit to apply to wTimeout * @return the WriteConcern with the given wTimeout + * @see #getWTimeout(TimeUnit) * @since 3.2 * @mongodb.driver.manual reference/write-concern/#wtimeout wtimeout option */ diff --git a/driver-core/src/main/com/mongodb/connection/ClusterSettings.java b/driver-core/src/main/com/mongodb/connection/ClusterSettings.java index aea02192373..36c590c58d5 100644 --- a/driver-core/src/main/com/mongodb/connection/ClusterSettings.java +++ b/driver-core/src/main/com/mongodb/connection/ClusterSettings.java @@ -222,6 +222,7 @@ public Builder mode(final ClusterConnectionMode mode) { * * @param requiredReplicaSetName the required replica set name. * @return this + * @see #getRequiredReplicaSetName() */ public Builder requiredReplicaSetName(@Nullable final String requiredReplicaSetName) { this.requiredReplicaSetName = requiredReplicaSetName; @@ -443,7 +444,9 @@ public ClusterType getRequiredClusterType() { * Gets the required replica set name. * * @return the required replica set name + * @see Builder#requiredReplicaSetName(String) */ + @Nullable public String getRequiredReplicaSetName() { return requiredReplicaSetName; } diff --git a/driver-core/src/main/com/mongodb/connection/SocketSettings.java b/driver-core/src/main/com/mongodb/connection/SocketSettings.java index 56fae36861c..62e21725847 100644 --- a/driver-core/src/main/com/mongodb/connection/SocketSettings.java +++ b/driver-core/src/main/com/mongodb/connection/SocketSettings.java @@ -103,6 +103,7 @@ public Builder connectTimeout(final int connectTimeout, final TimeUnit timeUnit) * @param readTimeout the read timeout * @param timeUnit the time unit * @return this + * @see #getReadTimeout(TimeUnit) */ public Builder readTimeout(final int readTimeout, final TimeUnit timeUnit) { this.readTimeoutMS = MILLISECONDS.convert(readTimeout, timeUnit); @@ -177,6 +178,7 @@ public int getConnectTimeout(final TimeUnit timeUnit) { * * @param timeUnit the time unit to get the timeout in * @return the read timeout in the requested time unit, or 0 if there is no timeout + * @see Builder#readTimeout(int, TimeUnit) */ public int getReadTimeout(final TimeUnit timeUnit) { return (int) timeUnit.convert(readTimeoutMS, MILLISECONDS); diff --git a/driver-core/src/main/com/mongodb/internal/Timeout.java b/driver-core/src/main/com/mongodb/internal/Timeout.java index 7c2a2245aae..f36eedd1d64 100644 --- a/driver-core/src/main/com/mongodb/internal/Timeout.java +++ b/driver-core/src/main/com/mongodb/internal/Timeout.java @@ -164,14 +164,12 @@ long remainingNanos(final long currentNanos) { * returning {@code false}. If such a discrepancy is observed, * the result of the {@link #expired()} method should be preferred. * - * @throws UnsupportedOperationException If the timeout is {@linkplain #isInfinite() infinite}. + * @throws AssertionError If the timeout is {@linkplain #isInfinite() infinite}. * @see #remainingOrInfinite(TimeUnit) */ - public long remaining(final TimeUnit unit) throws UnsupportedOperationException { + public long remaining(final TimeUnit unit) { assertNotNull(unit); - if (isInfinite()) { - throw new UnsupportedOperationException(); - } + assertFalse(isInfinite()); return isImmediate() ? 0 : convertRoundUp(remainingNanos(System.nanoTime()), unit); } diff --git a/driver-core/src/main/com/mongodb/internal/connection/ConcurrentPool.java b/driver-core/src/main/com/mongodb/internal/connection/ConcurrentPool.java index 9f6ba17eb6d..0158c2d9637 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/ConcurrentPool.java +++ b/driver-core/src/main/com/mongodb/internal/connection/ConcurrentPool.java @@ -528,7 +528,7 @@ private static void lockInterruptiblyUnfair(final ReentrantLock lock) throws Mon lock.lockInterruptibly(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new MongoInterruptedException(null, new InterruptedException()); + throw new MongoInterruptedException(null, e); } } } @@ -542,7 +542,7 @@ static void lockUnfair(final ReentrantLock lock) { private static void throwIfInterrupted() throws MongoInterruptedException { if (Thread.currentThread().isInterrupted()) { - throw new MongoInterruptedException(null, new InterruptedException()); + throw new MongoInterruptedException(null, null); } } } diff --git a/driver-core/src/main/com/mongodb/internal/connection/ConnectionGenerationSupplier.java b/driver-core/src/main/com/mongodb/internal/connection/ConnectionGenerationSupplier.java index 67034284b19..8f07ed506b1 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/ConnectionGenerationSupplier.java +++ b/driver-core/src/main/com/mongodb/internal/connection/ConnectionGenerationSupplier.java @@ -16,9 +16,11 @@ package com.mongodb.internal.connection; +import com.mongodb.annotations.ThreadSafe; import com.mongodb.lang.NonNull; import org.bson.types.ObjectId; +@ThreadSafe interface ConnectionGenerationSupplier { int getGeneration(); diff --git a/driver-core/src/main/com/mongodb/internal/connection/ConnectionPool.java b/driver-core/src/main/com/mongodb/internal/connection/ConnectionPool.java index 0089268d7cb..da2b0dcc1a0 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/ConnectionPool.java +++ b/driver-core/src/main/com/mongodb/internal/connection/ConnectionPool.java @@ -17,6 +17,7 @@ package com.mongodb.internal.connection; import com.mongodb.MongoConnectionPoolClearedException; +import com.mongodb.annotations.ThreadSafe; import com.mongodb.connection.ConnectionPoolSettings; import com.mongodb.internal.async.SingleResultCallback; import org.bson.types.ObjectId; @@ -28,6 +29,7 @@ /** * An instance of an implementation must be created in the {@linkplain #invalidate(Throwable) paused} state. */ +@ThreadSafe interface ConnectionPool extends Closeable { /** * Is equivalent to {@link #get(OperationContext, long, TimeUnit)} called with {@link ConnectionPoolSettings#getMaxWaitTime(TimeUnit)}. diff --git a/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java b/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java index c7298b2223b..b20b1e7c57e 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java +++ b/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java @@ -121,7 +121,8 @@ import static java.util.concurrent.TimeUnit.NANOSECONDS; @SuppressWarnings("deprecation") -class DefaultConnectionPool implements ConnectionPool { +@ThreadSafe +final class DefaultConnectionPool implements ConnectionPool { private static final Logger LOGGER = Loggers.getLogger("connection"); private static final StructuredLogger STRUCTURED_LOGGER = new StructuredLogger("connection"); private final ConcurrentPoolThis class is not part of the public API and may be removed or changed at any time
*/ +@Immutable public class InternalConnectionInitializationDescription { private final ConnectionDescription connectionDescription; private final ServerDescription serverDescription; diff --git a/driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnectionInitializer.java b/driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnectionInitializer.java index 8b102182c05..ffd0b912233 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnectionInitializer.java +++ b/driver-core/src/main/com/mongodb/internal/connection/InternalStreamConnectionInitializer.java @@ -60,7 +60,8 @@ public class InternalStreamConnectionInitializer implements InternalConnectionIn public InternalStreamConnectionInitializer(final ClusterConnectionMode clusterConnectionMode, @Nullable final Authenticator authenticator, - final BsonDocument clientMetadataDocument, final List