Interface ConnectionProvider

All Superinterfaces:
Disposable
All Known Implementing Classes:
HttpResources, PooledConnectionProvider, TcpResources
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ConnectionProvider extends Disposable
Since:
0.8
Author:
Stephane Maldini
  • Field Details

    • DEFAULT_POOL_MAX_CONNECTIONS

      static final int DEFAULT_POOL_MAX_CONNECTIONS
      Default max connections. Fallback to 2 * available number of processors (but with a minimum value of 16)
    • DEFAULT_POOL_ACQUIRE_TIMEOUT

      static final long DEFAULT_POOL_ACQUIRE_TIMEOUT
      Default acquisition timeout (milliseconds) before error. If -1 will never wait to acquire before opening a new connection in an unbounded fashion. Fallback 45 seconds
    • DEFAULT_POOL_MAX_IDLE_TIME

      static final long DEFAULT_POOL_MAX_IDLE_TIME
      Default max idle time, fallback - max idle time is not specified.
    • DEFAULT_POOL_MAX_LIFE_TIME

      static final long DEFAULT_POOL_MAX_LIFE_TIME
      Default max life time, fallback - max life time is not specified.
    • LEASING_STRATEGY_FIFO

      static final String LEASING_STRATEGY_FIFO
      The connection selection is first in, first out.
      See Also:
    • LEASING_STRATEGY_LIFO

      static final String LEASING_STRATEGY_LIFO
      The connection selection is last in, first out.
      See Also:
    • DEFAULT_POOL_LEASING_STRATEGY

      static final String DEFAULT_POOL_LEASING_STRATEGY
      Default leasing strategy (fifo, lifo), fallback to fifo.
      • fifo - The connection selection is first in, first out
      • lifo - The connection selection is last in, first out
  • Method Details

    • builder

      static ConnectionProvider.Builder builder(String name)
      Creates a builder for ConnectionProvider.
      Parameters:
      name - ConnectionProvider name
      Returns:
      a new ConnectionProvider builder
      Since:
      0.9.5
    • newConnection

      static ConnectionProvider newConnection()
      Return a ConnectionProvider that will always create a new Connection.
      Returns:
      a ConnectionProvider that will always create a new Connection.
    • create

      static ConnectionProvider create(String name)
      Create a new ConnectionProvider to cache and reuse a fixed maximum number of Connection.

      A Fixed ConnectionProvider will open up to the given max number of processors observed by this jvm (minimum 4). Further connections will be pending acquisition until DEFAULT_POOL_ACQUIRE_TIMEOUT and the default pending acquisition max count will be 500.

      Parameters:
      name - the connection pool name
      Returns:
      a new ConnectionProvider to cache and reuse a fixed maximum number of Connection
      Since:
      0.9.5
    • create

      static ConnectionProvider create(String name, int maxConnections)
      Create a new ConnectionProvider to cache and reuse a fixed maximum number of Connection.

      A Fixed ConnectionProvider will open up to the given max connection value. Further connections will be pending acquisition until DEFAULT_POOL_ACQUIRE_TIMEOUT and the default pending acquisition max count will be 2 * max connections value.

      Parameters:
      name - the connection pool name
      maxConnections - the maximum number of connections before starting pending acquisition on existing ones
      Returns:
      a new ConnectionProvider to cache and reuse a fixed maximum number of Connection
      Since:
      0.9.5
    • create

      static ConnectionProvider create(String name, int maxConnections, boolean metricsEnabled)
      Create a new ConnectionProvider to cache and reuse a fixed maximum number of Connection.

      A Fixed ConnectionProvider will open up to the given max connection value. Further connections will be pending acquisition until DEFAULT_POOL_ACQUIRE_TIMEOUT and the default pending acquisition max count will be 2 * max connections value.

      Parameters:
      name - the connection pool name
      maxConnections - the maximum number of connections before starting pending acquisition on existing ones
      metricsEnabled - true enables metrics collection; false disables it
      Returns:
      a new ConnectionProvider to cache and reuse a fixed maximum number of Connection
      Since:
      1.0.21
    • acquire

      Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver connectionObserver, @Nullable Supplier<? extends SocketAddress> remoteAddress, @Nullable AddressResolverGroup<?> resolverGroup)
      Return an existing or new Connection on subscribe.
      Parameters:
      config - the transport configuration
      connectionObserver - the ConnectionObserver
      remoteAddress - the SocketAddress to connect to
      resolverGroup - the resolver which will resolve the address of the unresolved named address
      Returns:
      an existing or new Mono of Connection
    • disposeWhen

      default void disposeWhen(SocketAddress remoteAddress)
      Dispose all connection pools for the specified remote address.

      This method has NOOP default implementation. ConnectionProvider implementations may decide to provide more specific implementation.

      Parameters:
      remoteAddress - the remote address
    • dispose

      default void dispose()
      Dispose this ConnectionProvider. This method is NOT blocking. It is implemented as fire-and-forget. Use disposeLater() when you need to observe the final status of the operation, combined with Mono.block() if you need to synchronously wait for the underlying resources to be disposed.
      Specified by:
      dispose in interface Disposable
    • disposeLater

      default Mono<Void> disposeLater()
      Returns a Mono that triggers the disposal of the ConnectionProvider when subscribed to.

      This method has NOOP default implementation. ConnectionProvider implementations may decide to provide more specific implementation.

      Returns:
      a Mono representing the completion of the ConnectionProvider disposal.
    • maxConnections

      default int maxConnections()
      Returns the maximum number of connections before starting pending.
      Returns:
      the maximum number of connections before starting pending
    • maxConnectionsPerHost

      default @Nullable Map<SocketAddress,Integer> maxConnectionsPerHost()
      Returns the maximum number of connections per host before starting pending.
      Returns:
      the maximum number of connections per host before starting pending
    • mutate

      default @Nullable ConnectionProvider.Builder mutate()
      Returns a builder to mutate properties of this ConnectionProvider.
      Returns:
      a builder to mutate properties of this ConnectionProvider
      Since:
      1.0.14
    • name

      default @Nullable String name()
      Returns ConnectionProvider name used for metrics.
      Returns:
      ConnectionProvider name used for metrics
      Since:
      1.0.14