DODS 7.3 API

com.lutris.appserver.server.sql.standard
Class SimpleConnectionAllocator

java.lang.Object
  extended by com.lutris.appserver.server.sql.standard.SimpleConnectionAllocator
All Implemented Interfaces:
ConnectionAllocator, ExtendedConnectionAllocator

public class SimpleConnectionAllocator
extends java.lang.Object
implements ExtendedConnectionAllocator

Brief description of the patch: Since each long-time used connection holds too much memory (about 15Mb after several hours of work) it was decided to close and recreate connections that were allocated more than the MaxConnectionUsages value set in the proper config file. We also changed the stack-like structure of the connection pool to queue-like. This guarantees that no connections become stagnant. 4.07.2003


Field Summary
protected  java.lang.String connectionAllocateCheckSql
          database "ConnectionCheckSql" string
protected  java.lang.String connectionReleaseCheckSql
          database "ConnectionReleaseCheckSql" string
protected  int generation
          Generation number.
protected  LogicalDatabase logicalDatabase
          Reference to the logical database for easy access to the connection pool.
protected  int maxPreparedStatements
          Maximum number of prepared statements to use; if less-than zero, then JDBC is queried for this value.
protected  int maxWaitingConnections
          JP Patch Maximum number of DBConnections that will be waiting in the pool
protected  long numRequests
          Number of queries or transactions on this logical database.
protected  java.lang.String password
          SQL password..
protected  int queryTimeOut
          Maximum amount of time in seconds to block on a query.
protected  java.lang.String shutDownStr
          database "ShutDown" string
protected  boolean sqlLogging
          Indicates if logging is enabled.
protected  int transactionTimeOut
          Maximum amount of time in seconds to block on a transaction.
protected  java.lang.String url
          JDBC URL of database.
protected  java.lang.String user
          SQL user name.
 
Constructor Summary
SimpleConnectionAllocator(LogicalDatabase logicalDatabase, Config conConfig)
          Initialize the connection allocator object.
 
Method Summary
 DBConnection allocate()
          Allocate a connection to a thread.
protected  DBConnection createConnection()
          Create a new connection in the pool.
 void drop(DBConnection dbConnection)
          Called when a connection in this pool has an SQL error.
 void dropAllNow()
          Called when the database manager is shutting down: Close all connections immediately.
protected  void finalize()
          Finalizer.
 int getActiveCount()
          Return the number of currently active connections.
 java.lang.String getDatabaseName()
           
 int getMaxCount()
          Return the maximum number of connections active at one time.
 java.util.Date getMaxCountDate()
          Return the time when the maximum connection count occured.
 long getRequestCount()
          Return the number of database requests.
 void incrementRequesteCount()
           
 boolean performRollbackOnReset()
           
 void release(DBConnection dbConnection)
          Return a connection to the pool.
 void resetMaxCount()
          Reset the maximum connection count and date.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logicalDatabase

protected LogicalDatabase logicalDatabase
Reference to the logical database for easy access to the connection pool.


url

protected java.lang.String url
JDBC URL of database.


user

protected java.lang.String user
SQL user name.


password

protected java.lang.String password
SQL password..


shutDownStr

protected java.lang.String shutDownStr
database "ShutDown" string


connectionAllocateCheckSql

protected java.lang.String connectionAllocateCheckSql
database "ConnectionCheckSql" string


connectionReleaseCheckSql

protected java.lang.String connectionReleaseCheckSql
database "ConnectionReleaseCheckSql" string


numRequests

protected long numRequests
Number of queries or transactions on this logical database.


maxWaitingConnections

protected int maxWaitingConnections
JP Patch Maximum number of DBConnections that will be waiting in the pool


sqlLogging

protected boolean sqlLogging
Indicates if logging is enabled.


queryTimeOut

protected int queryTimeOut
Maximum amount of time in seconds to block on a query. The DBQuery object will retrieve this value from the connection.


transactionTimeOut

protected int transactionTimeOut
Maximum amount of time in seconds to block on a transaction. The DBTransaction object will retrieve this value from the connection.


maxPreparedStatements

protected int maxPreparedStatements
Maximum number of prepared statements to use; if less-than zero, then JDBC is queried for this value.


generation

protected int generation
Generation number. When an SQL error occurs, all objects of the same generation or earlier are dropped.

Constructor Detail

SimpleConnectionAllocator

public SimpleConnectionAllocator(LogicalDatabase logicalDatabase,
                                 Config conConfig)
                          throws ConfigException
Initialize the connection allocator object. Connections are opened on demand and stored in a pool.

Parameters:
logicalDatabase - LogicalDatabase.
conConfig - LogicalDatabase Config object
Throws:
ConfigException - if bad configuration information is given in the config file.
Method Detail

createConnection

protected DBConnection createConnection()
                                 throws java.sql.SQLException
Create a new connection in the pool.

Throws:
java.sql.SQLException - If a SQL error occures.

allocate

public DBConnection allocate()
                      throws java.sql.SQLException
Allocate a connection to a thread. If none are available, grow the pool. If the pool is alredy its maximum size, then the thread waits.

Specified by:
allocate in interface ConnectionAllocator
Returns:
The allocated connection object.
Throws:
java.sql.SQLException - If a SQL error occures.

release

public void release(DBConnection dbConnection)
Return a connection to the pool. If it is of an old generation, close and drop.

Specified by:
release in interface ConnectionAllocator
Parameters:
dbConnection - The connection object to return.

drop

public void drop(DBConnection dbConnection)
Called when a connection in this pool has an SQL error. All unallocated connections in the pool are dropped if they have a generation number less than or equal to the error connection. If the current generation number is the same as this generation number, increment it. This way so that all outstanding connections (including the one passed in) of the same generation are dropped when returned.

Specified by:
drop in interface ConnectionAllocator
Parameters:
dbConnection - The connection object to drop. The connection should be returned to the pool after this function returns.

dropAllNow

public void dropAllNow()
Called when the database manager is shutting down: Close all connections immediately.

Specified by:
dropAllNow in interface ConnectionAllocator

getActiveCount

public int getActiveCount()
Return the number of currently active connections.

Specified by:
getActiveCount in interface ConnectionAllocator
Returns:
The number of connections.

getMaxCount

public int getMaxCount()
Return the maximum number of connections active at one time.

Specified by:
getMaxCount in interface ConnectionAllocator
Returns:
The number of connections.

getMaxCountDate

public java.util.Date getMaxCountDate()
Return the time when the maximum connection count occured.

Specified by:
getMaxCountDate in interface ConnectionAllocator
Returns:
The Date when the maximum connection count occured.

resetMaxCount

public void resetMaxCount()
Reset the maximum connection count and date.

Specified by:
resetMaxCount in interface ConnectionAllocator

getRequestCount

public long getRequestCount()
Return the number of database requests.

Specified by:
getRequestCount in interface ConnectionAllocator
Returns:
The number of database requests (queries or transactions).

finalize

protected void finalize()
Finalizer. If any connections allocated by this object have not been closed, this method ensures that garbage collection does so.

Overrides:
finalize in class java.lang.Object

getDatabaseName

public java.lang.String getDatabaseName()
Specified by:
getDatabaseName in interface ConnectionAllocator
Returns:
database name of current connection

incrementRequesteCount

public void incrementRequesteCount()
Specified by:
incrementRequesteCount in interface ExtendedConnectionAllocator

performRollbackOnReset

public boolean performRollbackOnReset()
Specified by:
performRollbackOnReset in interface ExtendedConnectionAllocator

DODS 7.3 API