connectionpool
Class SmartPoolFactory

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

public class SmartPoolFactory
extends java.lang.Object

SmartPoolFactory provides a Singleton interface to the implementation of the PoolManager Interface. An object of SmartPoolFactory should be loaded with the configuration file prior to calling any static methods on the class. Once a object is loaded it maintains a single instance of PoolManager across all objects and static methods can be directly invoked on the class without creating any other instance of SmartPoolFactory. // Creating an instance .

	SmartPoolFactory = new SmartPoolFactory(); 
 

// using SmartPoolFactory once it is initialised.

	 Connection conn = SmartPoolFactory.getConnection();	
  

It is advisable to load the SmartPoolFactory on your application boot up (start-up-servlet in a web application), so that it is available for other components from the word go.


Constructor Summary
SmartPoolFactory(java.io.File file)
          This constructor intialises the SmartPoolClass , reads the configuration from file and loads the PoolManger.
SmartPoolFactory(java.lang.String fileName)
          This constructor intialises the SmartPoolClass , reads the configuration from fileName and loads the PoolManger.
 
Method Summary
static 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.
static java.sql.Connection getConnection()
          This method returns a Connection from the default connection pool.
static java.sql.Connection getConnection(java.lang.String poolName)
          This method returns a Connection from the pool poolName.
static java.sql.Connection getConnection(java.lang.String poolName, java.lang.String owner)
          This method returns a Connection from the pool poolName.
static PoolMonitor getPoolMonitor(java.lang.String poolName)
          This method returns the instance of PoolMonitor for the pool poolName
static void main(java.lang.String[] arg)
           
static 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

SmartPoolFactory

public SmartPoolFactory(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

SmartPoolFactory

public SmartPoolFactory(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
Method Detail

getConnection

public static 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.
Returns:
Connection from the default pool
Throws:
ConnectionPoolException - if there is any problem getting connection.

getConnection

public static 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.
Parameters:
poolName - Name of the pool.
Returns:
Connection from the pool
Throws:
ConnectionPoolException - if there is any problem getting connection.

getConnection

public static 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.
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 static 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.
Parameters:
poolName - Name of the pool.
cle - Class implementing ConnectionLeakListener interface.
Throws:
ConnectionPoolException - If there is any problem adding ConnectionLeakListener.

removeConnectionLeakListener

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

getPoolMonitor

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

main

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