@FunctionalInterface public interface ConnectionProvider extends Disposable
ConnectionProvider
will produce Connection
Modifier and Type | Interface and Description |
---|---|
static interface |
ConnectionProvider.AllocationStrategy<A extends ConnectionProvider.AllocationStrategy<A>> |
static class |
ConnectionProvider.Builder
Build a
ConnectionProvider to cache and reuse a fixed maximum number of
Connection . |
static interface |
ConnectionProvider.ConnectionMetadata |
static class |
ConnectionProvider.ConnectionPoolSpec<SPEC extends ConnectionProvider.ConnectionPoolSpec<SPEC>>
Configuration for a connection pool.
|
static class |
ConnectionProvider.HostSpecificSpec
Configuration for a connection pool per remote host.
|
static interface |
ConnectionProvider.MeterRegistrar
A strategy to register which metrics are collected in a particular connection pool.
|
Disposable.Composite, Disposable.Swap
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_POOL_ACQUIRE_TIMEOUT
Default acquisition timeout (milliseconds) before error.
|
static String |
DEFAULT_POOL_LEASING_STRATEGY
Default leasing strategy (fifo, lifo), fallback to fifo.
|
static int |
DEFAULT_POOL_MAX_CONNECTIONS
Default max connections.
|
static long |
DEFAULT_POOL_MAX_IDLE_TIME
Default max idle time, fallback - max idle time is not specified.
|
static long |
DEFAULT_POOL_MAX_LIFE_TIME
Default max life time, fallback - max life time is not specified.
|
static String |
LEASING_STRATEGY_FIFO
The connection selection is first in, first out.
|
static String |
LEASING_STRATEGY_LIFO
The connection selection is last in, first out.
|
Modifier and Type | Method and Description |
---|---|
Mono<? extends Connection> |
acquire(TransportConfig config,
ConnectionObserver connectionObserver,
Supplier<? extends SocketAddress> remoteAddress,
AddressResolverGroup<?> resolverGroup)
Return an existing or new
Connection on subscribe. |
static ConnectionProvider.Builder |
builder(String name)
Creates a builder for
ConnectionProvider |
static ConnectionProvider |
create(String name)
Create a new
ConnectionProvider to cache and reuse a fixed maximum
number of Connection . |
static ConnectionProvider |
create(String name,
int maxConnections)
Create a new
ConnectionProvider to cache and reuse a fixed maximum
number of Connection . |
static ConnectionProvider |
create(String name,
int maxConnections,
boolean metricsEnabled)
Create a new
ConnectionProvider to cache and reuse a fixed maximum
number of Connection . |
default void |
dispose()
Dispose this ConnectionProvider.
|
default Mono<Void> |
disposeLater()
Returns a Mono that triggers the disposal of the ConnectionProvider when subscribed to.
|
default void |
disposeWhen(SocketAddress remoteAddress)
Dispose all connection pools for the specified remote address.
|
default int |
maxConnections()
Returns the maximum number of connections before starting pending
|
default Map<SocketAddress,Integer> |
maxConnectionsPerHost()
Returns the maximum number of connections per host before starting pending
|
default ConnectionProvider.Builder |
mutate()
Returns a builder to mutate properties of this
ConnectionProvider |
default String |
name()
Returns
ConnectionProvider name used for metrics |
static ConnectionProvider |
newConnection()
Return a
ConnectionProvider that will always create a new
Connection . |
isDisposed
static final int DEFAULT_POOL_MAX_CONNECTIONS
static final long DEFAULT_POOL_ACQUIRE_TIMEOUT
static final long DEFAULT_POOL_MAX_IDLE_TIME
static final long DEFAULT_POOL_MAX_LIFE_TIME
static final String LEASING_STRATEGY_FIFO
static final String LEASING_STRATEGY_LIFO
static final String DEFAULT_POOL_LEASING_STRATEGY
static ConnectionProvider.Builder builder(String name)
ConnectionProvider
name
- ConnectionProvider
namestatic ConnectionProvider newConnection()
ConnectionProvider
that will always create a new
Connection
.ConnectionProvider
that will always create a new
Connection
.static ConnectionProvider create(String name)
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.
name
- the connection pool nameConnectionProvider
to cache and reuse a fixed maximum
number of Connection
static ConnectionProvider create(String name, int maxConnections)
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.
name
- the connection pool namemaxConnections
- the maximum number of connections before starting pending
acquisition on existing onesConnectionProvider
to cache and reuse a fixed maximum
number of Connection
static ConnectionProvider create(String name, int maxConnections, boolean metricsEnabled)
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.
name
- the connection pool namemaxConnections
- the maximum number of connections before starting pending
acquisition on existing onesmetricsEnabled
- true enables metrics collection; false disables itConnectionProvider
to cache and reuse a fixed maximum
number of Connection
Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver connectionObserver, @Nullable Supplier<? extends SocketAddress> remoteAddress, @Nullable AddressResolverGroup<?> resolverGroup)
Connection
on subscribe.config
- the transport configurationconnectionObserver
- the ConnectionObserver
remoteAddress
- the SocketAddress
to connect toresolverGroup
- the resolver which will resolve the address of the unresolved named addressMono
of Connection
default void disposeWhen(SocketAddress remoteAddress)
This method has NOOP
default implementation.
ConnectionProvider
implementations may decide to provide more specific implementation.
remoteAddress
- the remote addressdefault void dispose()
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.dispose
in interface Disposable
default Mono<Void> disposeLater()
This method has NOOP
default implementation.
ConnectionProvider
implementations may decide to provide more specific implementation.
default int maxConnections()
@Nullable default Map<SocketAddress,Integer> maxConnectionsPerHost()
@Nullable default ConnectionProvider.Builder mutate()
ConnectionProvider
ConnectionProvider
@Nullable default String name()
ConnectionProvider
name used for metricsConnectionProvider
name used for metrics