22
22
import java .util .concurrent .TimeUnit ;
23
23
import java .util .logging .Level ;
24
24
25
+ import org .neo4j .driver .internal .async .pool .PoolSettings ;
25
26
import org .neo4j .driver .internal .cluster .RoutingSettings ;
26
27
import org .neo4j .driver .internal .logging .JULogging ;
27
- import org .neo4j .driver .internal .async .pool .PoolSettings ;
28
28
import org .neo4j .driver .internal .retry .RetrySettings ;
29
29
import org .neo4j .driver .v1 .exceptions .ServiceUnavailableException ;
30
30
import org .neo4j .driver .v1 .exceptions .SessionExpiredException ;
@@ -412,7 +412,7 @@ public ConfigBuilder withConnectionLivenessCheckTimeout( long value, TimeUnit un
412
412
* this case, it is recommended to set liveness check to a value smaller than network equipment has and maximum
413
413
* lifetime to a reasonably large value to "renew" connections once in a while.
414
414
* <p>
415
- * No maximum lifetime limit is imposed by default . Zero and negative values result in lifetime not being
415
+ * Default maximum connection lifetime is 1 hour . Zero and negative values result in lifetime not being
416
416
* checked.
417
417
*
418
418
* @param value the maximum connection lifetime
@@ -426,27 +426,64 @@ public ConfigBuilder withMaxConnectionLifetime( long value, TimeUnit unit )
426
426
}
427
427
428
428
/**
429
- * Todo: doc and validation
429
+ * Configure maximum amount of connections in the connection pool towards a single database. This setting
430
+ * limits total amount of connections in the pool when used in direct driver, created for URI with 'bolt'
431
+ * scheme. It will limit amount of connections per cluster member when used with routing driver, created for
432
+ * URI with 'bolt+routing' scheme.
433
+ * <p>
434
+ * Acquisition will be attempted for at most configured timeout
435
+ * {@link #withConnectionAcquisitionTimeout(long, TimeUnit)} when limit is reached.
436
+ * <p>
437
+ * Default value is {@code 100}. Negative values are allowed and result in unlimited pool. Value of {@code 0}
438
+ * is not allowed.
430
439
*
431
- * @param value
432
- * @return
440
+ * @param value the maximum connection pool size.
441
+ * @return this builder
442
+ * @see #withConnectionAcquisitionTimeout(long, TimeUnit)
433
443
*/
434
444
public ConfigBuilder withMaxConnectionPoolSize ( int value )
435
445
{
436
- this .maxConnectionPoolSize = value ;
446
+ if ( value == 0 )
447
+ {
448
+ throw new IllegalArgumentException ( "Zero value is not supported" );
449
+ }
450
+ else if ( value < 0 )
451
+ {
452
+ this .maxConnectionPoolSize = Integer .MAX_VALUE ;
453
+ }
454
+ else
455
+ {
456
+ this .maxConnectionPoolSize = value ;
457
+ }
437
458
return this ;
438
459
}
439
460
440
461
/**
441
- * Todo: doc and validation
462
+ * Configure maximum amount of time connection acquisition will attempt to acquire a connection from the
463
+ * connection pool. This timeout only kicks in when all existing connections are being used and no new
464
+ * connections can be created because maximum connection pool size has been reached.
465
+ * <p>
466
+ * Exception is raised when connection can't be acquired within configured time.
467
+ * <p>
468
+ * Default value is 60 seconds. Negative values are allowed and result in unlimited acquisition timeout. Value
469
+ * of {@code 0} is allowed and results in no timeout and immediate failure when connection is unavailable.
442
470
*
443
- * @param value
444
- * @param unit
445
- * @return
471
+ * @param value the acquisition timeout
472
+ * @param unit the unit in which the duration is given
473
+ * @return this builder
474
+ * @see #withMaxConnectionPoolSize(int)
446
475
*/
447
476
public ConfigBuilder withConnectionAcquisitionTimeout ( long value , TimeUnit unit )
448
477
{
449
- this .connectionAcquisitionTimeoutMillis = unit .toMillis ( value );
478
+ long valueInMillis = unit .toMillis ( value );
479
+ if ( value >= 0 )
480
+ {
481
+ this .connectionAcquisitionTimeoutMillis = valueInMillis ;
482
+ }
483
+ else
484
+ {
485
+ this .connectionAcquisitionTimeoutMillis = -1 ;
486
+ }
450
487
return this ;
451
488
}
452
489
0 commit comments