mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
fixed bug & testcase
This commit is contained in:
@@ -54,8 +54,12 @@ import com.alibaba.druid.support.logging.LogFactory;
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
*/
|
||||
public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(StatFilter.class);
|
||||
|
||||
private static final String SYS_PROP_LOG_SLOW_SQL = "druid.stat.logSlowSql";
|
||||
private static final String SYS_PROP_SLOW_SQL_MILLIS = "druid.stat.slowSqlMillis";
|
||||
private static final String SYS_PROP_MERGE_SQL = "druid.stat.mergeSql";
|
||||
|
||||
public final static String ATTR_NAME_CONNECTION_STAT = "stat.conn";
|
||||
public final static String ATTR_NAME_STATEMENT_STAT = "stat.stmt";
|
||||
public final static String ATTR_UPDATE_COUNT = "stat.updteCount";
|
||||
@@ -153,7 +157,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
}
|
||||
|
||||
{
|
||||
String property = properties.getProperty("druid.stat.mergeSql");
|
||||
String property = properties.getProperty(SYS_PROP_MERGE_SQL);
|
||||
if ("true".equals(property)) {
|
||||
this.mergeSql = true;
|
||||
} else if ("false".equals(property)) {
|
||||
@@ -162,7 +166,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
}
|
||||
|
||||
{
|
||||
String property = properties.getProperty("druid.stat.slowSqlMillis");
|
||||
String property = properties.getProperty(SYS_PROP_SLOW_SQL_MILLIS);
|
||||
if (property != null && property.trim().length() > 0) {
|
||||
property = property.trim();
|
||||
try {
|
||||
@@ -174,7 +178,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
}
|
||||
|
||||
{
|
||||
String property = properties.getProperty("druid.stat.logSlowSql");
|
||||
String property = properties.getProperty(SYS_PROP_LOG_SLOW_SQL);
|
||||
if ("true".equals(property)) {
|
||||
this.logSlowSql = true;
|
||||
} else if ("false".equals(property)) {
|
||||
|
||||
@@ -106,6 +106,11 @@ public class DruidDataSourceFactory implements ObjectFactory {
|
||||
|
||||
return createDataSource(properties);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static DataSource createDataSource(Properties properties) throws Exception {
|
||||
return createDataSource((Map) properties);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static DataSource createDataSource(Map properties) throws Exception {
|
||||
|
||||
@@ -43,18 +43,19 @@ import com.alibaba.druid.util.JMXUtils;
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBean {
|
||||
|
||||
public final static String SYS_PROP_INSTANCES = "druid.dataSources";
|
||||
public final static String SYS_PROP_INSTANCES = "druid.dataSources";
|
||||
public final static String SYS_PROP_REGISTER_SYS_PROPERTY = "druid.registerToSysProperty";
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(DruidDataSourceStatManager.class);
|
||||
private final static Log LOG = LogFactory.getLog(DruidDataSourceStatManager.class);
|
||||
|
||||
private final static DruidDataSourceStatManager instance = new DruidDataSourceStatManager();
|
||||
private final static DruidDataSourceStatManager instance = new DruidDataSourceStatManager();
|
||||
|
||||
private final AtomicLong resetCount = new AtomicLong();
|
||||
private final AtomicLong resetCount = new AtomicLong();
|
||||
|
||||
// global instances
|
||||
private static IdentityHashMap dataSources;
|
||||
private static volatile IdentityHashMap dataSources;
|
||||
|
||||
private final static String MBEAN_NAME = "com.alibaba.druid:type=DruidDataSourceStat";
|
||||
private final static String MBEAN_NAME = "com.alibaba.druid:type=DruidDataSourceStat";
|
||||
|
||||
public static DruidDataSourceStatManager getInstance() {
|
||||
return instance;
|
||||
@@ -84,14 +85,28 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static IdentityHashMap<Object, ObjectName> getInstances() {
|
||||
public synchronized static IdentityHashMap<Object, ObjectName> getInstances() {
|
||||
if (dataSources == null) {
|
||||
dataSources = getInstances0();
|
||||
if (isRegisterToSystemProperty()) {
|
||||
dataSources = getInstances0();
|
||||
} else {
|
||||
dataSources = new IdentityHashMap<Object, ObjectName>();
|
||||
}
|
||||
}
|
||||
|
||||
return dataSources;
|
||||
}
|
||||
|
||||
public static boolean isRegisterToSystemProperty() {
|
||||
String value = System.getProperty(SYS_PROP_REGISTER_SYS_PROPERTY);
|
||||
|
||||
if ("false".equals(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static IdentityHashMap<Object, ObjectName> getInstances0() {
|
||||
Properties properties = System.getProperties();
|
||||
|
||||
Reference in New Issue
Block a user