org.jtools.jpool.system
Class Pool

java.lang.Object
  extended byorg.jtools.jpool.system.Pool

public class Pool
extends java.lang.Object

 Pool Class
 The pool class contains a collection of connection to the database as specified in
 the configuration object. You can retrieved pooled connections and return them in
 order for other user to use these connections. Additionally you can request for
 current pool information as also the configuration values.
 

Version:
$Id: Pool.java,v 1.1 2003/10/15 15:37:31 stfndln Exp $
Author:
Stefaan Delanghe (stfndln@yahoo.com)

Constructor Summary
Pool(PoolConfig _config)
          Constructs the pool based up the given configuration object
 
Method Summary
protected  java.sql.Connection createConnection()
          Creates a new connection as specified with the values in the configuration object.
 PoolConfig getConfig()
          Retrieves the configuration object for this pool object
 java.sql.Connection getConnection()
          Retrieves a connection from this pool which you can use as you need it.
 int getNumberFreeConnections()
          Retrieves the number of free connections
 int getNumberUsedConnections()
          Retrieves the number of used connections.
protected  java.sql.Connection getPooledConnection()
          Retrieves a pooled connection and checks if the connection is still within the limit of the maximum defined number of connections.
 java.lang.String getStats()
          Returns a string value with the current statistics of the pool.
protected  void initialize()
          Initializes the pool.
protected  boolean isConnectionExpired(java.sql.Connection _conn)
          Checks if a connection is expired or not based upon the expire value in the configuration object.
protected  java.sql.Connection retrieveConnection(long _timeout)
          Tries to retrieves a connection from the pool but the given timeout may not be exceded.
 boolean returnConnection(java.sql.Connection _conn)
          Returns a requested pool connection to the pool and makes it available again for request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pool

public Pool(PoolConfig _config)
Constructs the pool based up the given configuration object

Parameters:
_config - Configuration object to initialize the pool
Method Detail

initialize

protected void initialize()
                   throws java.sql.SQLException
Initializes the pool. The initial number of connections are created as defined in the configuration object.

Throws:
java.sql.SQLException - failed to initialize the pool object

createConnection

protected java.sql.Connection createConnection()
                                        throws java.sql.SQLException
Creates a new connection as specified with the values in the configuration object.

Returns:
The new connection object.
Throws:
java.sql.SQLException - thrown when failed to create a new connection

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Retrieves a connection from this pool which you can use as you need it.

Returns:
a connection object for your use
Throws:
java.sql.SQLException - thrown when failed to get a pooled connection

retrieveConnection

protected java.sql.Connection retrieveConnection(long _timeout)
                                          throws java.sql.SQLException
Tries to retrieves a connection from the pool but the given timeout may not be exceded.

Parameters:
_timeout - The maximum time to try and get a pooled connection
Returns:
A connection from the pool
Throws:
java.sql.SQLException - thrown when failed to retrieve a pooled connection

getPooledConnection

protected java.sql.Connection getPooledConnection()
                                           throws java.sql.SQLException
Retrieves a pooled connection and checks if the connection is still within the limit of the maximum defined number of connections.

Returns:
A connection object
Throws:
java.sql.SQLException - thrown when retrieval of a pooled connection fails

isConnectionExpired

protected boolean isConnectionExpired(java.sql.Connection _conn)
                               throws java.sql.SQLException
Checks if a connection is expired or not based upon the expire value in the configuration object.

Parameters:
_conn - The connection to check for expiration
Returns:
if connection is expired returns true otherwise returns false
Throws:
java.sql.SQLException - thrown when an error occurs during the check

returnConnection

public boolean returnConnection(java.sql.Connection _conn)
Returns a requested pool connection to the pool and makes it available again for request. If connection is closed then the connection is removed.

Parameters:
_conn - The connection to return to the pool
Returns:
if the returning of the connection failed returns false otherwise returns true

getNumberUsedConnections

public int getNumberUsedConnections()
Retrieves the number of used connections.

Returns:
The number of used connections

getNumberFreeConnections

public int getNumberFreeConnections()
Retrieves the number of free connections

Returns:
The number of free connections.

getConfig

public PoolConfig getConfig()
Retrieves the configuration object for this pool object

Returns:
The pool configuration object

getStats

public java.lang.String getStats()
Returns a string value with the current statistics of the pool.

Returns:
A string with the statistics