|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable
org.apache.avalon.excalibur.datasource.ResourceLimitingJdbcDataSource
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" connection-class="my.overrided.ConnectionClass"> <keep-alive disable="false" age="5000">select 1</keep-alive> </pool-controller> <auto-commit>true</auto-commit> <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:
max
attribute is used to set the maximum
number of connections which will be opened. See the
blocking
attribute. (Defaults to "3")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")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")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")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)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")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)auto-commit
element is used to determine the
default auto-commit mode for the Connection
s returned
by this DataSource
.
driver
element is used to specify the driver
to use when connecting to the database. The specified class must
be in the classpath. (Required)dburl
element is the JDBC connection string
which will be used to connect to the database. (Required)user
and password
attributes are
used to specify the user and password for connections to the
database. (Required)
Field Summary | |
protected org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool |
m_pool
|
Fields inherited from interface org.apache.avalon.excalibur.datasource.TraceableDataSourceComponent |
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. |
java.sql.Connection |
getConnection()
Gets the Connection to the database |
org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool.State |
getState()
Returns a snapshot of the current state of the pool. |
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 |
protected org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool m_pool
Constructor Detail |
public ResourceLimitingJdbcDataSource()
Method Detail |
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface DataSourceComponent
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
public org.apache.avalon.excalibur.pool.TraceableResourceLimitingPool.State getState()
getState
in interface TraceableDataSourceComponent
public void configure(org.apache.avalon.framework.configuration.Configuration configuration) throws org.apache.avalon.framework.configuration.ConfigurationException
Configuration
to the Configurable
class. This method must always be called after the constructor
and before any other method.
configure
in interface org.apache.avalon.framework.configuration.Configurable
configuration
- the class configurations.
org.apache.avalon.framework.configuration.ConfigurationException
public void dispose()
dispose
in interface org.apache.avalon.framework.activity.Disposable
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |