public class DefaultRoundRobinDataSourceCluster extends AbstractDataSourceCluster implements RoundRobinDataSourceCluster
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>
| Modifier and Type | Field and Description |
|---|---|
private int |
m_nextIndex |
private java.lang.Object |
m_semaphore |
m_sizeROLE| Constructor and Description |
|---|
DefaultRoundRobinDataSourceCluster() |
| Modifier and Type | Method and Description |
|---|---|
java.sql.Connection |
getConnection()
Returns a Connection to one of the Cluster's member DataSources.
|
configure, dispose, getClusterSize, getConnectionForIndex, initialize, serviceenableLogging, getLogger, setupLogger, setupLogger, setupLoggerpublic java.sql.Connection getConnection()
throws java.sql.SQLException
getConnection in interface DataSourceComponentNoValidConnectionException - when there is no valid Connection wrapper
available in the classloader.NoValidConnectionException - when there are no more available
Connections in the pool.NoAvailableConnectionException - when there are no more available
Connections in the pool.java.sql.SQLException