refactor & add testcase

This commit is contained in:
wenshao
2012-07-20 07:44:06 +08:00
parent 88ebf7d3db
commit 342b6af58b
6 changed files with 82 additions and 9 deletions
@@ -55,7 +55,7 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
return instance;
}
public synchronized static void add(DruidDataSource dataSource) {
public synchronized static ObjectName add(DruidDataSource dataSource, String name) {
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
if (dataSources.size() == 0) {
try {
@@ -70,9 +70,9 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
}
ObjectName objectName = null;
if (dataSource.getNameInternal() != null) {
if (name != null) {
try {
objectName = new ObjectName("com.alibaba.druid:type=DruidDataSource,id=" + dataSource.getNameInternal());
objectName = new ObjectName("com.alibaba.druid:type=DruidDataSource,id=" + name);
mbeanServer.registerMBean(dataSource, objectName);
} catch (JMException ex) {
LOG.error("register mbean error", ex);
@@ -92,7 +92,7 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
}
dataSources.put(dataSource, objectName);
dataSource.setObjectName(objectName);
return objectName;
}
public synchronized static void remove(DruidDataSource dataSource) {