mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
支持HA
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@453 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -5,6 +5,7 @@ import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@@ -14,8 +15,10 @@ public class HADataSource implements DataSource {
|
||||
|
||||
private final List<DruidDataSource> dataSources = new CopyOnWriteArrayList<DruidDataSource>();
|
||||
|
||||
private int loginTimeout = 0;
|
||||
private PrintWriter logWriter = new PrintWriter(System.out);
|
||||
private int loginTimeout = 0;
|
||||
private PrintWriter logWriter = new PrintWriter(System.out);
|
||||
|
||||
private AtomicInteger requestCount = new AtomicInteger();
|
||||
|
||||
public List<DruidDataSource> getDataSources() {
|
||||
return dataSources;
|
||||
@@ -70,7 +73,12 @@ public class HADataSource implements DataSource {
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return null;
|
||||
int requestNumber = requestCount.getAndIncrement();
|
||||
int size = dataSources.size();
|
||||
int index = requestNumber % size;
|
||||
|
||||
DruidDataSource dataSource = dataSources.get(index);
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user