diff --git a/src/main/java/com/alibaba/druid/jconsole/ConnectionsPanel.java b/src/main/java/com/alibaba/druid/jconsole/ConnectionsPanel.java new file mode 100644 index 0000000000..60ad433d6f --- /dev/null +++ b/src/main/java/com/alibaba/druid/jconsole/ConnectionsPanel.java @@ -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; + } + +} diff --git a/src/main/java/com/alibaba/druid/jconsole/DruidPanel.java b/src/main/java/com/alibaba/druid/jconsole/DruidPanel.java index 9421f148d8..5b73f731cc 100644 --- a/src/main/java/com/alibaba/druid/jconsole/DruidPanel.java +++ b/src/main/java/com/alibaba/druid/jconsole/DruidPanel.java @@ -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 stats = new ArrayList(); - List dataSourceInstances = new ArrayList(); Set 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); } diff --git a/src/main/java/com/alibaba/druid/jconsole/NodeInfo.java b/src/main/java/com/alibaba/druid/jconsole/NodeInfo.java index 8969ffc3f8..14ea24de9f 100644 --- a/src/main/java/com/alibaba/druid/jconsole/NodeInfo.java +++ b/src/main/java/com/alibaba/druid/jconsole/NodeInfo.java @@ -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; }