19
19
import com .mongodb .ConnectionString ;
20
20
import com .mongodb .annotations .Immutable ;
21
21
import com .mongodb .annotations .NotThreadSafe ;
22
+ import com .mongodb .event .ConnectionCheckOutStartedEvent ;
23
+ import com .mongodb .event .ConnectionCheckedInEvent ;
24
+ import com .mongodb .event .ConnectionCheckedOutEvent ;
22
25
import com .mongodb .event .ConnectionCreatedEvent ;
23
26
import com .mongodb .event .ConnectionPoolListener ;
24
27
import com .mongodb .event .ConnectionReadyEvent ;
@@ -119,6 +122,8 @@ public Builder applySettings(final ConnectionPoolSettings connectionPoolSettings
119
122
*
120
123
* @param maxSize the maximum number of connections in the pool; if 0, then there is no limit.
121
124
* @return this
125
+ * @see #getMaxSize()
126
+ * @see #getMaxWaitTime(TimeUnit)
122
127
*/
123
128
public Builder maxSize (final int maxSize ) {
124
129
this .maxSize = maxSize ;
@@ -140,13 +145,38 @@ public Builder minSize(final int minSize) {
140
145
}
141
146
142
147
/**
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>
144
173
*
145
174
* <p>Default is 2 minutes. A value of 0 means that it will not wait. A negative value means it will wait indefinitely.</p>
146
175
*
147
176
* @param maxWaitTime the maximum amount of time to wait
148
177
* @param timeUnit the TimeUnit for this wait period
149
178
* @return this
179
+ * @see #getMaxWaitTime(TimeUnit)
150
180
*/
151
181
public Builder maxWaitTime (final long maxWaitTime , final TimeUnit timeUnit ) {
152
182
this .maxWaitTimeMS = MILLISECONDS .convert (maxWaitTime , timeUnit );
@@ -234,6 +264,7 @@ public Builder connectionPoolListenerList(final List<ConnectionPoolListener> con
234
264
* @param maxConnecting The maximum number of connections a pool may be establishing concurrently. Must be positive.
235
265
* @return {@code this}.
236
266
* @see ConnectionPoolSettings#getMaxConnecting()
267
+ * @see #getMaxWaitTime(TimeUnit)
237
268
* @since 4.4
238
269
*/
239
270
public Builder maxConnecting (final int maxConnecting ) {
@@ -298,6 +329,9 @@ public Builder applyConnectionString(final ConnectionString connectionString) {
298
329
* <p>Default is 100.</p>
299
330
*
300
331
* @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)
301
335
*/
302
336
public int getMaxSize () {
303
337
return maxSize ;
@@ -316,12 +350,38 @@ public int getMinSize() {
316
350
}
317
351
318
352
/**
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>
320
378
*
321
379
* <p>Default is 2 minutes. A value of 0 means that it will not wait. A negative value means it will wait indefinitely.</p>
322
380
*
323
381
* @param timeUnit the TimeUnit for this wait period
324
382
* @return the maximum amount of time to wait in the given TimeUnits
383
+ * @see Builder#maxWaitTime(long, TimeUnit)
384
+ * @see ConnectionString#getMaxWaitTime()
325
385
*/
326
386
public long getMaxWaitTime (final TimeUnit timeUnit ) {
327
387
return timeUnit .convert (maxWaitTimeMS , MILLISECONDS );
@@ -388,6 +448,8 @@ public List<ConnectionPoolListener> getConnectionPoolListeners() {
388
448
*
389
449
* @return The maximum number of connections a pool may be establishing concurrently.
390
450
* @see Builder#maxConnecting(int)
451
+ * @see ConnectionString#getMaxConnecting()
452
+ * @see #getMaxWaitTime(TimeUnit)
391
453
* @since 4.4
392
454
*/
393
455
public int getMaxConnecting () {
0 commit comments