org.ldaptive.pool
Class BlockingConnectionPool

java.lang.Object
  extended by org.ldaptive.pool.AbstractPool<Connection>
      extended by org.ldaptive.pool.AbstractConnectionPool
          extended by org.ldaptive.pool.BlockingConnectionPool
All Implemented Interfaces:
ConnectionPool
Direct Known Subclasses:
SoftLimitConnectionPool

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 by getBlockWaitTime(). By default the pool will block indefinitely 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. See AbstractConnectionPool.

Version:
$Revision: 2967 $ $Date: 2014-04-09 16:37:01 -0400 (Wed, 09 Apr 2014) $
Author:
Middleware Services

Nested Class Summary
 
Nested classes/interfaces inherited from class org.ldaptive.pool.AbstractConnectionPool
AbstractConnectionPool.DefaultPooledConnectionProxy
 
Field Summary
 
Fields inherited from class org.ldaptive.pool.AbstractConnectionPool
active, available, checkInLock, checkOutLock, poolLock, poolNotEmpty
 
Fields inherited from class org.ldaptive.pool.AbstractPool
logger
 
Constructor Summary
BlockingConnectionPool()
          Creates a new blocking pool.
BlockingConnectionPool(DefaultConnectionFactory cf)
          Creates a new blocking pool.
BlockingConnectionPool(PoolConfig pc, DefaultConnectionFactory cf)
          Creates a new blocking pool.
 
Method Summary
protected  PooledConnectionProxy blockAvailableConnection()
          This blocks until a connection can be acquired.
 long 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(long time)
          Sets the block wait time.
 
Methods inherited from class org.ldaptive.pool.AbstractConnectionPool
activateAndValidateConnection, activeCount, availableCount, close, createActiveConnection, createActiveConnection, createAvailableConnection, createAvailableConnection, createConnection, createConnection, createConnectionProxy, finalize, getConnectionFactory, getConnectOnCreate, getFailFastInitialize, getPooledConnectionStatistics, getQueueType, grow, grow, initialize, isInitialized, prune, removeActiveConnection, removeAvailableAndActiveConnection, removeAvailableConnection, retrieveConnectionProxy, setConnectionFactory, setConnectOnCreate, setFailFastInitialize, setQueueType, toString, validate, validateAndPassivateConnection
 
Methods inherited from class org.ldaptive.pool.AbstractPool
activate, getActivator, getName, getPassivator, getPoolConfig, getPruneStrategy, getValidator, passivate, setActivator, setName, setPassivator, setPoolConfig, setPruneStrategy, setValidator, validate
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ldaptive.pool.ConnectionPool
getActivator, getPassivator, getValidator, setActivator, setPassivator, setValidator
 

Constructor Detail

BlockingConnectionPool

public BlockingConnectionPool()
Creates a new blocking pool.


BlockingConnectionPool

public BlockingConnectionPool(DefaultConnectionFactory cf)
Creates a new blocking pool. The pool config is initialized with the default values.

Parameters:
cf - connection factory

BlockingConnectionPool

public BlockingConnectionPool(PoolConfig pc,
                              DefaultConnectionFactory cf)
Creates a new blocking pool.

Parameters:
pc - pool configuration
cf - connection factory
Method Detail

getBlockWaitTime

public long getBlockWaitTime()
Returns the block wait time. Default time is 0, which will wait indefinitely.

Returns:
time in milliseconds to wait for available connections

setBlockWaitTime

public void setBlockWaitTime(long time)
Sets the block wait time. Default time is 0, which will wait indefinitely.

Parameters:
time - in milliseconds to wait for available connections

getConnection

public Connection getConnection()
                         throws PoolException
Returns a connection from the pool.

Specified by:
getConnection in interface ConnectionPool
Specified by:
getConnection in class AbstractConnectionPool
Returns:
connection
Throws:
PoolException - if this operation fails
BlockingTimeoutException - if this pool is configured with a block time and it occurs
PoolInterruptedException - if this pool is configured with a block time and the current thread is interrupted

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 fails
BlockingTimeoutException - if this pool is configured with a block time and it occurs
PoolInterruptedException - if the current thread is interrupted

putConnection

public void putConnection(Connection c)
Returns a connection to the pool.

Specified by:
putConnection in class AbstractConnectionPool
Parameters:
c - connection


Copyright © 2003-2015 Virginia Tech. All Rights Reserved.