支持setEnable

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@352 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-07-06 14:16:58 +00:00
parent e94a118f8c
commit 2aa90d656a
4 changed files with 75 additions and 23 deletions
@@ -8,14 +8,16 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.sql.DataSource;
import com.alibaba.druid.pool.DruidDataSource;
public class HADataSource implements DataSource {
private final List<DataSource> dataSources = new CopyOnWriteArrayList<DataSource>();
private final List<DruidDataSource> dataSources = new CopyOnWriteArrayList<DruidDataSource>();
private int loginTimeout = 0;
private PrintWriter logWriter = new PrintWriter(System.out);
public List<DataSource> getDataSources() {
public List<DruidDataSource> getDataSources() {
return dataSources;
}
@@ -0,0 +1,21 @@
package com.alibaba.druid.pool;
import java.sql.SQLException;
public class DataSourceDisableException extends SQLException {
private static final long serialVersionUID = 1L;
public DataSourceDisableException(){
super();
}
public DataSourceDisableException(String reason){
super(reason);
}
public DataSourceDisableException(Throwable cause){
super(cause);
}
}
@@ -56,8 +56,9 @@ import com.alibaba.druid.util.JdbcUtils;
/**
* @author wenshao<szujobs@hotmail.com>
*/
public class DruidDataSource extends DruidAbstractDataSource implements DruidDataSourceMBean, Referenceable {
private final static Log LOG = LogFactory.getLog(DruidDataSource.class);
public class DruidDataSource extends DruidAbstractDataSource implements DruidDataSourceMBean, ManagedDataSource, Referenceable {
private final static Log LOG = LogFactory.getLog(DruidDataSource.class);
private static final Object PRESENT = new Object();
private static final IdentityHashMap<DruidDataSource, Object> instances = new IdentityHashMap<DruidDataSource, Object>();
@@ -97,6 +98,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
private long id;
private Date createdTime;
private boolean enable;
public DruidDataSource(){
}
@@ -104,6 +107,14 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
return createdTime;
}
public boolean isEnable() {
return enable;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
private void init() throws SQLException {
if (inited) {
return;
@@ -250,11 +261,19 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
private PoolableConnection getConnectionInternal() throws SQLException {
PoolableConnection poolalbeConnection;
if (!enable) {
throw new DataSourceDisableException();
}
try {
lock.lockInterruptibly();
connectCount++;
if (!enable) {
throw new DataSourceDisableException();
}
ConnectionHolder holder;
for (;;) {
if (maxWait > 0) {
@@ -735,7 +754,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
public long getID() {
return this.id;
}
private int getRawDriverMajorVersion() {
int version = -1;
if (this.driver != null) {
@@ -743,7 +762,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
return version;
}
private int getRawDriverMinorVersion() {
int version = -1;
if (this.driver != null) {
@@ -751,19 +770,19 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
return version;
}
private String getProperties() {
if (this.connectionProperties == null) {
return null;
}
Properties properties = new Properties(this.connectionProperties);
if (properties.contains("password")) {
properties.put("password", "******");
}
return properties.toString();
}
public String[] getFilterClasses() {
List<Filter> filterConfigList = getFilters();
@@ -889,43 +908,43 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
map.put("ConnectionErrorLastTime", stat.getConnectionStat().getErrorLastTime());
map.put("ConnectionAliveMillisMax", stat.getConnectionConnectAliveMillisMax());
map.put("ConnectionAliveMillisMin", stat.getConnectionConnectAliveMillisMin());
map.put("ConnectionCount_Alive_0_1_Seconds", stat.getConnectionCount_Alive_0_1_Seconds());
map.put("ConnectionCount_Alive_1_5_Seconds", stat.getConnectionCount_Alive_1_5_Seconds());
map.put("ConnectionCount_Alive_5_10_Seconds", stat.getConnectionCount_Alive_5_10_Seconds());
map.put("ConnectionCount_Alive_10_30_Seconds", stat.getConnectionCount_Alive_10_30_Seconds());
map.put("ConnectionCount_Alive_30_60_Seconds", stat.getConnectionCount_Alive_30_60_Seconds());
map.put("ConnectionCount_Alive_1_5_Minutes", stat.getConnectionCount_Alive_1_5_Minutes());
map.put("ConnectionCount_Alive_5_10_Minutes", stat.getConnectionCount_Alive_5_10_Minutes());
map.put("ConnectionCount_Alive_10_30_Minutes", stat.getConnectionCount_Alive_10_30_Minutes());
map.put("ConnectionCount_Alive_30_60_Minutes", stat.getConnectionCount_Alive_30_60_Minutes());
map.put("ConnectionCount_Alive_1_6_Hours", stat.getConnectionCount_Alive_1_6_Hours());
map.put("ConnectionCount_Alive_6_24_Hours", stat.getConnectionCount_Alive_6_24_Hours());
map.put("ConnectionCount_Alive_1_7_Day", stat.getConnectionCount_Alive_1_7_day());
map.put("ConnectionCount_Alive_7_30_Day", stat.getConnectionCount_Alive_7_30_Day());
map.put("ConnectionCount_Alive_30_90_Day", stat.getConnectionCount_Alive_30_90_Day());
map.put("ConnectionCount_Alive_90_more_Day", stat.getConnectionCount_Alive_90_more_Day());
map.put("StatementExecuteCount_0_1_Millis", stat.getStatementStat().getCount_0_1_Millis());
map.put("StatementExecuteCount_1_2_Millis", stat.getStatementStat().getCount_1_2_Millis());
map.put("StatementExecuteCount_2_5_Millis", stat.getStatementStat().getCount_2_5_Millis());
map.put("StatementExecuteCount_5_10_Millis", stat.getStatementStat().getCount_5_10_Millis());
map.put("StatementExecuteCount_10_20_Millis", stat.getStatementStat().getCount_10_20_Millis());
map.put("StatementExecuteCount_20_50_Millis", stat.getStatementStat().getCount_20_50_Millis());
map.put("StatementExecuteCount_50_100_Millis", stat.getStatementStat().getCount_50_100_Millis());
map.put("StatementExecuteCount_100_200_Millis", stat.getStatementStat().getCount_100_200_Millis());
map.put("StatementExecuteCount_200_500_Millis", stat.getStatementStat().getCount_200_500_Millis());
map.put("StatementExecuteCount_500_1000_Millis", stat.getStatementStat().getCount_500_1000_Millis());
map.put("StatementExecuteCount_1_2_Seconds", stat.getStatementStat().getCount_1_2_Seconds());
map.put("StatementExecuteCount_2_5_Seconds", stat.getStatementStat().getCount_2_5_Seconds());
map.put("StatementExecuteCount_5_10_Seconds", stat.getStatementStat().getCount_5_10_Seconds());
map.put("StatementExecuteCount_10_30_Seconds", stat.getStatementStat().getCount_10_30_Seconds());
map.put("StatementExecuteCount_30_60_Seconds", stat.getStatementStat().getCount_30_60_Seconds());
map.put("StatementExecuteCount_1_2_Minutes", stat.getStatementStat().getCount_1_2_minutes());
map.put("StatementExecuteCount_2_5_Minutes", stat.getStatementStat().getCount_2_5_minutes());
map.put("StatementExecuteCount_5_10_Minutes", stat.getStatementStat().getCount_5_10_minutes());
@@ -984,43 +1003,43 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
map.put("ConnectionErrorLastTime", null);
map.put("ConnectionAliveMillisMax", null);
map.put("ConnectionAliveMillisMin", null);
map.put("ConnectionCount_Alive_0_1_Seconds", null);
map.put("ConnectionCount_Alive_1_5_Seconds", null);
map.put("ConnectionCount_Alive_5_10_Seconds", null);
map.put("ConnectionCount_Alive_10_30_Seconds", null);
map.put("ConnectionCount_Alive_30_60_Seconds", null);
map.put("ConnectionCount_Alive_1_5_Minutes", null);
map.put("ConnectionCount_Alive_5_10_Minutes", null);
map.put("ConnectionCount_Alive_10_30_Minutes", null);
map.put("ConnectionCount_Alive_30_60_Minutes", null);
map.put("ConnectionCount_Alive_1_6_Hours", null);
map.put("ConnectionCount_Alive_6_24_Hours", null);
map.put("ConnectionCount_Alive_1_7_Day", null);
map.put("ConnectionCount_Alive_7_30_Day", null);
map.put("ConnectionCount_Alive_30_90_Day", null);
map.put("ConnectionCount_Alive_90_more_Day", null);
map.put("StatementExecuteCount_0_1_Millis", null);
map.put("StatementExecuteCount_1_2_Millis", null);
map.put("StatementExecuteCount_2_5_Millis", null);
map.put("StatementExecuteCount_5_10_Millis", null);
map.put("StatementExecuteCount_10_20_Millis", null);
map.put("StatementExecuteCount_20_50_Millis", null);
map.put("StatementExecuteCount_50_100_Millis", null);
map.put("StatementExecuteCount_100_200_Millis", null);
map.put("StatementExecuteCount_200_500_Millis", null);
map.put("StatementExecuteCount_500_1000_Millis", null);
map.put("StatementExecuteCount_1_2_Seconds", null);
map.put("StatementExecuteCount_2_5_Seconds", null);
map.put("StatementExecuteCount_5_10_Seconds", null);
map.put("StatementExecuteCount_10_30_Seconds", null);
map.put("StatementExecuteCount_30_60_Seconds", null);
map.put("StatementExecuteCount_1_2_Minutes", null);
map.put("StatementExecuteCount_2_5_Minutes", null);
map.put("StatementExecuteCount_5_10_Minutes", null);
@@ -0,0 +1,10 @@
package com.alibaba.druid.pool;
import javax.sql.DataSource;
public interface ManagedDataSource extends DataSource {
boolean isEnable();
void setEnable(boolean value);
}