org.apache.avalon.excalibur.datasource.cluster
Class DefaultRoundRobinDataSourceCluster
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.avalon.excalibur.datasource.cluster.AbstractDataSourceCluster
org.apache.avalon.excalibur.datasource.cluster.DefaultRoundRobinDataSourceCluster
- All Implemented Interfaces:
- Component, Configurable, DataSourceComponent, Disposable, Initializable, LogEnabled, RoundRobinDataSourceCluster, Serviceable, ThreadSafe
- public class DefaultRoundRobinDataSourceCluster
- extends AbstractDataSourceCluster
- implements RoundRobinDataSourceCluster
The DefaultRoundRobinDataSourceCluster allows the user to specify a cluster of DataSources
which all act as one. The Cluster works by cycling through its member DataSources returning
a connection from a different one with each call to getConnection().
This form of Clustering has the benefit that it can be used by components without requiring
any changes. But care must be taken as to the kind of data written or read from the database.
Wich this clustering method, there is no control over which DataSource will provide a
connection for any given call.
Round Robin Clusters are useful in cases where lots of read-only data needs to be accessed and
multiple copies of the data can be stored on different database servers to balance load.
The Configuration for a 2 database cluster is like this:
<datasources>
<roundrobin-cluster name="mydb-cluster" size="2">
<dbpool index="0">mydb-0</dbpool>
<dbpool index="1">mydb-1</dbpool>
</roundrobin-cluster>
</datasources>
<cluster-datasources>
<jdbc name="mydb-0">
<pool-controller min="1" max="10"/>
<auto-commit>true</auto-commit>
<driver>com.database.jdbc.JdbcDriver</driver>
<dburl>jdbc:driver://host0/mydb</dburl>
<user>username</user>
<password>password</password>
</jdbc>
<jdbc name="mydb-1">
<pool-controller min="1" max="10"/>
<auto-commit>true</auto-commit>
<driver>com.database.jdbc.JdbcDriver</driver>
<dburl>jdbc:driver://host1/mydb</dburl>
<user>username</user>
<password>password</password>
</jdbc>
</cluster-datasources>
With the following roles declaration:
<role name="org.apache.avalon.excalibur.datasource.DataSourceComponentSelector"
shorthand="datasources"
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
<hint shorthand="jdbc" class="org.apache.avalon.excalibur.datasource.JdbcDataSource"/>
<hint shorthand="j2ee" class="org.apache.avalon.excalibur.datasource.J2eeDataSource"/>
<hint shorthand="roundrobin-cluster"
class="org.apache.avalon.excalibur.datasource.cluster.DefaultRoundRobinDataSourceCluster"/>
</role>
<role name="org.apache.avalon.excalibur.datasource.DataSourceComponentClusterSelector"
shorthand="cluster-datasources"
default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
<hint shorthand="jdbc" class="org.apache.avalon.excalibur.datasource.JdbcDataSource"/>
<hint shorthand="j2ee" class="org.apache.avalon.excalibur.datasource.J2eeDataSource"/>
</role>
- Since:
- 4.1
- Version:
- CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:20 $
- Author:
- Avalon Development Team
Method Summary |
java.sql.Connection |
getConnection()
Returns a Connection to one of the Cluster's member DataSources. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DefaultRoundRobinDataSourceCluster
public DefaultRoundRobinDataSourceCluster()
getConnection
public java.sql.Connection getConnection()
throws java.sql.SQLException
- Returns a Connection to one of the Cluster's member DataSources.
- 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.
NoValidConnectionException
- when there are no more available
Connections in the pool.
java.sql.SQLException
Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.