public abstract class AbstractConnectionPool extends AbstractPool<Connection> implements ConnectionPool
getConnection()
exist in the available queue.
Connections that are actively in use exist in the active queue. This implementation uses FIFO operations for each
queue.Modifier and Type | Class and Description |
---|---|
protected class |
AbstractConnectionPool.DefaultPooledConnectionProxy
Contains a connection that is participating in this pool.
|
Modifier and Type | Field and Description |
---|---|
protected Queue<PooledConnectionProxy> |
active
List of connections in use.
|
protected Queue<PooledConnectionProxy> |
available
List of available connections in the pool.
|
protected ReentrantLock |
checkInLock
Lock for check ins.
|
protected ReentrantLock |
checkOutLock
Lock for check outs.
|
private DefaultConnectionFactory |
connectionFactory
Connection factory to create connections with.
|
private boolean |
connectOnCreate
Whether to connect to the ldap on connection creation.
|
private boolean |
failFastInitialize
Whether
initialize() should throw if pooling configuration requirements are not met. |
private boolean |
initialized
Whether
initialize() has been invoked. |
private ScheduledExecutorService |
poolExecutor
Executor for scheduling pool tasks.
|
protected ReentrantLock |
poolLock
Lock for the entire pool.
|
protected Condition |
poolNotEmpty
Condition for notifying threads that a connection was returned.
|
private QueueType |
queueType
Type of queue.
|
logger
Constructor and Description |
---|
AbstractConnectionPool() |
Modifier and Type | Method and Description |
---|---|
protected void |
activateAndValidateConnection(PooledConnectionProxy pc)
Attempts to activate and validate a connection.
|
int |
activeCount()
Returns the number of connections in use.
|
int |
availableCount()
Returns the number of connections available for use.
|
void |
close()
Empty this pool, freeing any resources.
|
protected PooledConnectionProxy |
createActiveConnection()
Create a new connection and place it in the active pool.
|
protected PooledConnectionProxy |
createActiveConnection(boolean throwOnFailure)
Create a new connection and place it in the active pool.
|
protected PooledConnectionProxy |
createAvailableConnection()
Create a new connection and place it in the available pool.
|
protected PooledConnectionProxy |
createAvailableConnection(boolean throwOnFailure)
Create a new connection and place it in the available pool.
|
protected PooledConnectionProxy |
createConnection()
Create a new connection.
|
protected PooledConnectionProxy |
createConnection(boolean throwOnFailure)
Create a new connection.
|
protected Connection |
createConnectionProxy(PooledConnectionProxy pc)
Creates a connection proxy using the supplied pool connection.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references
to the object.
|
abstract Connection |
getConnection()
Returns a connection from the pool.
|
DefaultConnectionFactory |
getConnectionFactory()
Returns the connection factory for this pool.
|
boolean |
getConnectOnCreate()
Returns whether connections will attempt to connect after creation.
|
boolean |
getFailFastInitialize()
Returns whether
initialize() should throw if pooling configuration requirements are not met. |
Set<PooledConnectionStatistics> |
getPooledConnectionStatistics()
Returns the statistics for each connection in the pool.
|
QueueType |
getQueueType()
Returns the type of queue used for this connection pool.
|
protected void |
grow(int size)
Attempts to grow the pool to the supplied size.
|
protected void |
grow(int size,
boolean throwOnFailure)
Attempts to grow the pool to the supplied size.
|
void |
initialize()
Initialize this pool for use.
|
boolean |
isInitialized()
Returns whether this pool has been initialized.
|
void |
prune()
Attempts to reduce the size of the pool back to it's configured minimum.
|
abstract void |
putConnection(Connection c)
Returns a connection to the pool.
|
protected void |
removeActiveConnection(PooledConnectionProxy pc)
Remove a connection from the active pool.
|
protected void |
removeAvailableAndActiveConnection(PooledConnectionProxy pc)
Remove a connection from both the available and active pools.
|
protected void |
removeAvailableConnection(PooledConnectionProxy pc)
Remove a connection from the available pool.
|
protected PooledConnectionProxy |
retrieveConnectionProxy(Connection proxy)
Retrieves the invocation handler from the supplied connection proxy.
|
void |
setConnectionFactory(DefaultConnectionFactory cf)
Sets the connection factory for this pool.
|
void |
setConnectOnCreate(boolean b)
Sets whether newly created connections will attempt to connect.
|
void |
setFailFastInitialize(boolean b)
Sets whether
initialize() should throw if pooling configuration requirements are not met. |
void |
setQueueType(QueueType type)
Sets the type of queue used for this connection pool.
|
protected void |
throwIfNotInitialized()
Used to determine whether
initialize() has been invoked for this pool. |
String |
toString() |
void |
validate()
Attempts to validate all objects in the pool.
|
protected boolean |
validateAndPassivateConnection(PooledConnectionProxy pc)
Attempts to validate and passivate a connection.
|
activate, getActivator, getName, getPassivator, getPoolConfig, getPruneStrategy, getValidator, passivate, setActivator, setName, setPassivator, setPoolConfig, setPruneStrategy, setValidator, validate
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
getActivator, getPassivator, getValidator, setActivator, setPassivator, setValidator
protected final ReentrantLock poolLock
protected final Condition poolNotEmpty
protected final ReentrantLock checkInLock
protected final ReentrantLock checkOutLock
protected Queue<PooledConnectionProxy> available
protected Queue<PooledConnectionProxy> active
private DefaultConnectionFactory connectionFactory
private boolean connectOnCreate
private QueueType queueType
private ScheduledExecutorService poolExecutor
private boolean initialized
initialize()
has been invoked.private boolean failFastInitialize
initialize()
should throw if pooling configuration requirements are not met.public DefaultConnectionFactory getConnectionFactory()
public void setConnectionFactory(DefaultConnectionFactory cf)
cf
- connection factorypublic boolean getConnectOnCreate()
public void setConnectOnCreate(boolean b)
b
- connect on createpublic QueueType getQueueType()
public void setQueueType(QueueType type)
type
- of queuepublic boolean getFailFastInitialize()
initialize()
should throw if pooling configuration requirements are not met.initialize()
should throwpublic void setFailFastInitialize(boolean b)
initialize()
should throw if pooling configuration requirements are not met.b
- whether initialize()
should throwpublic boolean isInitialized()
protected void throwIfNotInitialized()
initialize()
has been invoked for this pool.IllegalStateException
- if this pool has not been initializedpublic void initialize()
AbstractConfig.makeImmutable()
.initialize
in interface ConnectionPool
IllegalStateException
- if this pool has already been initialized, the pooling configuration is
inconsistent or the pool does not contain at least one connection and it's minimum
size is greater than zeroprotected void grow(int size)
size
- to grow the pool toprotected void grow(int size, boolean throwOnFailure)
size
- to grow the pool tothrowOnFailure
- whether to throw illegal state exceptionIllegalStateException
- if the pool cannot grow to the supplied size and createAvailableConnection(boolean)
throwspublic void close()
close
in interface ConnectionPool
IllegalStateException
- if this pool has not been initializedpublic abstract Connection getConnection() throws PoolException
getConnection
in interface ConnectionPool
PoolException
- if this operation failsBlockingTimeoutException
- if this pool is configured with a block time and it occursPoolInterruptedException
- if this pool is configured with a block time and the current thread is
interruptedIllegalStateException
- if this pool has not been initializedpublic abstract void putConnection(Connection c)
c
- connectionIllegalStateException
- if this pool has not been initializedprotected PooledConnectionProxy createConnection()
connectOnCreate
is true, the connection will be opened.protected PooledConnectionProxy createConnection(boolean throwOnFailure)
connectOnCreate
is true, the connection will be opened.throwOnFailure
- whether to throw illegal state exceptionIllegalStateException
- if connectOnCreate
is true and the connection cannot be openedprotected PooledConnectionProxy createAvailableConnection()
protected PooledConnectionProxy createAvailableConnection(boolean throwOnFailure)
throwOnFailure
- whether to throw illegal state exceptionIllegalStateException
- if createConnection(boolean)
throwsprotected PooledConnectionProxy createActiveConnection()
protected PooledConnectionProxy createActiveConnection(boolean throwOnFailure)
throwOnFailure
- whether to throw illegal state exceptionIllegalStateException
- if createConnection(boolean)
throwsprotected void removeAvailableConnection(PooledConnectionProxy pc)
pc
- connection that is in the available poolprotected void removeActiveConnection(PooledConnectionProxy pc)
pc
- connection that is in the active poolprotected void removeAvailableAndActiveConnection(PooledConnectionProxy pc)
pc
- connection that is in both the available and active poolsprotected void activateAndValidateConnection(PooledConnectionProxy pc) throws PoolException
getConnection()
.pc
- connectionPoolException
- if this method failsActivationException
- if the connection cannot be activatedValidationException
- if the connection cannot be validatedprotected boolean validateAndPassivateConnection(PooledConnectionProxy pc)
putConnection(Connection)
.pc
- connectionpublic void prune()
PoolConfig.setMinPoolSize(int)
.IllegalStateException
- if this pool has not been initializedpublic void validate()
PoolConfig.setValidatePeriodically(boolean)
.IllegalStateException
- if this pool has not been initializedpublic int availableCount()
ConnectionPool
availableCount
in interface ConnectionPool
public int activeCount()
ConnectionPool
activeCount
in interface ConnectionPool
public Set<PooledConnectionStatistics> getPooledConnectionStatistics()
ConnectionPool
getPooledConnectionStatistics
in interface ConnectionPool
protected Connection createConnectionProxy(PooledConnectionProxy pc)
pc
- pool connection to create proxy withprotected PooledConnectionProxy retrieveConnectionProxy(Connection proxy)
proxy
- connection proxyprotected void finalize() throws Throwable
Copyright © 2003-2019 Virginia Tech. All Rights Reserved.