2222import java .util .concurrent .TimeUnit ;
2323import java .util .logging .Level ;
2424
25+ import org .neo4j .driver .internal .async .pool .PoolSettings ;
2526import org .neo4j .driver .internal .cluster .RoutingSettings ;
2627import org .neo4j .driver .internal .logging .JULogging ;
27- import org .neo4j .driver .internal .async .pool .PoolSettings ;
2828import org .neo4j .driver .internal .retry .RetrySettings ;
2929import org .neo4j .driver .v1 .exceptions .ServiceUnavailableException ;
3030import org .neo4j .driver .v1 .exceptions .SessionExpiredException ;
@@ -412,7 +412,7 @@ public ConfigBuilder withConnectionLivenessCheckTimeout( long value, TimeUnit un
412412 * this case, it is recommended to set liveness check to a value smaller than network equipment has and maximum
413413 * lifetime to a reasonably large value to "renew" connections once in a while.
414414 * <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
416416 * checked.
417417 *
418418 * @param value the maximum connection lifetime
@@ -426,27 +426,64 @@ public ConfigBuilder withMaxConnectionLifetime( long value, TimeUnit unit )
426426 }
427427
428428 /**
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.
430439 *
431- * @param value
432- * @return
440+ * @param value the maximum connection pool size.
441+ * @return this builder
442+ * @see #withConnectionAcquisitionTimeout(long, TimeUnit)
433443 */
434444 public ConfigBuilder withMaxConnectionPoolSize ( int value )
435445 {
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+ }
437458 return this ;
438459 }
439460
440461 /**
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.
442470 *
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)
446475 */
447476 public ConfigBuilder withConnectionAcquisitionTimeout ( long value , TimeUnit unit )
448477 {
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+ }
450487 return this ;
451488 }
452489
0 commit comments