org.objectweb.cjdbc.controller.connection
Class VariablePoolConnectionManager

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.connection.AbstractConnectionManager
      extended byorg.objectweb.cjdbc.controller.connection.AbstractPoolConnectionManager
          extended byorg.objectweb.cjdbc.controller.connection.VariablePoolConnectionManager
All Implemented Interfaces:
java.lang.Cloneable, XmlComponent

public class VariablePoolConnectionManager
extends AbstractPoolConnectionManager

This connection manager provides connection pooling with a dynamically adjustable pool size.

If the maximum number of active connections is not reached, the getConnection()method creates a connection. Else, the execution is blocked until a connection is freed or the timeout expires. blocked until a connection is freed or the timeout expires.

Idle connections in the pool are removed after the timeout idleTimeout if the minimum pool size has not been reached.

Version:
1.0
Author:
Emmanuel Cecchet , Mathieu Peltier , Nicolas Modrzyk

Nested Class Summary
protected  class VariablePoolConnectionManager.RemoveIdleConnectionsThread
          Allows to remove idle free connections after the idleTimeout timeout.
 
Field Summary
static int DEFAULT_IDLE_TIMEOUT
          Default idle timeout in milliseconds: default is 0 and means that once allocated, connections are never released.
static int DEFAULT_MAX_POOL_SIZE
          Default maximum pool size: default is 0 and means no limit.
static int DEFAULT_WAIT_TIMEOUT
          Default wait timeout in milliseconds: the default is 0 and means no timeout: waits until one connection is freed.
private  int idleTimeout
          Time a connection can stay idle before begin released (removed from the pool) in milliseconds (0 means forever)
private  int initPoolSize
          Initial pool size to be initialized at startup.
private  int maxPoolSize
          Maximum pool size.
private  int minPoolSize
          Minimum pool size.
private  java.util.LinkedList releaseTimes
          Stores the time on which connections have been released.
private  VariablePoolConnectionManager.RemoveIdleConnectionsThread removeIdleConnectionsThread
          Allow to remove idle connections in the pool.
private  int waitTimeout
          Maximum time to wait for a connection in milliseconds.
 
Fields inherited from class org.objectweb.cjdbc.controller.connection.AbstractPoolConnectionManager
activeConnections, freeConnections, poolSize
 
Fields inherited from class org.objectweb.cjdbc.controller.connection.AbstractConnectionManager
backendName, backendUrl, driverClassName, driverPath, initialized, logger, rLogin, rPassword
 
Fields inherited from interface org.objectweb.cjdbc.common.xml.XmlComponent
DOCTYPE_CONTROLLER, DOCTYPE_DB, XML_VERSION
 
Constructor Summary
VariablePoolConnectionManager(java.lang.String backendUrl, java.lang.String backendName, java.lang.String rLogin, java.lang.String rPassword, java.lang.String driverPath, java.lang.String driverClassName, int minPoolSize, int maxPoolSize, int idleTimeout, int waitTimeout)
          Creates a new VariablePoolConnectionManager instance with the default minPoolSize(initial pool size to be initialized at startup).
VariablePoolConnectionManager(java.lang.String backendUrl, java.lang.String backendName, java.lang.String rLogin, java.lang.String rPassword, java.lang.String driverPath, java.lang.String driverClassName, int initPoolSize, int minPoolSize, int maxPoolSize, int idleTimeout, int waitTimeout)
          Creates a new VariablePoolConnectionManager instance.
 
Method Summary
protected  java.lang.Object clone()
           
 void deleteConnection(java.sql.Connection c)
          Delete a connection that is no more valid.
 void finalizeConnections()
          Releases all the connections to the database.
 java.sql.Connection getConnection()
          Gets a connection from the pool.
 int getIdleTimeout()
          Gets the idle timeout.
 int getMaxPoolSize()
          Gets the max pool size.
 int getMinPoolSize()
          Gets the min pool size.
 int getWaitTimeout()
          Gets the wait timeout.
 java.lang.String getXmlImpl()
          Gets xml formatted information on this connection manager
 void initializeConnections()
          Initializes the connection(s) to the database.
 void releaseConnection(java.sql.Connection c)
          Releases a connection.
 
Methods inherited from class org.objectweb.cjdbc.controller.connection.AbstractPoolConnectionManager
getCurrentNumberOfConnections, initializeConnections
 
Methods inherited from class org.objectweb.cjdbc.controller.connection.AbstractConnectionManager
copy, deleteConnection, finalize, getConnection, getConnectionFromDriver, getDriverClassName, getDriverPath, getLogin, getPassword, getVLogin, getXml, isInitialized, releaseConnection, retrieveConnection, setDriverClassName, setDriverPath, setLogin, setPassword, setVLogin
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_POOL_SIZE

public static final int DEFAULT_MAX_POOL_SIZE
Default maximum pool size: default is 0 and means no limit.

See Also:
Constant Field Values

DEFAULT_IDLE_TIMEOUT

public static final int DEFAULT_IDLE_TIMEOUT
Default idle timeout in milliseconds: default is 0 and means that once allocated, connections are never released.

See Also:
Constant Field Values

DEFAULT_WAIT_TIMEOUT

public static final int DEFAULT_WAIT_TIMEOUT
Default wait timeout in milliseconds: the default is 0 and means no timeout: waits until one connection is freed.

See Also:
Constant Field Values

initPoolSize

private int initPoolSize
Initial pool size to be initialized at startup.


minPoolSize

private int minPoolSize
Minimum pool size.


maxPoolSize

private int maxPoolSize
Maximum pool size.


idleTimeout

private int idleTimeout
Time a connection can stay idle before begin released (removed from the pool) in milliseconds (0 means forever)


waitTimeout

private int waitTimeout
Maximum time to wait for a connection in milliseconds.


releaseTimes

private java.util.LinkedList releaseTimes
Stores the time on which connections have been released.


removeIdleConnectionsThread

private VariablePoolConnectionManager.RemoveIdleConnectionsThread removeIdleConnectionsThread
Allow to remove idle connections in the pool.

Constructor Detail

VariablePoolConnectionManager

public VariablePoolConnectionManager(java.lang.String backendUrl,
                                     java.lang.String backendName,
                                     java.lang.String rLogin,
                                     java.lang.String rPassword,
                                     java.lang.String driverPath,
                                     java.lang.String driverClassName,
                                     int minPoolSize,
                                     int maxPoolSize,
                                     int idleTimeout,
                                     int waitTimeout)
Creates a new VariablePoolConnectionManager instance with the default minPoolSize(initial pool size to be initialized at startup).

Parameters:
backendUrl - URL of the DatabaseBackend owning this connection manager
backendName - name of the DatabaseBackend owning this connection manager
rLogin - backend connection login to be used by this connection manager
rPassword - backend connection password to be used by this connection manager
driverPath - path for driver
driverClassName - class name for driver
minPoolSize - minimum pool size.
maxPoolSize - maximum pool size. 0 means no limit.
idleTimeout - time a connection can stay idle before begin released (removed from the pool) in seconds. 0 means no timeout: once allocated, connections are never released.
waitTimeout - maximum time to wait for a connection in seconds. 0 means no timeout: waits until one connection is freed.

VariablePoolConnectionManager

public VariablePoolConnectionManager(java.lang.String backendUrl,
                                     java.lang.String backendName,
                                     java.lang.String rLogin,
                                     java.lang.String rPassword,
                                     java.lang.String driverPath,
                                     java.lang.String driverClassName,
                                     int initPoolSize,
                                     int minPoolSize,
                                     int maxPoolSize,
                                     int idleTimeout,
                                     int waitTimeout)
Creates a new VariablePoolConnectionManager instance.

Parameters:
backendUrl - URL of the DatabaseBackend owning this connection manager
backendName - name of the DatabaseBackend owning this connection manager
rLogin - backend connection login to be used by this connection manager
rPassword - backend connection password to be used by this connection manager
driverPath - path for driver
driverClassName - class name for driver
initPoolSize - initial pool size to be intialized at startup
minPoolSize - minimum pool size.
maxPoolSize - maximum pool size. 0 means no limit.
idleTimeout - time a connection can stay idle before begin released (removed from the pool) in seconds. 0 means no timeout: once allocated, connections are never released.
waitTimeout - maximum time to wait for a connection in seconds. 0 means no timeout: waits until one connection is freed.
Method Detail

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
Specified by:
clone in class AbstractConnectionManager
Throws:
java.lang.CloneNotSupportedException
See Also:
Object.clone()

getMaxPoolSize

public int getMaxPoolSize()
Gets the max pool size.

Returns:
a int value.

getMinPoolSize

public int getMinPoolSize()
Gets the min pool size.

Returns:
a int value.

getIdleTimeout

public int getIdleTimeout()
Gets the idle timeout.

Returns:
a int value.

getWaitTimeout

public int getWaitTimeout()
Gets the wait timeout.

Returns:
a int value.

initializeConnections

public void initializeConnections()
                           throws java.sql.SQLException
Description copied from class: AbstractConnectionManager
Initializes the connection(s) to the database. The caller must ensure that the driver has already been loaded else an exception will be thrown.

Overrides:
initializeConnections in class AbstractPoolConnectionManager
Throws:
java.sql.SQLException
See Also:
AbstractPoolConnectionManager.initializeConnections()

finalizeConnections

public void finalizeConnections()
                         throws java.sql.SQLException
Description copied from class: AbstractConnectionManager
Releases all the connections to the database.

Overrides:
finalizeConnections in class AbstractPoolConnectionManager
Throws:
java.sql.SQLException
See Also:
AbstractConnectionManager.finalizeConnections()

getConnection

public java.sql.Connection getConnection()
                                  throws UnreachableBackendException
Gets a connection from the pool.

If the current number of active connections is lower than the maximum pool size, a new connection is created. If the creation fails, this method waits for a connection to be freed.

If the maximum number of active connections is reached, this methods blocks until a connection is freed or the timeout expires.

Specified by:
getConnection in class AbstractConnectionManager
Returns:
a connection from the pool or null if the timeout has expired.
Throws:
UnreachableBackendException - if the backend must be disabled
See Also:
AbstractConnectionManager.getConnection()

releaseConnection

public void releaseConnection(java.sql.Connection c)
Description copied from class: AbstractConnectionManager
Releases a connection.

Specified by:
releaseConnection in class AbstractConnectionManager
Parameters:
c - the connection to release.
See Also:
AbstractConnectionManager.releaseConnection(Connection)

deleteConnection

public void deleteConnection(java.sql.Connection c)
Description copied from class: AbstractConnectionManager
Delete a connection that is no more valid.

Specified by:
deleteConnection in class AbstractConnectionManager
Parameters:
c - the connection to delete.
See Also:
AbstractConnectionManager.deleteConnection(Connection)

getXmlImpl

public java.lang.String getXmlImpl()
Description copied from class: AbstractConnectionManager
Gets xml formatted information on this connection manager

Specified by:
getXmlImpl in class AbstractConnectionManager
Returns:
xml formatted string that conforms to c-jdbc.dtd
See Also:
AbstractConnectionManager.getXmlImpl()


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.