org.objectweb.cjdbc.controller.connection
Class RandomWaitPoolConnectionManager

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

public class RandomWaitPoolConnectionManager
extends AbstractPoolConnectionManager

This connection manager waits when the pool is empty. Requests are stacked using the Java wait/notify mechanism. Therefore the FIFO order is not guaranteed and the first request to get the freed connection is the thread that gets elected by the scheduler.

Version:
1.0
Author:
Emmanuel Cecchet , Nicolas Modrzyk

Field Summary
private  int timeout
          Time to wait for a connection in milliseconds (0 means wait forever).
 
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
RandomWaitPoolConnectionManager(java.lang.String backendUrl, java.lang.String backendName, java.lang.String login, java.lang.String password, java.lang.String driverPath, java.lang.String driverClassName, int poolSize, int timeout)
          Creates a new RandomWaitPoolConnectionManager instance.
 
Method Summary
protected  java.lang.Object clone()
           
 void deleteConnection(java.sql.Connection c)
          Delete a connection that is no more valid.
 java.sql.Connection getConnection()
          Gets a connection from the pool.
 int getTimeout()
          Gets the timeout.
 java.lang.String getXmlImpl()
          Gets xml formatted information on this connection manager
 void releaseConnection(java.sql.Connection c)
          Releases a connection.
 
Methods inherited from class org.objectweb.cjdbc.controller.connection.AbstractPoolConnectionManager
finalizeConnections, getCurrentNumberOfConnections, initializeConnections, 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

timeout

private int timeout
Time to wait for a connection in milliseconds (0 means wait forever).

Constructor Detail

RandomWaitPoolConnectionManager

public RandomWaitPoolConnectionManager(java.lang.String backendUrl,
                                       java.lang.String backendName,
                                       java.lang.String login,
                                       java.lang.String password,
                                       java.lang.String driverPath,
                                       java.lang.String driverClassName,
                                       int poolSize,
                                       int timeout)
Creates a new RandomWaitPoolConnectionManager instance.

Parameters:
backendUrl - URL of the DatabaseBackend owning this connection manager
backendName - name of the DatabaseBackend owning this connection manager
login - backend connection login to be used by this connection manager
password - backend connection password to be used by this connection manager
driverPath - path for driver
driverClassName - class name for driver
poolSize - size of the connection pool
timeout - time to wait for a connection in seconds (0 means wait forever)
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()

getTimeout

public int getTimeout()
Gets the timeout.

Returns:
a int value.

getConnection

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

If the pool is empty, 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.