git-svn-id: http://code.alibabatech.com/svn/druid/trunk@233 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-06-02 01:42:46 +00:00
parent 18f9c87146
commit 65f2330924
3 changed files with 43 additions and 30 deletions
@@ -0,0 +1,28 @@
package com.alibaba.druid.jconsole;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.swing.JPanel;
public class ConnectionsPanel extends JPanel {
private static final long serialVersionUID = 1L;
private MBeanServerConnection connection;
private ObjectName objectName;
public ConnectionsPanel(MBeanServerConnection connection, ObjectName objectName){
super();
this.connection = connection;
this.objectName = objectName;
}
public MBeanServerConnection getConnection() {
return connection;
}
public ObjectName getObjectName() {
return objectName;
}
}
@@ -52,7 +52,7 @@ public class DruidPanel extends JPanel {
mainSplit.setBorder(BorderFactory.createEmptyBorder());
rootNode = new DefaultMutableTreeNode("root", true);
dataSourcesNode = new DefaultMutableTreeNode(new NodeInfo(null, NodeType.DataSources, null, "DataSources"), true);
dataSourcesNode = new DefaultMutableTreeNode(new NodeInfo(null, null, NodeType.DataSources, null, "DataSources"), true);
rootNode.add(dataSourcesNode);
tree = new JTree(rootNode);
@@ -134,7 +134,6 @@ public class DruidPanel extends JPanel {
// dataSourcesNode.removeAllChildren();
List<ObjectInstance> stats = new ArrayList<ObjectInstance>();
List<ObjectInstance> dataSourceInstances = new ArrayList<ObjectInstance>();
Set<ObjectInstance> instances = conn.queryMBeans(null, null);
for (ObjectInstance instance : instances) {
@@ -144,10 +143,6 @@ public class DruidPanel extends JPanel {
continue;
}
if ("com.alibaba.druid.pool.DruidDataSource".equals(info.getClassName())) {
dataSourceInstances.add(instance);
continue;
}
}
if (stats.size() == 0) {
@@ -161,39 +156,23 @@ public class DruidPanel extends JPanel {
DataSourceInfo dataSourceInfo = new DataSourceInfo(conn, rowData);
DefaultMutableTreeNode dataSourceNode = new DefaultMutableTreeNode(new NodeInfo(conn, NodeType.DataSource, dataSourceInfo,
dataSourceInfo.getName()), true);
DefaultMutableTreeNode connections = new DefaultMutableTreeNode(new NodeInfo(conn, NodeType.Connections, "Connections", "Connections"), true);
NodeInfo dataSourceNodeInfo = new NodeInfo(conn, statInstance, NodeType.DataSource, dataSourceInfo, dataSourceInfo.getName());
DefaultMutableTreeNode dataSourceNode = new DefaultMutableTreeNode(dataSourceNodeInfo, true);
NodeInfo connectionsNodeInfo = new NodeInfo(conn, statInstance, NodeType.Connections, "Connections", "Connections");
DefaultMutableTreeNode connections = new DefaultMutableTreeNode(connectionsNodeInfo, true);
{
}
dataSourceNode.add(connections);
DefaultMutableTreeNode sqlListNode = new DefaultMutableTreeNode(new NodeInfo(conn, NodeType.SQL, dataSourceInfo.getName(), "SQL"), true);
NodeInfo sqlNodeInfo = new NodeInfo(conn, statInstance, NodeType.SQL, dataSourceInfo.getName(), "SQL");
DefaultMutableTreeNode sqlListNode = new DefaultMutableTreeNode(sqlNodeInfo, true);
dataSourceNode.add(sqlListNode);
dataSourcesNode.add(dataSourceNode);
}
}
for (ObjectInstance dataSourceInstance : dataSourceInstances) {
String name = (String) conn.getAttribute(dataSourceInstance.getObjectName(), "Name");
DefaultMutableTreeNode dataSource = new DefaultMutableTreeNode(name, true);
DefaultMutableTreeNode connections = new DefaultMutableTreeNode(new NodeInfo(conn, NodeType.Connections, "Connections", "Connections"), true);
{
}
dataSource.add(connections);
DefaultMutableTreeNode sqlListNode = new DefaultMutableTreeNode(new NodeInfo(conn, NodeType.SQL, name, "SQL"), true);
{
}
dataSource.add(sqlListNode);
dataSourcesNode.add(dataSource);
}
// TreePath path = new TreePath(dataSourcesNode.children());
// tree.scrollPathToVisible(path);
}
@@ -1,21 +1,27 @@
package com.alibaba.druid.jconsole;
import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
public class NodeInfo {
private MBeanServerConnection connection;
private ObjectInstance objectInstance;
private NodeType type;
private Object data;
private String name;
public NodeInfo(MBeanServerConnection connection, NodeType type, Object data, String name){
public NodeInfo(MBeanServerConnection connection, ObjectInstance objectInstance, NodeType type, Object data, String name){
this.connection = connection;
this.type = type;
this.data = data;
this.name = name;
}
public ObjectInstance getObjectInstance() {
return objectInstance;
}
public MBeanServerConnection getConnection() {
return connection;
}