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@459 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -54,10 +54,7 @@ public class HADataSource extends MultiDataSource implements DataSource {
|
||||
assert dataSource != null;
|
||||
|
||||
if (!dataSource.isEnable()) {
|
||||
boolean removed = dataSources.remove(dataSource);
|
||||
if (removed) {
|
||||
notAvailableDatasources.add(dataSource);
|
||||
}
|
||||
handleNotAwailableDatasource(dataSource);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -79,6 +76,13 @@ public class HADataSource extends MultiDataSource implements DataSource {
|
||||
return conn;
|
||||
}
|
||||
}
|
||||
|
||||
void handleNotAwailableDatasource(DruidDataSource dataSource) {
|
||||
boolean removed = dataSources.remove(dataSource);
|
||||
if (removed) {
|
||||
notAvailableDatasources.add(dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
public long getIndexErrorCount() {
|
||||
return indexErrorCount.get();
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.alibaba.druid.pool.ha;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.pool.DataSourceAdapter;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
@@ -15,8 +17,14 @@ public abstract class MultiDataSource extends DataSourceAdapter {
|
||||
dataSources = new ArrayList<DruidDataSource>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
public List<DruidDataSource> getDataSources() {
|
||||
return Collections.unmodifiableList(dataSources);
|
||||
}
|
||||
|
||||
public void setDataSources(List<DruidDataSource> dataSources) {
|
||||
this.dataSources = new ArrayList<DruidDataSource>(dataSources);;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract Connection getConnection() throws SQLException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user