connectionpool
Class PoolManagerImpl

java.lang.Object
  |
  +--connectionpool.PoolManagerImpl

public class PoolManagerImpl
extends java.lang.Object
implements PoolManager

This class implements the PoolManager interface.The basic responsibility of this class is to load the configuration file , and initialise the pools and priovide a single point access to the pools.


Inner Class Summary
static class PoolManagerImpl.ThreadRunner
           
 
Constructor Summary
PoolManagerImpl(java.io.File file)
          This constructor intialises the SmartPoolClass , reads the configuration from file and loads the PoolManger.
PoolManagerImpl(java.lang.String fileName)
          This constructor intialises the SmartPoolClass , reads the configuration from fileName and loads the PoolManger.
 
Method Summary
 void addConnectionLeakListener(java.lang.String poolName, ConnectionLeakListener cle)
          This method adds a connection leak listener.The methods of cle will be called when a leak is detected as per the pool configuration.
 java.sql.Connection getConnection()
          This method returns a Connection from the default connection pool.
 java.sql.Connection getConnection(java.lang.String poolName)
          This method returns a Connection from the pool poolName.
 java.sql.Connection getConnection(java.lang.String poolName, java.lang.String owner)
          This method returns a Connection from the pool poolName.
 PoolMonitor getPoolMonitor(java.lang.String poolName)
          This method returns the instance of PoolMonitor for the pool poolName
static void main(java.lang.String[] args)
           
 void removeConnectionLeakListener(java.lang.String poolName, ConnectionLeakListener cle)
          This method removes a connection leak listener.cle will not get any further notifications.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PoolManagerImpl

public PoolManagerImpl(java.lang.String fileName)
                throws ConnectionPoolException
This constructor intialises the SmartPoolClass , reads the configuration from fileName and loads the PoolManger.
Parameters:
file - The absolute configuration file path.
Throws:
ConnectionPoolException - if there is any problem initialising the pools

PoolManagerImpl

public PoolManagerImpl(java.io.File file)
                throws ConnectionPoolException
This constructor intialises the SmartPoolClass , reads the configuration from file and loads the PoolManger.
Parameters:
file - The configuration file.
Throws:
ConnectionPoolException - if there is any problem initialising the pools
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws ConnectionPoolException
This method returns a Connection from the default connection pool. The owner of this pool is marked as N/A indicating unknown. Note: This method blocks if the pool size has reached it's maximum size and no free connections are available until a free connection is available. The time period for which this method blocks depends on the connection-wait-time-out specified in the configuration file.
Specified by:
getConnection in interface PoolManager
Returns:
Connection from the default pool
Throws:
ConnectionPoolException - if there is any problem getting connection.

getConnection

public java.sql.Connection getConnection(java.lang.String poolName)
                                  throws ConnectionPoolException
This method returns a Connection from the pool poolName. The owner of this pool is marked as N/A indicating unknown. Note: This method blocks if the pool size has reached it's maximum size and no free connections are available until a free connection is available. The time period for which this method blocks depends on the connection-wait-time-out specified in the configuration file.
Specified by:
getConnection in interface PoolManager
Parameters:
poolName - Name of the pool.
Returns:
Connection from the pool
Throws:
ConnectionPoolException - if there is any problem getting connection.

getConnection

public java.sql.Connection getConnection(java.lang.String poolName,
                                         java.lang.String owner)
                                  throws ConnectionPoolException
This method returns a Connection from the pool poolName. The owner of this connection is identified by owner . Note: This method blocks if the pool size has reached it's maximum size and no free connections are available until a free connection is available. The time period for which this method blocks depends on the connection-wait-time-out specified in the configuration file.
Specified by:
getConnection in interface PoolManager
Parameters:
poolName - Name of the pool.
owner - String identifying the owner.
Returns:
Connection from the pool
Throws:
ConnectionPoolException - if there is any problem getting connection.

addConnectionLeakListener

public void addConnectionLeakListener(java.lang.String poolName,
                                      ConnectionLeakListener cle)
                               throws ConnectionPoolException
This method adds a connection leak listener.The methods of cle will be called when a leak is detected as per the pool configuration.
Specified by:
addConnectionLeakListener in interface PoolManager
Parameters:
poolName - Name of the pool.
cle - Class implementing ConnectionLeakListener interface.
Throws:
ConnectionPoolException - if there is any problem adding ConnectionLeakListener.

removeConnectionLeakListener

public void removeConnectionLeakListener(java.lang.String poolName,
                                         ConnectionLeakListener cle)
                                  throws ConnectionPoolException
This method removes a connection leak listener.cle will not get any further notifications.
Specified by:
removeConnectionLeakListener in interface PoolManager
Parameters:
poolName - Name of the pool.
cle - Class implementing ConnectionLeakListener interface.
Throws:
ConnectionPoolException - if there is any problem removing ConnectionLeakListener.

getPoolMonitor

public PoolMonitor getPoolMonitor(java.lang.String poolName)
                           throws ConnectionPoolException
This method returns the instance of PoolMonitor for the pool poolName
Specified by:
getPoolMonitor in interface PoolManager
Parameters:
poolName - Name of the pool.
Returns:
PoolMonitor interface to monitor the state of the pool
Throws:
ConnectionPoolException -  

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception