org.apache.avalon.excalibur.datasource
Class ResourceLimitingJdbcDataSource

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

public class ResourceLimitingJdbcDataSource
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements DataSourceComponent, org.apache.excalibur.instrument.Instrumentable, org.apache.avalon.framework.activity.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  org.apache.avalon.excalibur.pool.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(org.apache.avalon.framework.configuration.Configuration configuration)
          Pass the Configuration to the Configurable class.
 void dispose()
          The dispose operation is called at the end of a components lifecycle.
 org.apache.excalibur.instrument.Instrumentable[] getChildInstrumentables()
          Any Object which implements Instrumentable can also make use of other Instrumentable child objects.
 java.sql.Connection getConnection()
          Gets the Connection to the database
 java.lang.String getInstrumentableName()
          Gets the name of the Instrumentable.
 org.apache.excalibur.instrument.Instrument[] getInstruments()
          Obtain a reference to all the Instruments that the Instrumentable object wishes to expose.
 void setInstrumentableName(java.lang.String name)
          Sets the name for the Instrumentable.
 
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 org.apache.avalon.excalibur.pool.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(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.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 org.apache.avalon.framework.configuration.Configurable
Parameters:
configuration - the class configurations.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

setInstrumentableName

public void setInstrumentableName(java.lang.String name)
Sets the name for the Instrumentable. The Instrumentable Name is used to uniquely identify the Instrumentable during the configuration of the InstrumentManager and to gain access to an InstrumentableDescriptor through the InstrumentManager. The value should be a string which does not contain spaces or periods.

This value may be set by a parent Instrumentable, or by the InstrumentManager using the value of the 'instrumentable' attribute in the configuration of the component.

Specified by:
setInstrumentableName in interface org.apache.excalibur.instrument.Instrumentable
Parameters:
name - The name used to identify a Instrumentable.

getInstrumentableName

public java.lang.String getInstrumentableName()
Gets the name of the Instrumentable.

Specified by:
getInstrumentableName in interface org.apache.excalibur.instrument.Instrumentable
Returns:
The name used to identify a Instrumentable.

getInstruments

public org.apache.excalibur.instrument.Instrument[] getInstruments()
Obtain a reference to all the Instruments that the Instrumentable object wishes to expose. All sampling is done directly through the Instruments as opposed to the Instrumentable interface.

Specified by:
getInstruments in interface org.apache.excalibur.instrument.Instrumentable
Returns:
An array of the Instruments available for profiling. Should never be null. If there are no Instruments, then EMPTY_INSTRUMENT_ARRAY can be returned. This should never be the case though unless there are child Instrumentables with Instruments.

getChildInstrumentables

public org.apache.excalibur.instrument.Instrumentable[] getChildInstrumentables()
Any Object which implements Instrumentable can also make use of other Instrumentable child objects. This method is used to tell the InstrumentManager about them.

Specified by:
getChildInstrumentables in interface org.apache.excalibur.instrument.Instrumentable
Returns:
An array of child Instrumentables. This method should never return null. If there are no child Instrumentables, then EMPTY_INSTRUMENTABLE_ARRAY can be returned.

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 org.apache.avalon.framework.activity.Disposable


Copyright © 2003-2004 The Apache Software Foundation. All Rights Reserved.