Package org.ldaptive.pool
Class BlockingConnectionPool
- java.lang.Object
-
- org.ldaptive.pool.AbstractConnectionPool
-
- org.ldaptive.pool.BlockingConnectionPool
-
- All Implemented Interfaces:
ConnectionPool
- Direct Known Subclasses:
PooledConnectionFactory
public class BlockingConnectionPool extends AbstractConnectionPool
Implements a pool of connections that has a set minimum and maximum size. The pool will not grow beyond the maximum size and when the pool is exhausted, requests for new connections will block. The length of time the pool will block is determined bygetBlockWaitTime()
. By default, the pool will block for 1 minute and there is no guarantee that waiting threads will be serviced in the order in which they made their request. This implementation should be used when you need to control the exact number of connections that can be created. SeeAbstractConnectionPool
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.ldaptive.pool.AbstractConnectionPool
AbstractConnectionPool.DefaultPooledConnectionProxy
-
-
Field Summary
Fields Modifier and Type Field Description private Duration
blockWaitTime
Duration to wait for an available connection.-
Fields inherited from class org.ldaptive.pool.AbstractConnectionPool
active, available, checkOutLock, DEFAULT_MAX_POOL_SIZE, DEFAULT_MIN_POOL_SIZE, logger, poolLock, poolNotEmpty
-
-
Constructor Summary
Constructors Constructor Description BlockingConnectionPool()
Creates a new blocking pool.BlockingConnectionPool(DefaultConnectionFactory cf)
Creates a new blocking pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected PooledConnectionProxy
blockAvailableConnection()
This blocks until a connection can be acquired.Duration
getBlockWaitTime()
Returns the block wait time.Connection
getConnection()
Returns a connection from the pool.void
putConnection(Connection c)
Returns a connection to the pool.protected PooledConnectionProxy
retrieveAvailableConnection()
Attempts to retrieve a connection from the available queue.void
setBlockWaitTime(Duration time)
Sets the block wait time.String
toString()
-
Methods inherited from class org.ldaptive.pool.AbstractConnectionPool
activateAndValidateConnection, activeCount, availableCount, close, createActiveConnection, createAvailableConnection, createAvailableConnections, createConnection, createConnectionProxy, getActivator, getConnectOnCreate, getDefaultConnectionFactory, getFailFastInitialize, getMaxPoolSize, getMinPoolSize, getName, getPassivator, getPooledConnectionStatistics, getPruneStrategy, getQueueType, getValidator, grow, initialize, isInitialized, isValidateOnCheckIn, isValidateOnCheckOut, isValidatePeriodically, passivateAndValidateConnection, prune, removeActiveConnection, removeAvailableAndActiveConnection, removeAvailableConnection, retrieveConnectionProxy, setActivator, setConnectOnCreate, setDefaultConnectionFactory, setFailFastInitialize, setMaxPoolSize, setMinPoolSize, setName, setPassivator, setPruneStrategy, setQueueType, setValidateOnCheckIn, setValidateOnCheckOut, setValidatePeriodically, setValidator, throwIfNotInitialized, validate
-
-
-
-
Field Detail
-
blockWaitTime
private Duration blockWaitTime
Duration to wait for an available connection.
-
-
Constructor Detail
-
BlockingConnectionPool
public BlockingConnectionPool()
Creates a new blocking pool.
-
BlockingConnectionPool
public BlockingConnectionPool(DefaultConnectionFactory cf)
Creates a new blocking pool.- Parameters:
cf
- connection factory
-
-
Method Detail
-
getBlockWaitTime
public Duration getBlockWaitTime()
Returns the block wait time. Default time is 1 minute.- Returns:
- time to wait for available connections
-
setBlockWaitTime
public void setBlockWaitTime(Duration time)
Sets the block wait time. Default time is 1 minute.- Parameters:
time
- to wait for available connections
-
getConnection
public Connection getConnection() throws PoolException
Description copied from class:AbstractConnectionPool
Returns a connection from the pool.- Specified by:
getConnection
in interfaceConnectionPool
- Specified by:
getConnection
in classAbstractConnectionPool
- Returns:
- connection
- Throws:
PoolException
- if this operation failsBlockingTimeoutException
- if this pool is configured with a block time and it occurs
-
retrieveAvailableConnection
protected PooledConnectionProxy retrieveAvailableConnection()
Attempts to retrieve a connection from the available queue.- Returns:
- connection from the pool
- Throws:
NoSuchElementException
- if the available queue is empty
-
blockAvailableConnection
protected PooledConnectionProxy blockAvailableConnection() throws PoolException
This blocks until a connection can be acquired.- Returns:
- connection from the pool
- Throws:
PoolException
- if this method failsBlockingTimeoutException
- if this pool is configured with a block time and it occurs
-
putConnection
public void putConnection(Connection c)
Description copied from class:AbstractConnectionPool
Returns a connection to the pool.- Specified by:
putConnection
in classAbstractConnectionPool
- Parameters:
c
- connection
-
toString
public String toString()
- Overrides:
toString
in classAbstractConnectionPool
-
-