This commit is contained in:
wenshao
2011-12-23 16:51:11 +08:00
parent 9d4d45512b
commit 9207dd46a7
4 changed files with 127 additions and 10 deletions
@@ -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");
}
}