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.
ConnectionProvider
will produce Connection
.- Since:
- 0.8
- Author:
- Stephane Maldini
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
static final class
Build aConnectionProvider
to cache and reuse a fixed maximum number ofConnection
.static interface
static class
Configuration for a connection pool.static final class
Configuration for a connection pool per remote host.static interface
A strategy to register which metrics are collected in a particular connection pool.Nested classes/interfaces inherited from interface reactor.core.Disposable
Disposable.Composite, Disposable.Swap
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
Default acquisition timeout (milliseconds) before error.static final String
Default leasing strategy (fifo, lifo), fallback to fifo.static final int
Default max connections.static final long
Default max idle time, fallback - max idle time is not specified.static final long
Default max life time, fallback - max life time is not specified.static final String
The connection selection is first in, first out.static final String
The connection selection is last in, first out. -
Method Summary
Modifier and TypeMethodDescriptionMono<? extends Connection>
acquire
(TransportConfig config, ConnectionObserver connectionObserver, @Nullable Supplier<? extends SocketAddress> remoteAddress, @Nullable AddressResolverGroup<?> resolverGroup) Return an existing or newConnection
on subscribe.static ConnectionProvider.Builder
Creates a builder forConnectionProvider
.static ConnectionProvider
Create a newConnectionProvider
to cache and reuse a fixed maximum number ofConnection
.static ConnectionProvider
Create a newConnectionProvider
to cache and reuse a fixed maximum number ofConnection
.static ConnectionProvider
Create a newConnectionProvider
to cache and reuse a fixed maximum number ofConnection
.default void
dispose()
Dispose this ConnectionProvider.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
Returns the maximum number of connections before starting pending.default @Nullable Map<SocketAddress,
Integer> Returns the maximum number of connections per host before starting pending.default @Nullable ConnectionProvider.Builder
mutate()
Returns a builder to mutate properties of thisConnectionProvider
.default @Nullable String
name()
ReturnsConnectionProvider
name used for metrics.static ConnectionProvider
Return aConnectionProvider
that will always create a newConnection
.Methods inherited from interface reactor.core.Disposable
isDisposed
-
Field Details
-
DEFAULT_POOL_MAX_CONNECTIONS
static final int DEFAULT_POOL_MAX_CONNECTIONSDefault 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_TIMEOUTDefault 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_TIMEDefault max idle time, fallback - max idle time is not specified. -
DEFAULT_POOL_MAX_LIFE_TIME
static final long DEFAULT_POOL_MAX_LIFE_TIMEDefault max life time, fallback - max life time is not specified. -
LEASING_STRATEGY_FIFO
The connection selection is first in, first out.- See Also:
-
LEASING_STRATEGY_LIFO
The connection selection is last in, first out.- See Also:
-
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
Creates a builder forConnectionProvider
.- Parameters:
name
-ConnectionProvider
name- Returns:
- a new ConnectionProvider builder
- Since:
- 0.9.5
-
newConnection
Return aConnectionProvider
that will always create a newConnection
.- Returns:
- a
ConnectionProvider
that will always create a newConnection
.
-
create
Create a newConnectionProvider
to cache and reuse a fixed maximum number ofConnection
.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 untilDEFAULT_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 ofConnection
- Since:
- 0.9.5
-
create
Create a newConnectionProvider
to cache and reuse a fixed maximum number ofConnection
.A Fixed
ConnectionProvider
will open up to the given max connection value. Further connections will be pending acquisition untilDEFAULT_POOL_ACQUIRE_TIMEOUT
and the default pending acquisition max count will be 2 * max connections value.- Parameters:
name
- the connection pool namemaxConnections
- the maximum number of connections before starting pending acquisition on existing ones- Returns:
- a new
ConnectionProvider
to cache and reuse a fixed maximum number ofConnection
- Since:
- 0.9.5
-
create
Create a newConnectionProvider
to cache and reuse a fixed maximum number ofConnection
.A Fixed
ConnectionProvider
will open up to the given max connection value. Further connections will be pending acquisition untilDEFAULT_POOL_ACQUIRE_TIMEOUT
and the default pending acquisition max count will be 2 * max connections value.- Parameters:
name
- the connection pool namemaxConnections
- the maximum number of connections before starting pending acquisition on existing onesmetricsEnabled
- true enables metrics collection; false disables it- Returns:
- a new
ConnectionProvider
to cache and reuse a fixed maximum number ofConnection
- 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 newConnection
on subscribe.- Parameters:
config
- the transport configurationconnectionObserver
- theConnectionObserver
remoteAddress
- theSocketAddress
to connect toresolverGroup
- the resolver which will resolve the address of the unresolved named address- Returns:
- an existing or new
Mono
ofConnection
-
disposeWhen
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. UsedisposeLater()
when you need to observe the final status of the operation, combined withMono.block()
if you need to synchronously wait for the underlying resources to be disposed.- Specified by:
dispose
in interfaceDisposable
-
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
Returns the maximum number of connections per host before starting pending.- Returns:
- the maximum number of connections per host before starting pending
-
mutate
Returns a builder to mutate properties of thisConnectionProvider
.- Returns:
- a builder to mutate properties of this
ConnectionProvider
- Since:
- 1.0.14
-
name
ReturnsConnectionProvider
name used for metrics.- Returns:
ConnectionProvider
name used for metrics- Since:
- 1.0.14
-