org.apache.avalon.excalibur.datasource
Class ResourceLimitingJdbcDataSource
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
org.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:
- The
max
attribute is used to set the maximum
number of connections which will be opened. See the
blocking
attribute. (Defaults to "3")
- The
max-strict
attribute is used to determine whether
or not the maximum number of connections can be exceeded. If true,
then an exception will be thrown if more than max connections are
requested and blocking is false. (Defaults to "true")
WARNING: In most cases, this value
should always be set to true. Setting it to false means that under
heavy load, your application may open a very large number of
connections to the database. Some database servers behave very poorly
under large connection loads and can even crash.
- The
blocking
attributes is used to specify the
behavior of the DataSource pool when an attempt is made to allocate
more than max
concurrent connections. If true, the
request will block until a connection is released, otherwise, a
NoAvailableConnectionException will be thrown. Ignored if
max-strict
is false. (Defaults to "true")
- The
timeout
attribute is used to specify the
maximum amount of time in milliseconds that a request for a
connection will be allowed to block before a
NoAvailableConnectionException is thrown. A value of "0" specifies
that the block will never timeout. (Defaults to "0")
- The
trim-interval
attribute is used to specify how
long idle connections will be maintained in the pool before being
closed. For a complete explanation on how this works, see ResourceLimitingPool.trim()
(Defaults to "60000", 1 minute)
- The
auto-commit
attribute is used to determine the
default auto-commit mode for the Connection
s returned
by this DataSource
.
- The
connection-class
attribute is used to override
the Connection class returned by the DataSource from calls to
getConnection(). Set this to
"org.apache.avalon.excalibur.datasource.Jdbc3Connection" to gain
access to JDBC3 features. Jdbc3Connection does not exist if your
JVM does not support JDBC3. (Defaults to
"org.apache.avalon.excalibur.datasource.JdbcConnection")
- The
keep-alive
element is used to override the
query used to monitor the health of connections. If a connection
has not been used for 5 seconds then before returning the
connection from a call to getConnection(), the connection is first
used to ping the database to make sure that it is still alive.
Setting the disable
attribute to true will disable
this feature. Setting the age
allows the 5 second age to
be overridden. (Defaults to a query of "SELECT 1" and being enabled)
- The
driver
element is used to specify the driver
to use when connecting to the database. The specified class must
be in the classpath. (Required)
- The
dburl
element is the JDBC connection string
which will be used to connect to the database. (Required)
- The
user
and password
attributes are
used to specify the user and password for connections to the
database. (Required)
- Since:
- 4.1
- Version:
- CVS $Revision: 1.5 $ $Date: 2004/03/30 15:58:50 $
- Author:
- Avalon Development Team
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
m_pool
protected InstrumentedResourceLimitingPool m_pool
ResourceLimitingJdbcDataSource
public ResourceLimitingJdbcDataSource()
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.