1919import com .mongodb .ConnectionString ;
2020import com .mongodb .annotations .Immutable ;
2121import com .mongodb .annotations .NotThreadSafe ;
22+ import com .mongodb .event .ConnectionCheckOutStartedEvent ;
23+ import com .mongodb .event .ConnectionCheckedInEvent ;
24+ import com .mongodb .event .ConnectionCheckedOutEvent ;
2225import com .mongodb .event .ConnectionCreatedEvent ;
2326import com .mongodb .event .ConnectionPoolListener ;
2427import com .mongodb .event .ConnectionReadyEvent ;
@@ -119,6 +122,8 @@ public Builder applySettings(final ConnectionPoolSettings connectionPoolSettings
119122 *
120123 * @param maxSize the maximum number of connections in the pool; if 0, then there is no limit.
121124 * @return this
125+ * @see #getMaxSize()
126+ * @see #getMaxWaitTime(TimeUnit)
122127 */
123128 public Builder maxSize (final int maxSize ) {
124129 this .maxSize = maxSize ;
@@ -140,13 +145,38 @@ public Builder minSize(final int minSize) {
140145 }
141146
142147 /**
143- * <p>The maximum time that a thread may wait for a connection to become available.</p>
148+ * The maximum duration to wait until either:
149+ * <ul>
150+ * <li>
151+ * an {@linkplain ConnectionCheckedOutEvent in-use connection} becomes {@linkplain ConnectionCheckedInEvent available}; or
152+ * </li>
153+ * <li>
154+ * a {@linkplain ConnectionCreatedEvent connection is created} and begins to be {@linkplain ConnectionReadyEvent established}.
155+ * The time between {@linkplain ConnectionCheckOutStartedEvent requesting} a connection
156+ * and it being created is limited by this maximum duration.
157+ * The maximum time between it being created and {@linkplain ConnectionCheckedOutEvent successfully checked out},
158+ * which includes the time to {@linkplain ConnectionReadyEvent establish} the created connection,
159+ * is affected by {@link SocketSettings#getConnectTimeout(TimeUnit)}, {@link SocketSettings#getReadTimeout(TimeUnit)}
160+ * among others, and is not affected by this maximum duration.
161+ * </li>
162+ * </ul>
163+ * The reasons it is not always possible to create and start establishing a connection
164+ * whenever there is no available connection:
165+ * <ul>
166+ * <li>
167+ * the number of connections per pool is limited by {@link #getMaxSize()};
168+ * </li>
169+ * <li>
170+ * the number of connections a pool may be establishing concurrently is limited by {@link #getMaxConnecting()}.
171+ * </li>
172+ * </ul>
144173 *
145174 * <p>Default is 2 minutes. A value of 0 means that it will not wait. A negative value means it will wait indefinitely.</p>
146175 *
147176 * @param maxWaitTime the maximum amount of time to wait
148177 * @param timeUnit the TimeUnit for this wait period
149178 * @return this
179+ * @see #getMaxWaitTime(TimeUnit)
150180 */
151181 public Builder maxWaitTime (final long maxWaitTime , final TimeUnit timeUnit ) {
152182 this .maxWaitTimeMS = MILLISECONDS .convert (maxWaitTime , timeUnit );
@@ -234,6 +264,7 @@ public Builder connectionPoolListenerList(final List<ConnectionPoolListener> con
234264 * @param maxConnecting The maximum number of connections a pool may be establishing concurrently. Must be positive.
235265 * @return {@code this}.
236266 * @see ConnectionPoolSettings#getMaxConnecting()
267+ * @see #getMaxWaitTime(TimeUnit)
237268 * @since 4.4
238269 */
239270 public Builder maxConnecting (final int maxConnecting ) {
@@ -298,6 +329,9 @@ public Builder applyConnectionString(final ConnectionString connectionString) {
298329 * <p>Default is 100.</p>
299330 *
300331 * @return the maximum number of connections in the pool; if 0, then there is no limit.
332+ * @see Builder#maxSize(int)
333+ * @see ConnectionString#getMaxConnectionPoolSize()
334+ * @see #getMaxWaitTime(TimeUnit)
301335 */
302336 public int getMaxSize () {
303337 return maxSize ;
@@ -316,12 +350,38 @@ public int getMinSize() {
316350 }
317351
318352 /**
319- * <p>The maximum time that a thread may wait for a connection to become available.</p>
353+ * The maximum duration to wait until either:
354+ * <ul>
355+ * <li>
356+ * an {@linkplain ConnectionCheckedOutEvent in-use connection} becomes {@linkplain ConnectionCheckedInEvent available}; or
357+ * </li>
358+ * <li>
359+ * a {@linkplain ConnectionCreatedEvent connection is created} and begins to be {@linkplain ConnectionReadyEvent established}.
360+ * The time between {@linkplain ConnectionCheckOutStartedEvent requesting} a connection
361+ * and it being created is limited by this maximum duration.
362+ * The maximum time between it being created and {@linkplain ConnectionCheckedOutEvent successfully checked out},
363+ * which includes the time to {@linkplain ConnectionReadyEvent establish} the created connection,
364+ * is affected by {@link SocketSettings#getConnectTimeout(TimeUnit)}, {@link SocketSettings#getReadTimeout(TimeUnit)}
365+ * among others, and is not affected by this maximum duration.
366+ * </li>
367+ * </ul>
368+ * The reasons it is not always possible to create and start establishing a connection
369+ * whenever there is no available connection:
370+ * <ul>
371+ * <li>
372+ * the number of connections per pool is limited by {@link #getMaxSize()};
373+ * </li>
374+ * <li>
375+ * the number of connections a pool may be establishing concurrently is limited by {@link #getMaxConnecting()}.
376+ * </li>
377+ * </ul>
320378 *
321379 * <p>Default is 2 minutes. A value of 0 means that it will not wait. A negative value means it will wait indefinitely.</p>
322380 *
323381 * @param timeUnit the TimeUnit for this wait period
324382 * @return the maximum amount of time to wait in the given TimeUnits
383+ * @see Builder#maxWaitTime(long, TimeUnit)
384+ * @see ConnectionString#getMaxWaitTime()
325385 */
326386 public long getMaxWaitTime (final TimeUnit timeUnit ) {
327387 return timeUnit .convert (maxWaitTimeMS , MILLISECONDS );
@@ -388,6 +448,8 @@ public List<ConnectionPoolListener> getConnectionPoolListeners() {
388448 *
389449 * @return The maximum number of connections a pool may be establishing concurrently.
390450 * @see Builder#maxConnecting(int)
451+ * @see ConnectionString#getMaxConnecting()
452+ * @see #getMaxWaitTime(TimeUnit)
391453 * @since 4.4
392454 */
393455 public int getMaxConnecting () {
0 commit comments