org.apache.avalon.excalibur.datasource
Class ResourceLimitingJdbcDataSource

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
          extended byorg.apache.avalon.excalibur.datasource.ResourceLimitingJdbcDataSource
All Implemented Interfaces:
Component, Configurable, DataSourceComponent, Disposable, Instrumentable, LogEnabled, ThreadSafe

public class ResourceLimitingJdbcDataSource
extends AbstractLogEnabledInstrumentable
implements DataSourceComponent, Disposable

The ResourceLimiting implementation for DataSources in Avalon. This uses the normal java.sql.Connection object and java.sql.DriverManager.

This datasource pool implementation is designed to make as many database connections as are needed available without placing undo load on the database server.

If an application under normal load needs 3 database connections for example, then the max pool size should be set to a value like 10. This will allow the pool to grow to accomodate a sudden spike in load without allowing the pool to grow to such a large size as to place undo load on the database server. The pool's trimming features will keep track of how many connections are actually needed and close those connections which are no longer required.

Configuration Example:

   <rl-jdbc>
     <pool-controller max="10" max-strict="true"
       blocking="true" timeout="-1"
       trim-interval="60000" auto-commit="true"
       connection-class="my.overrided.ConnectionClass">
       <keep-alive disable="false" age="5000">select 1</keep-alive>
     </pool-controller>
     <driver>com.database.jdbc.JdbcDriver</driver>
     <dburl>jdbc:driver://host/mydb</dburl>
     <user>username</user>
     <password>password</password>
   </rl-jdbc>
 

Roles Example:

   <role name="org.apache.avalon.excalibur.datasource.DataSourceComponentSelector"
     shorthand="datasources"
     default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
     <hint shorthand="rl-jdbc"
       class="org.apache.avalon.excalibur.datasource.ResourceLimitingJdbcDataSource"/>
   </role>
 

Configuration Attributes:

Since:
4.1
Version:
CVS $Revision: 1.5 $ $Date: 2004/03/30 15:58:50 $
Author:
Avalon Development Team

Field Summary
protected  InstrumentedResourceLimitingPool m_pool
           
 
Fields inherited from interface org.apache.avalon.excalibur.datasource.DataSourceComponent
ROLE
 
Fields inherited from interface org.apache.excalibur.instrument.Instrumentable
EMPTY_INSTRUMENT_ARRAY, EMPTY_INSTRUMENTABLE_ARRAY
 
Constructor Summary
ResourceLimitingJdbcDataSource()
           
 
Method Summary
 void configure(Configuration configuration)
          Pass the Configuration to the Configurable class.
 void dispose()
          The dispose operation is called at the end of a components lifecycle.
 java.sql.Connection getConnection()
          Gets the Connection to the database
 
Methods inherited from class org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
addChildInstrumentable, addInstrument, getChildInstrumentables, getInstrumentableName, getInstruments, setInstrumentableName
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_pool

protected InstrumentedResourceLimitingPool m_pool
Constructor Detail

ResourceLimitingJdbcDataSource

public ResourceLimitingJdbcDataSource()
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Gets the Connection to the database

Specified by:
getConnection in interface DataSourceComponent
Returns:
Connection a valid connection for you to use
Throws:
NoValidConnectionException - when there is no valid Connection wrapper available in the classloader.
NoAvailableConnectionException - when there are no more available Connections in the pool.
java.sql.SQLException

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Pass the Configuration to the Configurable class. This method must always be called after the constructor and before any other method.

Specified by:
configure in interface Configurable
Parameters:
configuration - the class configurations.
Throws:
ConfigurationException - if an error occurs

dispose

public void dispose()
The dispose operation is called at the end of a components lifecycle. This method will be called after Startable.stop() method (if implemented by component). Components use this method to release and destroy any resources that the Component owns.

Specified by:
dispose in interface Disposable


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.