mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
ha
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
package com.alibaba.druid.pool.ha;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
public class DataSourceHolder {
|
||||
public class DataSourceHolder implements Closeable {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
private boolean enable;
|
||||
private final DruidDataSource dataSource;
|
||||
private boolean enable = true;
|
||||
private final AtomicLong connectCount = new AtomicLong();
|
||||
private final AtomicLong connectErrorCount = new AtomicLong();
|
||||
|
||||
public DataSourceHolder(DruidDataSource dataSource){
|
||||
if (dataSource == null) {
|
||||
throw new IllegalArgumentException("dataSource is null");
|
||||
}
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@@ -33,10 +37,6 @@ public class DataSourceHolder {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
public void setDataSource(DruidDataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
public long getConnectCount() {
|
||||
return connectCount.get();
|
||||
}
|
||||
@@ -46,10 +46,6 @@ public class DataSourceHolder {
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
if (dataSource == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return dataSource.getUrl();
|
||||
}
|
||||
|
||||
@@ -65,4 +61,9 @@ public class DataSourceHolder {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import javax.management.ObjectName;
|
||||
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.pool.DataSourceAdapter;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.ha.valid.DataSourceFailureDetecter;
|
||||
import com.alibaba.druid.pool.ha.valid.DefaultDataSourceFailureDetecter;
|
||||
import com.alibaba.druid.proxy.jdbc.DataSourceProxy;
|
||||
@@ -120,7 +119,7 @@ public abstract class MultiDataSource extends DataSourceAdapter implements Multi
|
||||
|
||||
Object[] items = this.getDataSources().values().toArray();
|
||||
for (Object item : items) {
|
||||
JdbcUtils.close((DruidDataSource) item);
|
||||
JdbcUtils.close((DataSourceHolder) item);
|
||||
}
|
||||
|
||||
MultiDataSourceStatManager.remove(this);
|
||||
|
||||
Reference in New Issue
Block a user