mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
ha
This commit is contained in:
@@ -22,6 +22,16 @@ public class DataSourceHolder implements Closeable {
|
||||
|
||||
private transient int weightRegionEnd;
|
||||
|
||||
private boolean writable = true;
|
||||
|
||||
public boolean isWritable() {
|
||||
return writable;
|
||||
}
|
||||
|
||||
public void setWritable(boolean writable) {
|
||||
this.writable = writable;
|
||||
}
|
||||
|
||||
public int getWeightRegionBegin() {
|
||||
return weightRegionBegin;
|
||||
}
|
||||
@@ -93,7 +103,7 @@ public class DataSourceHolder implements Closeable {
|
||||
connectCount.incrementAndGet();
|
||||
try {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
|
||||
return new MultiConnectionHolder(this, conn);
|
||||
} catch (SQLException ex) {
|
||||
connectErrorCount.incrementAndGet();
|
||||
|
||||
@@ -24,6 +24,14 @@ public class HADataSource extends MultiDataSource implements HADataSourceMBean,
|
||||
master.resetState();
|
||||
slave.resetState();
|
||||
}
|
||||
|
||||
public boolean isMasterWritable() {
|
||||
return master != null && master.isWritable();
|
||||
}
|
||||
|
||||
public boolean isSlaveWritable() {
|
||||
return slave != null && slave.isWritable();
|
||||
}
|
||||
|
||||
public long getMasterConnectCount() {
|
||||
return master.getConnectCount();
|
||||
@@ -45,8 +53,10 @@ public class HADataSource extends MultiDataSource implements HADataSourceMBean,
|
||||
this.restartDataSource("slave");
|
||||
}
|
||||
|
||||
public void setMaster(DruidDataSource master) {
|
||||
this.setMaster(new DataSourceHolder(master));
|
||||
public DataSourceHolder setMaster(DruidDataSource master) {
|
||||
DataSourceHolder holder = new DataSourceHolder(master);
|
||||
this.setMaster(holder);
|
||||
return holder;
|
||||
}
|
||||
|
||||
public void setMaster(DataSourceHolder master) {
|
||||
@@ -58,8 +68,10 @@ public class HADataSource extends MultiDataSource implements HADataSourceMBean,
|
||||
return slave;
|
||||
}
|
||||
|
||||
public void setSlave(DruidDataSource slave) {
|
||||
this.setSlave(new DataSourceHolder(slave));
|
||||
public DataSourceHolder setSlave(DruidDataSource slave) {
|
||||
DataSourceHolder holder = new DataSourceHolder(slave);
|
||||
this.setSlave(holder);
|
||||
return holder;
|
||||
}
|
||||
|
||||
public void setSlave(DataSourceHolder slave) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.alibaba.druid.pool.ha.config;
|
||||
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
|
||||
public class HAConfigLoader extends URLConnectionConfigLoader {
|
||||
|
||||
public HAConfigLoader(URL configServerURL){
|
||||
super(configServerURL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleResponseMessage() throws SQLException {
|
||||
JSONObject json = JSON.parseObject(this.getResponseMessage());
|
||||
json.get("serverList");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user