Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.lutris.appserver.server.sql.standard
Class StandardConnectionAllocator  view StandardConnectionAllocator download StandardConnectionAllocator.java

java.lang.Object
  extended bycom.lutris.appserver.server.sql.standard.StandardConnectionAllocator
All Implemented Interfaces:
com.lutris.appserver.server.sql.ConnectionAllocator

public class StandardConnectionAllocator
extends java.lang.Object
implements com.lutris.appserver.server.sql.ConnectionAllocator

Manages a pool (set) of connections to a database. The pool is named as a logical database. By naming a pool, this allows connection resource control to be on a finer grain that a database and allows for easier migration to multiple databases. One or more pools can map to the same actual database. A connection considered part of the pool, even if its allocated to a thread. These objects are all publicly accessed via the Database Manager, not directly.

If an error occurs in a connection, it is dropped from the pool. The process using the connection has already received an error which aborts the work in progress. By dropping the connection, waiting threads are restarted. If something is wrong with the database (e.g. server is down), they will recieve errors and also be aborted. A generation number is used to close down all connections that were open when the error occured, allowing new connections to be allocated.

The configuration data is specified in the section: DatabaseManager.DB.dbName.Connection

Configuration sub fields are:

It would be nice to add a config parameter that would disable caching of PreparedStatements.

Since:
LBS1.8
Version:
$Revision: 1.10.12.1 $

Field Summary
private  java.util.Date biggestPoolDate
          Date at which the biggest pool size occured.
private  int biggestPoolSize
          Maximum size the pool ever got to, regardless of generation.
private  int currentPoolSize
          Current size of the pool; includes allocated connections.
protected  int generation
          Generation number.
private  com.lutris.logging.LogChannel log
          The log channel.
protected  com.lutris.appserver.server.sql.LogicalDatabase logicalDatabase
          Reference to the logical database for easy access to the connection pool.
private  int maxPoolSize
          Maximum number of connections in the pool.
protected  int maxPreparedStatements
          Maximum number of prepared statements to use; if less-than zero, then JDBC is queried for this value.
protected  long numRequests
          Number of queries or transactions on this logical database.
protected  java.lang.String password
          SQL password..
private  java.util.Stack pool
          The actual pool of DBConnection objects.
protected  int queryTimeOut
          Maximum amount of time in seconds to block on a query.
protected  boolean sqlLogging
          Indicates if logging is enabled.
private  int timeOut
          Maximum amount of time in milliseconds to wait for a connection.
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
protected StandardConnectionAllocator(com.lutris.appserver.server.sql.LogicalDatabase logicalDatabase, com.lutris.util.Config conConfig)
          Initialize the connection allocator object.
 
Method Summary
 com.lutris.appserver.server.sql.DBConnection allocate()
          Allocate a connection to a thread.
protected  com.lutris.appserver.server.sql.DBConnection createConnection()
          Create a new connection in the pool.
 void drop(com.lutris.appserver.server.sql.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.
 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 release(com.lutris.appserver.server.sql.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 com.lutris.appserver.server.sql.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..


maxPoolSize

private int maxPoolSize
Maximum number of connections in the pool. If this value is <= zero, then create as many connections as possible.


currentPoolSize

private int currentPoolSize
Current size of the pool; includes allocated connections.


biggestPoolSize

private int biggestPoolSize
Maximum size the pool ever got to, regardless of generation.


biggestPoolDate

private java.util.Date biggestPoolDate
Date at which the biggest pool size occured.


numRequests

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


pool

private java.util.Stack pool
The actual pool of DBConnection objects.


sqlLogging

protected boolean sqlLogging
Indicates if logging is enabled.


timeOut

private int timeOut
Maximum amount of time in milliseconds to wait for a connection.


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.


log

private com.lutris.logging.LogChannel log
The log channel.

Constructor Detail

StandardConnectionAllocator

protected StandardConnectionAllocator(com.lutris.appserver.server.sql.LogicalDatabase logicalDatabase,
                                      com.lutris.util.Config conConfig)
                               throws com.lutris.util.ConfigException
Initialize the connection allocator object. Connections are opened on demand and stored in a pool.

Method Detail

createConnection

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


allocate

public com.lutris.appserver.server.sql.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 com.lutris.appserver.server.sql.ConnectionAllocator

release

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

Specified by:
release in interface com.lutris.appserver.server.sql.ConnectionAllocator

drop

public void drop(com.lutris.appserver.server.sql.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 com.lutris.appserver.server.sql.ConnectionAllocator

dropAllNow

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

Specified by:
dropAllNow in interface com.lutris.appserver.server.sql.ConnectionAllocator

getActiveCount

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

Specified by:
getActiveCount in interface com.lutris.appserver.server.sql.ConnectionAllocator

getMaxCount

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

Specified by:
getMaxCount in interface com.lutris.appserver.server.sql.ConnectionAllocator

getMaxCountDate

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

Specified by:
getMaxCountDate in interface com.lutris.appserver.server.sql.ConnectionAllocator

resetMaxCount

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

Specified by:
resetMaxCount in interface com.lutris.appserver.server.sql.ConnectionAllocator

getRequestCount

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

Specified by:
getRequestCount in interface com.lutris.appserver.server.sql.ConnectionAllocator

finalize

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