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.io.Serializable

public class VariablePoolConnectionManager
extends AbstractPoolConnectionManager
implements java.io.Serializable

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 waitTimeout expires.

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

Version:
1.0
Author:
Emmanuel Cecchet, Mathieu Peltier, Nicolas Modrzyk
See Also:
Serialized Form

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.Stack 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, initialized, logger, rLogin, rPassword
 
Constructor Summary
VariablePoolConnectionManager(java.lang.String backendUrl, java.lang.String backendName, java.lang.String rLogin, java.lang.String rPassword, 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, int initPoolSize, int minPoolSize, int maxPoolSize, int idleTimeout, int waitTimeout)
          Creates a new VariablePoolConnectionManager instance.
 
Method Summary
 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.
 java.lang.String getInformation()
          Gets information about this connection manager
 int getMaxPoolSize()
          Gets the max pool size.
 int getMinPoolSize()
          Gets the min pool size.
 int getWaitTimeout()
          Gets the wait timeout.
 java.lang.String getXmlInformation()
          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 and puts it back to the pool.
 
Methods inherited from class org.objectweb.cjdbc.controller.connection.AbstractPoolConnectionManager
initializeConnections
 
Methods inherited from class org.objectweb.cjdbc.controller.connection.AbstractConnectionManager
finalize, getConnection, getLogin, getPassword, isInitialized, releaseConnection, retrieveConnection, setLogin, setPassword
 
Methods inherited from class java.lang.Object
clone, 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.Stack 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,
                                     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
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,
                                     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
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

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.
See Also:
idleTimeout

getWaitTimeout

public int getWaitTimeout()
Gets the wait timeout.

Returns:
a int value.
See Also:
waitTimeout

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()
Gets a connection from the pool.

If the current number of active connections is lower than the maxminum pool size maxPoolSize, 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 waitTimeout expires.

Specified by:
getConnection in class AbstractConnectionManager
Returns:
a connection from the pool or null if the timeout has expired.
See Also:
AbstractConnectionManager.getConnection()

releaseConnection

public void releaseConnection(java.sql.Connection c)
Description copied from class: AbstractPoolConnectionManager
Releases a connection and puts it back to the pool. Note that the connection is not closed but only returns to the free connections pool.

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

getXmlInformation

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

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

getInformation

public java.lang.String getInformation()
Description copied from class: AbstractConnectionManager
Gets information about this connection manager

Specified by:
getInformation in class AbstractConnectionManager
Returns:
a String value containing information.
See Also:
AbstractConnectionManager.getInformation()


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