Class ConnectionProvider.ConnectionPoolSpec<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>>

java.lang.Object
reactor.netty.resources.ConnectionProvider.ConnectionPoolSpec<SPEC>
All Implemented Interfaces:
Supplier<SPEC>
Direct Known Subclasses:
ConnectionProvider.Builder, ConnectionProvider.HostSpecificSpec
Enclosing interface:
ConnectionProvider

public static class ConnectionProvider.ConnectionPoolSpec<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>> extends Object implements Supplier<SPEC>
Configuration for a connection pool.
Since:
0.9.5
  • Method Details

    • pendingAcquireTimeout

      public final SPEC pendingAcquireTimeout(Duration pendingAcquireTimeout)
      Set the options to use for configuring ConnectionProvider acquire timeout (resolution: ms). Default to ConnectionProvider.DEFAULT_POOL_ACQUIRE_TIMEOUT.
      Parameters:
      pendingAcquireTimeout - the maximum time after which a pending acquire must complete or the TimeoutException will be thrown (resolution: ms)
      Returns:
      this
      Throws:
      NullPointerException - if pendingAcquireTimeout is null
    • maxConnections

      public final SPEC maxConnections(int maxConnections)
      Set the options to use for configuring ConnectionProvider maximum connections per connection pool. This is a pre-made allocation strategy where only max connections is specified. Custom allocation strategies can be provided via allocationStrategy(AllocationStrategy). Default to ConnectionProvider.DEFAULT_POOL_MAX_CONNECTIONS.
      Parameters:
      maxConnections - the maximum number of connections (per connection pool) before start pending
      Returns:
      this
      Throws:
      IllegalArgumentException - if maxConnections is negative
      See Also:
    • pendingAcquireMaxCount

      public final SPEC pendingAcquireMaxCount(int pendingAcquireMaxCount)
      Set the options to use for configuring ConnectionProvider the maximum number of registered requests for acquire to keep in a pending queue When invoked with -1 the pending queue will not have upper limit. Default to 2 * max connections.
      Parameters:
      pendingAcquireMaxCount - the maximum number of registered requests for acquire to keep in a pending queue
      Returns:
      this
      Throws:
      IllegalArgumentException - if pendingAcquireMaxCount is negative
    • maxIdleTime

      public final SPEC maxIdleTime(Duration maxIdleTime)
      Set the options to use for configuring ConnectionProvider max idle time (resolution: ms). Default to ConnectionProvider.DEFAULT_POOL_MAX_IDLE_TIME if specified otherwise - no max idle time.

      Note: This configuration is not applicable for TcpClient. A TCP connection is always closed and never returned to the pool.

      Parameters:
      maxIdleTime - the Duration after which the channel will be closed when idle (resolution: ms)
      Returns:
      this
      Throws:
      NullPointerException - if maxIdleTime is null
    • maxLifeTime

      public final SPEC maxLifeTime(Duration maxLifeTime)
      Set the options to use for configuring ConnectionProvider max life time (resolution: ms). Default to ConnectionProvider.DEFAULT_POOL_MAX_LIFE_TIME if specified otherwise - no max life time.

      Note: This configuration is not applicable for TcpClient. A TCP connection is always closed and never returned to the pool.

      Parameters:
      maxLifeTime - the Duration after which the channel will be closed (resolution: ms)
      Returns:
      this
      Throws:
      NullPointerException - if maxLifeTime is null
    • evictionPredicate

      public final SPEC evictionPredicate(BiPredicate<Connection,ConnectionProvider.ConnectionMetadata> evictionPredicate)
      Set the options to use for configuring ConnectionProvider custom eviction predicate.

      Unless a custom eviction predicate is specified, the connection is evicted when not active or not persistent, If maxLifeTime(Duration) and/or maxIdleTime(Duration) settings are configured, they are also taken into account.

      Otherwise only the custom eviction predicate is invoked.

      Note: This configuration is not applicable for TcpClient. A TCP connection is always closed and never returned to the pool.

      Parameters:
      evictionPredicate - The predicate function that evaluates whether a connection should be evicted
      Returns:
      this
      Throws:
      NullPointerException - if evictionPredicate is null
    • metrics

      public final SPEC metrics(boolean metricsEnabled)
      Whether to enable metrics to be collected and registered in Micrometer's globalRegistry under the name Metrics.CONNECTION_PROVIDER_PREFIX. Applications can separately register their own filters associated with this name. For example, to put an upper bound on the number of tags produced:
       MeterFilter filter = ... ;
       Metrics.globalRegistry.config().meterFilter(MeterFilter.maximumAllowableTags(CONNECTION_PROVIDER_PREFIX, 100, filter));
       

      By default this is not enabled.

      Parameters:
      metricsEnabled - true enables metrics collection; false disables it
      Returns:
      this
    • metrics

      public final SPEC metrics(boolean metricsEnabled, Supplier<? extends ConnectionProvider.MeterRegistrar> registrar)
      Specifies whether the metrics are enabled on the ConnectionProvider. All generated metrics are provided to the specified registrar which is only instantiated if metrics are being enabled.
      Parameters:
      metricsEnabled - true enables metrics collection; false disables it
      registrar - a supplier for the ConnectionProvider.MeterRegistrar
      Returns:
      this
      Since:
      0.9.11
    • lifo

      public final SPEC lifo()
      Configure the pool so that if there are idle connections (i.e. pool is under-utilized), the next acquire operation will get the Most Recently Used connection (MRU, i.e. the connection that was released last among the current idle connections).

      Note: This configuration is not applicable for TcpClient. A TCP connection is always closed and never returned to the pool.

      Returns:
      this
    • fifo

      public final SPEC fifo()
      Configure the pool so that if there are idle connections (i.e. pool is under-utilized), the next acquire operation will get the Least Recently Used connection (LRU, i.e. the connection that was released first among the current idle connections).

      Note: This configuration is not applicable for TcpClient. A TCP connection is always closed and never returned to the pool.

      Returns:
      this
    • evictInBackground

      public final SPEC evictInBackground(Duration evictionInterval)
      Set the options to use for configuring ConnectionProvider background eviction. When a background eviction is enabled, the connection pool is regularly checked for connections, that are applicable for removal. Default to EVICT_IN_BACKGROUND_DISABLED - the background eviction is disabled. Providing an evictionInterval of zero means the background eviction is disabled.

      Note: This configuration is not applicable for TcpClient. A TCP connection is always closed and never returned to the pool.

      Parameters:
      evictionInterval - specifies the interval to be used for checking the connection pool, (resolution: ns)
      Returns:
      this
    • pendingAcquireTimer

      public final SPEC pendingAcquireTimer(BiFunction<Runnable,Duration,Disposable> pendingAcquireTimer)
      Set the option to use for configuring ConnectionProvider pending acquire timer. The pending acquire timer must be specified as a function which is used to schedule a pending acquire timeout when there is no idle connection and no new connection can be created currently. The function takes as argument a Duration which is the one configured by pendingAcquireTimeout(Duration).

      Use this function if you want to specify your own implementation for scheduling pending acquire timers.

      Default to Schedulers.parallel().

      Examples using Netty HashedWheelTimer implementation:

       
       final static HashedWheelTimer wheel = new HashedWheelTimer(10, TimeUnit.MILLISECONDS, 1024);
      
       HttpClient client = HttpClient.create(
           ConnectionProvider.builder("myprovider")
               .pendingAcquireTimeout(Duration.ofMillis(10000))
               .pendingAcquireTimer((r, d) -> {
                   Timeout t = wheel.newTimeout(timeout -> r.run(), d.toMillis(), TimeUnit.MILLISECONDS);
                   return () -> t.cancel();
               })
               .build());
       
       
      Parameters:
      pendingAcquireTimer - the function to apply when scheduling pending acquire timers
      Returns:
      this
      Throws:
      NullPointerException - if pendingAcquireTimer is null
      Since:
      1.0.20
      See Also:
    • allocationStrategy

      public final SPEC allocationStrategy(ConnectionProvider.AllocationStrategy<?> allocationStrategy)
      Limits in how many connections can be allocated and managed by the pool are driven by the provided ConnectionProvider.AllocationStrategy. This is a customization escape hatch that replaces the last configured strategy, but most cases should be covered by the ConnectionProvider.maxConnections() pre-made allocation strategy.
      Parameters:
      allocationStrategy - the ConnectionProvider.AllocationStrategy to use
      Returns:
      this
      Since:
      1.0.20
      See Also:
    • get

      public SPEC get()
      Specified by:
      get in interface Supplier<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>>