@FunctionalInterface public interface ConnectionProvider extends Disposable
ConnectionProvider
will produce Connection
Disposable.Composite, Disposable.Swap
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_POOL_ACQUIRE_TIMEOUT
Default acquisition timeout (milliseconds) before error.
|
static int |
DEFAULT_POOL_MAX_CONNECTIONS
Default max connections, if -1 will never wait to acquire before opening a new
connection in an unbounded fashion.
|
Modifier and Type | Method and Description |
---|---|
Mono<? extends Connection> |
acquire(Bootstrap bootstrap)
Return an existing or new
Connection on subscribe. |
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 address) |
static ConnectionProvider |
elastic(String name)
Create a
ConnectionProvider to cache and grow on demand Connection . |
static ConnectionProvider |
elastic(String name,
java.time.Duration maxIdleTime)
Create a
ConnectionProvider to cache and grow on demand Connection . |
static ConnectionProvider |
fixed(String name)
a new
ConnectionProvider to cache and reuse a fixed maximum
number of Connection . |
static ConnectionProvider |
fixed(String name,
int maxConnections)
Create a new
ConnectionProvider to cache and reuse a fixed maximum
number of Connection . |
static ConnectionProvider |
fixed(String name,
int maxConnections,
long acquireTimeout)
Create a new
ConnectionProvider to cache and reuse a fixed maximum
number of Connection . |
static ConnectionProvider |
fixed(String name,
int maxConnections,
long acquireTimeout,
java.time.Duration maxIdleTime)
Create a new
ConnectionProvider to cache and reuse a fixed maximum
number of Connection . |
default int |
maxConnections()
Returns the maximum number of connections before starting pending
|
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 ConnectionProvider newConnection()
ConnectionProvider
that will always create a new
Connection
.ConnectionProvider
that will always create a new
Connection
.static ConnectionProvider elastic(String name)
ConnectionProvider
to cache and grow on demand Connection
.
An elastic ConnectionProvider
will never wait before opening a new
connection. The reuse window is limited but it cannot starve an undetermined volume
of clients using it.
name
- the channel pool map nameConnectionProvider
to cache and grow on demand
Connection
static ConnectionProvider elastic(String name, @Nullable java.time.Duration maxIdleTime)
ConnectionProvider
to cache and grow on demand Connection
.
An elastic ConnectionProvider
will never wait before opening a new
connection. The reuse window is limited but it cannot starve an undetermined volume
of clients using it.
name
- the channel pool map namemaxIdleTime
- the Duration
after which the channel will be closed (resolution: ms),
if NULL
there is no max idle timeConnectionProvider
to cache and grow on demand
Connection
static ConnectionProvider fixed(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 indefinitely.
name
- the connection pool nameConnectionProvider
to cache and reuse a fixed maximum
number of Connection
static ConnectionProvider fixed(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 indefinitely.
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 fixed(String name, int maxConnections, long acquireTimeout)
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 indefinitely.
name
- the connection pool namemaxConnections
- the maximum number of connections before starting pendingacquireTimeout
- the maximum time in millis after which a pending acquire
must complete or the TimeoutException
will be thrown.ConnectionProvider
to cache and reuse a fixed maximum
number of Connection
static ConnectionProvider fixed(String name, int maxConnections, long acquireTimeout, @Nullable java.time.Duration maxIdleTime)
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 indefinitely.
name
- the connection pool namemaxConnections
- the maximum number of connections before starting pendingacquireTimeout
- the maximum time in millis after which a pending acquire
must complete or the TimeoutException
will be thrown.maxIdleTime
- the Duration
after which the channel will be closed (resolution: ms),
if NULL
there is no max idle timeConnectionProvider
to cache and reuse a fixed maximum
number of Connection
Mono<? extends Connection> acquire(Bootstrap bootstrap)
Connection
on subscribe.bootstrap
- the client connection Bootstrap
Mono
of Connection
default void disposeWhen(@NonNull SocketAddress address)
default 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()
default int maxConnections()