java.lang.Object
is.codion.common.db.pool.AbstractConnectionPoolWrapper<T>
- Type Parameters:
T- the type representing the actual pool object
- All Implemented Interfaces:
ConnectionPoolWrapper
public abstract class AbstractConnectionPoolWrapper<T>
extends Object
implements ConnectionPoolWrapper
A default base implementation of the ConnectionPool wrapper, handling the collection of statistics
-
Field Summary
Fields inherited from interface is.codion.common.db.pool.ConnectionPoolWrapper
CHECK_OUT_TIMEOUT, IDLE_TIMEOUT, MAXIMUM_POOL_SIZE, MINIMUM_POOL_SIZE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractConnectionPoolWrapper(ConnectionFactory connectionFactory, User user, DataSource dataSource, Function<DataSource, T> poolFactory) Instantiates a new AbstractConnectionPoolWrapper instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract intprotected final voidMarks this pool as closed (causing subsequentconnection(User)calls to throwIllegalStateException) and cleans up statistics collection resources to prevent resource leaks.final booleanReturns true if connection check out times are being collected.final voidcollectCheckOutTimes(boolean collectCheckOutTimes) Specifies whether to collect connection check out times.final booleanReturns true if snapshot statistics are being collected.final voidcollectSnapshotStatistics(boolean collectSnapshotStatistics) Specifies whether to collect usage statistics for a snapshot.final Connectionconnection(User user) Fetches a connection from the pool.protected final Tprotected abstract ConnectionFetches a connection from the underlying pool.protected abstract intinUse()final voidResets the collected usage statisticsfinal ConnectionPoolStatisticsstatistics(long since) Retrieves usage statistics for the connection pool.final Useruser()protected abstract intwaiting()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface is.codion.common.db.pool.ConnectionPoolWrapper
cleanupInterval, cleanupInterval, close, idleTimeout, idleTimeout, maximumCheckOutTime, maximumCheckOutTime, maximumPoolSize, maximumPoolSize, minimumPoolSize, minimumPoolSize
-
Constructor Details
-
AbstractConnectionPoolWrapper
protected AbstractConnectionPoolWrapper(ConnectionFactory connectionFactory, User user, DataSource dataSource, Function<DataSource, T> poolFactory) Instantiates a new AbstractConnectionPoolWrapper instance.- Parameters:
connectionFactory- the connection factoryuser- the connection pool userdataSource- the data sourcepoolFactory- creates the actual connection pool based on the given data source
-
-
Method Details
-
user
- Specified by:
userin interfaceConnectionPoolWrapper- Returns:
- the user this connection pool is based on.
-
connection
Description copied from interface:ConnectionPoolWrapperFetches a connection from the pool. Close the connection to return it to the pool.Note that
useris a credentials check, not a selector: the pool serves a singleConnectionPoolWrapper.user(), and the given credentials are verified against it (username case-insensitively, password exactly) before a connection is handed out.- Specified by:
connectionin interfaceConnectionPoolWrapper- Parameters:
user- the credentials to verify against the pool user- Returns:
- a database connection retrieved from the pool
- See Also:
-
resetStatistics
public final void resetStatistics()Description copied from interface:ConnectionPoolWrapperResets the collected usage statistics- Specified by:
resetStatisticsin interfaceConnectionPoolWrapper
-
collectSnapshotStatistics
public final boolean collectSnapshotStatistics()Description copied from interface:ConnectionPoolWrapperReturns true if snapshot statistics are being collected.- Specified by:
collectSnapshotStatisticsin interfaceConnectionPoolWrapper- Returns:
- true if pool usage statistics for a snapshot should be collected
- See Also:
-
collectSnapshotStatistics
public final void collectSnapshotStatistics(boolean collectSnapshotStatistics) Description copied from interface:ConnectionPoolWrapperSpecifies whether to collect usage statistics for a snapshot.- Specified by:
collectSnapshotStatisticsin interfaceConnectionPoolWrapper- Parameters:
collectSnapshotStatistics- the value- See Also:
-
collectCheckOutTimes
public final boolean collectCheckOutTimes()Description copied from interface:ConnectionPoolWrapperReturns true if connection check out times are being collected.- Specified by:
collectCheckOutTimesin interfaceConnectionPoolWrapper- Returns:
- true if connection check out times should be collected
- See Also:
-
collectCheckOutTimes
public final void collectCheckOutTimes(boolean collectCheckOutTimes) Description copied from interface:ConnectionPoolWrapperSpecifies whether to collect connection check out times.- Specified by:
collectCheckOutTimesin interfaceConnectionPoolWrapper- Parameters:
collectCheckOutTimes- the value- See Also:
-
statistics
Description copied from interface:ConnectionPoolWrapperRetrieves usage statistics for the connection pool.Note that this is a destructive read: it resets the per-second counters and consumes the collected check-out times. The
sinceparameter only filters the snapshot statistics list; the counters ignore it. Concurrent monitoring clients polling the same pool will steal each other's data.- Specified by:
statisticsin interfaceConnectionPoolWrapper- Parameters:
since- the time from which the snapshot statistics should be retrieved- Returns:
- connection pool usage statistics
-
fetchConnection
Fetches a connection from the underlying pool.- Returns:
- a connection from the underlying pool
- Throws:
SQLException- in case of an exception.
-
connectionPool
- Returns:
- the underlying connection pool instance
-
available
protected abstract int available()- Returns:
- the number of available connections in this pool
-
inUse
protected abstract int inUse()- Returns:
- the number of connections in active use
-
waiting
protected abstract int waiting()- Returns:
- the number of waiting connection requests
-
closeStatisticsCollection
protected final void closeStatisticsCollection()Marks this pool as closed (causing subsequentconnection(User)calls to throwIllegalStateException) and cleans up statistics collection resources to prevent resource leaks. This method should be called by concrete implementations in their close() methods.
-