public class HikariPooledConnectionProvider extends java.lang.Object implements PooledConnectionProvider, CanReleaseResources
| Modifier and Type | Field and Description |
|---|---|
protected static java.util.Map<java.lang.String,HostSelector> |
acceptedStrategies |
protected AcceptsUrlFunc |
acceptsUrlFunc |
protected LeastConnectionsHostSelector |
leastConnectionsHostSelector |
protected HikariPoolConfigurator |
poolConfigurator |
protected static long |
poolExpirationCheckNanos |
protected HikariPoolMapping |
poolMapping |
protected static RdsUtils |
rdsUtils |
| Constructor and Description |
|---|
HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator)
HikariPooledConnectionProvider constructor. |
HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator,
HikariPoolMapping mapping)
HikariPooledConnectionProvider constructor. |
HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator,
HikariPoolMapping mapping,
AcceptsUrlFunc acceptsUrlFunc,
long poolExpirationNanos,
long poolCleanupNanos)
HikariPooledConnectionProvider constructor. |
HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator,
HikariPoolMapping mapping,
long poolExpirationNanos,
long poolCleanupNanos)
HikariPooledConnectionProvider constructor. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptsStrategy(@NonNull HostRole role,
@NonNull java.lang.String strategy)
Indicates whether the selection strategy is supported by the connection provider.
|
boolean |
acceptsUrl(@NonNull java.lang.String protocol,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
Indicates whether this ConnectionProvider can provide connections for the given host and
properties.
|
protected void |
configurePool(com.zaxxer.hikari.HikariConfig config,
java.lang.String protocol,
HostSpec hostSpec,
java.util.Properties connectionProps,
@NonNull TargetDriverDialect targetDriverDialect)
Configures the default required settings for the internal connection pool.
|
java.sql.Connection |
connect(@NonNull java.lang.String protocol,
@NonNull Dialect dialect,
@NonNull TargetDriverDialect targetDriverDialect,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
Called once per connection that needs to be created.
|
int |
getHostCount()
Returns the number of active connection pools.
|
java.util.Set<java.lang.String> |
getHosts()
Returns a set containing every host URL for which there are one or more connection pool(s).
|
HostSpec |
getHostSpecByStrategy(@NonNull java.util.List<HostSpec> hosts,
@NonNull HostRole role,
@NonNull java.lang.String strategy,
@Nullable java.util.Properties props)
Return a reader or a writer node using the specified strategy.
|
java.util.Set<Pair> |
getKeys()
Returns a set containing every key associated with an active connection pool.
|
protected java.lang.String |
getPoolKey(HostSpec hostSpec,
java.util.Properties props) |
java.lang.String |
getTargetName() |
void |
logConnections()
Logs information for every active connection pool.
|
void |
releaseResources()
An object that implements this interface should release all acquired resources assuming it may
be disposed at any time.
|
protected static final java.util.Map<java.lang.String,HostSelector> acceptedStrategies
protected static final RdsUtils rdsUtils
protected static long poolExpirationCheckNanos
protected final HikariPoolConfigurator poolConfigurator
protected final HikariPoolMapping poolMapping
protected final AcceptsUrlFunc acceptsUrlFunc
protected final LeastConnectionsHostSelector leastConnectionsHostSelector
public HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator)
HikariPooledConnectionProvider constructor. This class can be passed to
Driver.setCustomConnectionProvider(ConnectionProvider) to enable internal connection pools for
each database instance in a cluster. By maintaining internal connection pools, the driver can
improve performance by reusing old Connection objects.hikariPoolConfigurator - a function that returns a HikariConfig with specific
Hikari configurations. By default, the
HikariPooledConnectionProvider will configure the
jdbcUrl, exceptionOverrideClassName, username, and password. Any
additional configuration should be defined by passing in this
parameter. If no additional configuration is desired, pass in a
HikariPoolConfigurator that returns an empty
HikariConfig.public HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator, HikariPoolMapping mapping)
HikariPooledConnectionProvider constructor. This class can be passed to
Driver.setCustomConnectionProvider(ConnectionProvider) to enable internal connection pools for
each database instance in a cluster. By maintaining internal connection pools, the driver can
improve performance by reusing old Connection objects.hikariPoolConfigurator - a function that returns a HikariConfig with specific
Hikari configurations. By default, the
HikariPooledConnectionProvider will configure the
jdbcUrl, exceptionOverrideClassName, username, and password. Any
additional configuration should be defined by passing in this
parameter. If no additional configuration is desired, pass in a
HikariPoolConfigurator that returns an empty
HikariConfig.mapping - a function that returns a String key used for the internal
connection pool keys. An internal connection pool will be
generated for each unique key returned by this function.public HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator, HikariPoolMapping mapping, long poolExpirationNanos, long poolCleanupNanos)
HikariPooledConnectionProvider constructor. This class can be passed to
Driver.setCustomConnectionProvider(ConnectionProvider) to enable internal connection pools for
each database instance in a cluster. By maintaining internal connection pools, the driver can
improve performance by reusing old Connection objects.hikariPoolConfigurator - a function that returns a HikariConfig with specific
Hikari configurations. By default, the
HikariPooledConnectionProvider will configure the
jdbcUrl, exceptionOverrideClassName, username, and password. Any
additional configuration should be defined by passing in this
parameter. If no additional configuration is desired, pass in a
HikariPoolConfigurator that returns an empty
HikariConfig.mapping - a function that returns a String key used for the internal
connection pool keys. An internal connection pool will be
generated for each unique key returned by this function.poolExpirationNanos - the amount of time that a pool should sit in the cache before
being marked as expired for cleanup, in nanoseconds. Expired
pools can still be used and will not be closed unless there
are no active connections.poolCleanupNanos - the interval defining how often expired connection pools
should be cleaned up, in nanoseconds. Note that expired pools
will not be closed unless there are no active connections.public HikariPooledConnectionProvider(HikariPoolConfigurator hikariPoolConfigurator, HikariPoolMapping mapping, AcceptsUrlFunc acceptsUrlFunc, long poolExpirationNanos, long poolCleanupNanos)
HikariPooledConnectionProvider constructor. This class can be passed to
Driver.setCustomConnectionProvider(ConnectionProvider) to enable internal connection pools for
each database instance in a cluster. By maintaining internal connection pools, the driver can
improve performance by reusing old Connection objects.hikariPoolConfigurator - a function that returns a HikariConfig with specific
Hikari configurations. By default, the
HikariPooledConnectionProvider will configure the
jdbcUrl, exceptionOverrideClassName, username, and password. Any
additional configuration should be defined by passing in this
parameter. If no additional configuration is desired, pass in a
HikariPoolConfigurator that returns an empty
HikariConfig.mapping - a function that returns a String key used for the internal
connection pool keys. An internal connection pool will be
generated for each unique key returned by this function.acceptsUrlFunc - a function that defines when an internal connection pool should be created for a
requested connection. An internal connection pool will be created when the connect
pipeline is being executed and this function returns true.poolExpirationNanos - the amount of time that a pool should sit in the cache before
being marked as expired for cleanup, in nanoseconds. Expired
pools can still be used and will not be closed unless there
are no active connections.poolCleanupNanos - the interval defining how often expired connection pools
should be cleaned up, in nanoseconds. Note that expired pools
will not be closed unless there are no active connections.public boolean acceptsUrl(@NonNull java.lang.String protocol,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
ConnectionProvideracceptsUrl in interface ConnectionProviderprotocol - the connection protocol (example "jdbc:mysql://")hostSpec - the HostSpec containing the host-port information for the host to connect toprops - the Properties to use for the connectionpublic boolean acceptsStrategy(@NonNull HostRole role, @NonNull java.lang.String strategy)
ConnectionProvideracceptsStrategy in interface ConnectionProviderrole - determines if the connection provider should return a reader host or a writer
hoststrategy - the selection strategy to usepublic HostSpec getHostSpecByStrategy(@NonNull java.util.List<HostSpec> hosts, @NonNull HostRole role, @NonNull java.lang.String strategy, @Nullable java.util.Properties props) throws java.sql.SQLException
ConnectionProviderUnsupportedOperationException if the specified strategy is unsupported.getHostSpecByStrategy in interface ConnectionProviderhosts - the list of HostSpec to select fromrole - determines if the connection provider should return a writer or a readerstrategy - the strategy determining how the HostSpec should be selected, e.g.,
random or round-robinprops - any properties that are required by the provided strategy to select a hostHostSpec selected using the specified strategyjava.sql.SQLException - if an error occurred while returning the hostspublic java.sql.Connection connect(@NonNull java.lang.String protocol,
@NonNull Dialect dialect,
@NonNull TargetDriverDialect targetDriverDialect,
@NonNull HostSpec hostSpec,
@NonNull java.util.Properties props)
throws java.sql.SQLException
ConnectionProviderconnect in interface ConnectionProviderprotocol - the connection protocol (example "jdbc:mysql://")dialect - the database dialecttargetDriverDialect - the target driver dialecthostSpec - the HostSpec containing the host-port information for the host to connect toprops - the Properties to use for the connectionConnection resulting from the given connection informationjava.sql.SQLException - if an error occursprotected java.lang.String getPoolKey(HostSpec hostSpec, java.util.Properties props)
public void releaseResources()
CanReleaseResourcesCalling this method does NOT mean that an object is disposing and there won't be any further calls. An object should keep its functional state after calling this method.
releaseResources in interface CanReleaseResourcesprotected void configurePool(com.zaxxer.hikari.HikariConfig config,
java.lang.String protocol,
HostSpec hostSpec,
java.util.Properties connectionProps,
@NonNull TargetDriverDialect targetDriverDialect)
config - the HikariConfig to configure. By default, this method sets the
jdbcUrl, exceptionOverrideClassName, username, and password. The
HikariConfig passed to this method should be created via a
HikariPoolConfigurator, which allows the user to specify any
additional configuration properties.protocol - the driver protocol that should be used to form connectionshostSpec - the host details used to form the connectionconnectionProps - the connection propertiestargetDriverDialect - the target driver dialect TargetDriverDialectpublic int getHostCount()
public java.util.Set<java.lang.String> getHosts()
public java.util.Set<Pair> getKeys()
public java.lang.String getTargetName()
getTargetName in interface ConnectionProviderpublic void logConnections()