Top Description Inners Fields Constructors Methods
io.r2dbc.pool

public Class ConnectionPool

extends Object
implements ConnectionFactory, Disposable, Closeable, Wrapped<ConnectionFactory>
Class Inheritance
All Implemented Interfaces
io.r2dbc.spi.Wrapped, io.r2dbc.spi.Closeable, reactor.core.Disposable, io.r2dbc.spi.ConnectionFactory
Imports
io.r2dbc.spi.Closeable, .Connection, .ConnectionFactory, .ConnectionFactoryMetadata, .Lifecycle, .R2dbcTimeoutException, .Wrapped, org.reactivestreams.Publisher, reactor.core.Disposable, reactor.core.publisher.Flux, .Mono, reactor.core.scheduler.Schedulers, reactor.pool.InstrumentedPool, .PoolBuilder, .PoolConfig, .PoolMetricsRecorder, .PooledRefMetadata, reactor.util.Logger, .Loggers, reactor.util.annotation.Nullable, javax.management.JMException, .MBeanServer, .MalformedObjectNameException, .ObjectName, java.lang.management.ManagementFactory, java.time.Duration, java.util.ArrayList, .Hashtable, .List, .Optional, java.util.concurrent.TimeoutException, java.util.function.BiPredicate, .Consumer, .Function

Reactive Relational Database Connection Pool implementation.
Authors
Mark Paluch, Tadaya Tsuyukubo, Petromir Dzhunev, Gabriel Calin

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private final InstrumentedPool<Connection>
private final Mono<Connection>
private final List<Runnable>
private final ConnectionFactory
private static final String
private static final Logger
private final Duration
private final Duration
private final Optional<PoolMetrics>
private final Function<? super Connection, ? extends Publisher<Void>>

Constructor Summary

AccessConstructor and Description
public
ConnectionPool(ConnectionPoolConfiguration
the configuration to use for building the connection pool.
configuration
)

Creates a new connection factory.

Method Summary

Modifier and TypeMethod and Description
public Mono<Void>
close()

Implements io.r2dbc.spi.Closeable.close.

Close this object and release any resources associated with it.
public Mono<Connection>
private InstrumentedPool<Connection>
public void
dispose()

Implements reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.
public Mono<Void>

Returns:

a Mono triggering the shutdown of the pool once subscribed.
disposeLater
()

Dispose this ConnectionPool in non-blocking flow.

public ConnectionFactoryMetadata
getMetadata()

Implements io.r2dbc.spi.ConnectionFactory.getMetadata.

Returns the ConnectionFactoryMetadata about the product this ConnectionFactory is applicable to.
public Optional<PoolMetrics>

Returns:

the optional pool metrics.
getMetrics
()

Returns PoolMetrics if available.

protected ObjectName

Returns:

JMX ObjectName
getPoolObjectName
(String
connection pool name
name
)

Construct JMX ObjectName.

private Function<Connection, Mono<Void>>
private Function<Connection, Mono<Void>>
private Mono<Connection>
getValidConnection(Function<Connection, Mono<Void>> allocateValidation, Connection connection)

public boolean
isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.
private void
registerToJmx(PoolMetrics poolMetrics, String name)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public ConnectionFactory
unwrap()

Implements io.r2dbc.spi.Wrapped.unwrap.

Returns the original instance wrapped by this object.
public Mono<Integer>

Returns:

a cold Mono that triggers resource warmup and emits the number of warmed up resources.
warmup
()

Warms up the ConnectionPool, if needed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

connectionPoolback to summary
private final InstrumentedPool<Connection> connectionPool
createback to summary
private final Mono<Connection> create
destroyHandlersback to summary
private final List<Runnable> destroyHandlers
factoryback to summary
private final ConnectionFactory factory
HOOK_ON_DROPPEDback to summary
private static final String HOOK_ON_DROPPED
loggerback to summary
private static final Logger logger
maxAcquireTimeback to summary
private final Duration maxAcquireTime
maxValidationTimeback to summary
private final Duration maxValidationTime
poolMetricsback to summary
private final Optional<PoolMetrics> poolMetrics
preReleaseback to summary
private final Function<? super Connection, ? extends Publisher<Void>> preRelease
Annotations
@Nullable

Constructor Detail

ConnectionPoolback to summary
public ConnectionPool(ConnectionPoolConfiguration configuration)

Creates a new connection factory.

Parameters
configuration:ConnectionPoolConfiguration

the configuration to use for building the connection pool.

Annotations
@SuppressWarnings:unchecked
Exceptions
IllegalArgumentException:
if configuration is null

Method Detail

closeback to summary
public Mono<Void> close()

Implements io.r2dbc.spi.Closeable.close.

Doc from io.r2dbc.spi.Closeable.close.

Close this object and release any resources associated with it. If the object is already closed, then subscriptions complete successfully and the close operation has no effect.

Returns:Mono<Void>

a Publisher that termination is complete

Annotations
@Override
createback to summary
public Mono<Connection> create()

Implements io.r2dbc.spi.ConnectionFactory.create.

Doc from io.r2dbc.spi.ConnectionFactory.create.

Creates a new Connection.

Returns:Mono<Connection>

the newly created Connection

Annotations
@Override
createConnectionPoolback to summary
private InstrumentedPool<Connection> createConnectionPool(ConnectionPoolConfiguration configuration)
Annotations
@SuppressWarnings:unchecked
disposeback to summary
public void dispose()

Implements reactor.core.Disposable.dispose.

Doc from reactor.core.Disposable.dispose.

Cancel or dispose the underlying task or resource.

Implementations are required to make this method idempotent.

Annotations
@Override
disposeLaterback to summary
public Mono<Void> disposeLater()

Dispose this ConnectionPool in non-blocking flow.

When multiple errors occurred during dispose flow, they are added as suppressed errors onto the first error.

Returns:Mono<Void>

a Mono triggering the shutdown of the pool once subscribed.

getMetadataback to summary
public ConnectionFactoryMetadata getMetadata()

Implements io.r2dbc.spi.ConnectionFactory.getMetadata.

Doc from io.r2dbc.spi.ConnectionFactory.getMetadata.

Returns the ConnectionFactoryMetadata about the product this ConnectionFactory is applicable to.

Returns:ConnectionFactoryMetadata

the ConnectionFactoryMetadata about the product this ConnectionFactory is applicable to

Annotations
@Override
getMetricsback to summary
public Optional<PoolMetrics> getMetrics()

Returns PoolMetrics if available.

Returns:Optional<PoolMetrics>

the optional pool metrics.

getPoolObjectNameback to summary
protected ObjectName getPoolObjectName(String name) throws MalformedObjectNameException

Construct JMX ObjectName.

Parameters
name:String

connection pool name

Returns:ObjectName

JMX ObjectName

Exceptions
MalformedObjectNameException:
when invalid objectname is constructed
getValidationback to summary
private Function<Connection, Mono<Void>> getValidation(ConnectionPoolConfiguration configuration)
getValidationFunctionback to summary
private Function<Connection, Mono<Void>> getValidationFunction(ConnectionPoolConfiguration configuration)
getValidConnectionback to summary
private Mono<Connection> getValidConnection(Function<Connection, Mono<Void>> allocateValidation, Connection connection)
isDisposedback to summary
public boolean isDisposed()

Overrides default reactor.core.Disposable.isDisposed.

Doc from reactor.core.Disposable.isDisposed.

Optionally return true when the resource or task is disposed.

Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.

Returns:boolean

true when there's a guarantee the resource or task is disposed.

Annotations
@Override
registerToJmxback to summary
private void registerToJmx(PoolMetrics poolMetrics, String name)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
unwrapback to summary
public ConnectionFactory unwrap()

Implements io.r2dbc.spi.Wrapped.unwrap.

Doc from io.r2dbc.spi.Wrapped.unwrap.

Returns the original instance wrapped by this object.

Returns:ConnectionFactory

the original instance wrapped by this object

Annotations
@Override
warmupback to summary
public Mono<Integer> warmup()

Warms up the ConnectionPool, if needed. This instructs the pool to check for a minimum size and allocate necessary connections when the minimum is not reached.

Returns:Mono<Integer>

a cold Mono that triggers resource warmup and emits the number of warmed up resources.

io.r2dbc.pool back to summary

private Class ConnectionPool.ConnectionPoolMXBeanImpl

extends Object
implements ConnectionPoolMXBean
Class Inheritance
All Implemented Interfaces
io.r2dbc.pool.ConnectionPoolMXBean

Field Summary

Modifier and TypeField and Description
private final PoolMetrics

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
getAcquiredSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getAcquiredSize.

Measure the current number of connections that have been successfully ConnectionPool#create() acquired and are in active use.
public int
getAllocatedSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getAllocatedSize.

Measure the current number of allocated connections in the ConnectionPool, acquired or idle.
public int
getIdleSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getIdleSize.

Measure the current number of idle connections in the ConnectionPool.
public int
getMaxAllocatedSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getMaxAllocatedSize.

Get the maximum number of live connections this ConnectionPool will allow.
public int
getMaxPendingAcquireSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getMaxPendingAcquireSize.

Get the maximum number of ConnectionPool#create() this ConnectionPool can queue in a pending state when no available connection is immediately handy (and the ConnectionPool cannot allocate more connections).
public int
getPendingAcquireSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getPendingAcquireSize.

Measure the current number of "pending" ConnectionPool#create() acquire Monos in the ConnectionPool.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

poolMetricsback to summary
private final PoolMetrics poolMetrics

Constructor Detail

ConnectionPoolMXBeanImplback to summary
pack-priv ConnectionPoolMXBeanImpl(PoolMetrics poolMetrics)

Method Detail

getAcquiredSizeback to summary
public int getAcquiredSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getAcquiredSize.

Doc from io.r2dbc.pool.ConnectionPoolMXBean.getAcquiredSize.

Measure the current number of connections that have been successfully ConnectionPool#create() acquired and are in active use.

Returns:int

the number of acquired connections

Annotations
@Override
getAllocatedSizeback to summary
public int getAllocatedSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getAllocatedSize.

Doc from io.r2dbc.pool.ConnectionPoolMXBean.getAllocatedSize.

Measure the current number of allocated connections in the ConnectionPool, acquired or idle.

Returns:int

the total number of allocated connections managed by the Pool

Annotations
@Override
getIdleSizeback to summary
public int getIdleSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getIdleSize.

Doc from io.r2dbc.pool.ConnectionPoolMXBean.getIdleSize.

Measure the current number of idle connections in the ConnectionPool.

Note that some connections might be lazily evicted when they're next considered for an incoming ConnectionPool#create() call. Such connections would still count towards this method.

Returns:int

the number of idle connections

Annotations
@Override
getMaxAllocatedSizeback to summary
public int getMaxAllocatedSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getMaxAllocatedSize.

Doc from io.r2dbc.pool.ConnectionPoolMXBean.getMaxAllocatedSize.

Get the maximum number of live connections this ConnectionPool will allow.

A ConnectionPool might be unbounded, in which case this method returns Integer#MAX_VALUE.

Returns:int

the maximum number of live connections that can be allocated by the ConnectionPool.

Annotations
@Override
getMaxPendingAcquireSizeback to summary
public int getMaxPendingAcquireSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getMaxPendingAcquireSize.

Doc from io.r2dbc.pool.ConnectionPoolMXBean.getMaxPendingAcquireSize.

Get the maximum number of ConnectionPool#create() this ConnectionPool can queue in a pending state when no available connection is immediately handy (and the ConnectionPool cannot allocate more connections).

A ConnectionPool pending queue might be unbounded, in which case this method returns Integer#MAX_VALUE.

Returns:int

the maximum number of pending acquire that can be enqueued by the ConnectionPool.

Annotations
@Override
getPendingAcquireSizeback to summary
public int getPendingAcquireSize()

Implements io.r2dbc.pool.ConnectionPoolMXBean.getPendingAcquireSize.

Doc from io.r2dbc.pool.ConnectionPoolMXBean.getPendingAcquireSize.

Measure the current number of "pending" ConnectionPool#create() acquire Monos in the ConnectionPool.

An acquire is in the pending state when it is attempted at a point when no idle connections is available in the pool, and no new connection can be created.

Returns:int

the number of pending acquire

Annotations
@Override
io.r2dbc.pool back to summary

private Class ConnectionPool.PoolMetricsWrapper

extends Object
implements PoolMetrics
Class Inheritance
All Implemented Interfaces
io.r2dbc.pool.PoolMetrics

Field Summary

Modifier and TypeField and Description
private final InstrumentedPool.PoolMetrics

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
acquiredSize()

Implements io.r2dbc.pool.PoolMetrics.acquiredSize.

Measure the current number of connections that have been successfully ConnectionPool#create() acquired} and are in active use.
public int
allocatedSize()

Implements io.r2dbc.pool.PoolMetrics.allocatedSize.

Measure the current number of allocated connections in the ConnectionPool, acquired or idle.
public int
getMaxAllocatedSize()

Implements io.r2dbc.pool.PoolMetrics.getMaxAllocatedSize.

Get the maximum number of live connections this ConnectionPool will allow.
public int
getMaxPendingAcquireSize()

Implements io.r2dbc.pool.PoolMetrics.getMaxPendingAcquireSize.

Get the maximum number of ConnectionPool#create() this ConnectionPool can queue in a pending state when no available connection is immediately handy (and the ConnectionPool cannot allocate more connections).
public int
idleSize()

Implements io.r2dbc.pool.PoolMetrics.idleSize.

Measure the current number of idle connections in the ConnectionPool.
public int
pendingAcquireSize()

Implements io.r2dbc.pool.PoolMetrics.pendingAcquireSize.

Measure the current number of "pending" ConnectionPool#create() acquire Monos in the ConnectionPool.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private final InstrumentedPool.PoolMetrics delegate

Constructor Detail

PoolMetricsWrapperback to summary
pack-priv PoolMetricsWrapper(InstrumentedPool.PoolMetrics delegate)

Method Detail

acquiredSizeback to summary
public int acquiredSize()

Implements io.r2dbc.pool.PoolMetrics.acquiredSize.

Doc from io.r2dbc.pool.PoolMetrics.acquiredSize.

Measure the current number of connections that have been successfully ConnectionPool#create() acquired} and are in active use.

Returns:int

the number of acquired connections

Annotations
@Override
allocatedSizeback to summary
public int allocatedSize()

Implements io.r2dbc.pool.PoolMetrics.allocatedSize.

Doc from io.r2dbc.pool.PoolMetrics.allocatedSize.

Measure the current number of allocated connections in the ConnectionPool, acquired or idle.

Returns:int

the total number of allocated connections managed by the Pool

Annotations
@Override
getMaxAllocatedSizeback to summary
public int getMaxAllocatedSize()

Implements io.r2dbc.pool.PoolMetrics.getMaxAllocatedSize.

Doc from io.r2dbc.pool.PoolMetrics.getMaxAllocatedSize.

Get the maximum number of live connections this ConnectionPool will allow.

A ConnectionPool might be unbounded, in which case this method returns Integer#MAX_VALUE.

Returns:int

the maximum number of live connections that can be allocated by the ConnectionPool.

Annotations
@Override
getMaxPendingAcquireSizeback to summary
public int getMaxPendingAcquireSize()

Implements io.r2dbc.pool.PoolMetrics.getMaxPendingAcquireSize.

Doc from io.r2dbc.pool.PoolMetrics.getMaxPendingAcquireSize.

Get the maximum number of ConnectionPool#create() this ConnectionPool can queue in a pending state when no available connection is immediately handy (and the ConnectionPool cannot allocate more connections).

A ConnectionPool pending queue might be unbounded, in which case this method returns Integer#MAX_VALUE.

Returns:int

the maximum number of pending acquire that can be enqueued by the ConnectionPool.

Annotations
@Override
idleSizeback to summary
public int idleSize()

Implements io.r2dbc.pool.PoolMetrics.idleSize.

Doc from io.r2dbc.pool.PoolMetrics.idleSize.

Measure the current number of idle connections in the ConnectionPool.

Note that some connections might be lazily evicted when they're next considered for an incoming ConnectionPool#create() call. Such connections would still count towards this method.

Returns:int

the number of idle connections

Annotations
@Override
pendingAcquireSizeback to summary
public int pendingAcquireSize()

Implements io.r2dbc.pool.PoolMetrics.pendingAcquireSize.

Doc from io.r2dbc.pool.PoolMetrics.pendingAcquireSize.

Measure the current number of "pending" ConnectionPool#create() acquire Monos in the ConnectionPool.

An acquire is in the pending state when it is attempted at a point when no idle connections is available in the pool, and no new connection can be created.

Returns:int

the number of pending acquire

Annotations
@Override