1 19 20 package org.apache.avalon.excalibur.datasource.cluster; 21 22 import java.sql.Connection ; 23 import java.sql.SQLException ; 24 25 96 public class DefaultRoundRobinDataSourceCluster 97 extends AbstractDataSourceCluster 98 implements RoundRobinDataSourceCluster 99 { 100 private Object m_semaphore = new Object (); 101 private int m_nextIndex; 102 103 106 public DefaultRoundRobinDataSourceCluster() 107 { 108 } 109 110 113 122 public Connection getConnection() throws SQLException 123 { 124 int index; 125 synchronized( m_semaphore ) 126 { 127 index = m_nextIndex; 128 if( ( ++m_nextIndex ) >= m_size ) 129 { 130 m_nextIndex = 0; 131 } 132 } 133 134 return getConnectionForIndex( index ); 135 } 136 } 137 138 | Popular Tags |