mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
jconsole
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@229 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -4,27 +4,30 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
|
||||
public class DataSourceInfo {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
private String url;
|
||||
private List<String> filters = new ArrayList<String>();
|
||||
private Date createdTime;
|
||||
private long id;
|
||||
private String name;
|
||||
private String url;
|
||||
private List<String> filters = new ArrayList<String>();
|
||||
private Date createdTime;
|
||||
|
||||
private String rawDriverClassName;
|
||||
private String rawUrl;
|
||||
private int rawDriverMajorVersion;
|
||||
private int rawDriverMinorVersion;
|
||||
private String properties;
|
||||
private String rawDriverClassName;
|
||||
private String rawUrl;
|
||||
private int rawDriverMajorVersion;
|
||||
private int rawDriverMinorVersion;
|
||||
private String properties;
|
||||
private MBeanServerConnection connection;
|
||||
|
||||
public DataSourceInfo(){
|
||||
|
||||
}
|
||||
|
||||
public DataSourceInfo(CompositeData data){
|
||||
public DataSourceInfo(MBeanServerConnection conn, CompositeData data){
|
||||
this.connection = conn;
|
||||
this.id = ((Number) data.get("ID")).longValue();
|
||||
this.name = (String) data.get("Name");
|
||||
this.url = (String) data.get("URL");
|
||||
@@ -40,6 +43,14 @@ public class DataSourceInfo {
|
||||
this.properties = (String) data.get("Properties");
|
||||
}
|
||||
|
||||
public MBeanServerConnection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void setConnection(MBeanServerConnection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,50 @@
|
||||
package com.alibaba.druid.jconsole;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Panel;
|
||||
|
||||
import com.sun.tools.jconsole.JConsoleContext;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
|
||||
public class DataSourcePanel extends Panel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private JConsoleContext context;
|
||||
private DataSourceInfo dataSourceInfo;
|
||||
|
||||
public DataSourcePanel(JConsoleContext context){
|
||||
this.context = context;
|
||||
|
||||
this.setBackground(Color.RED);
|
||||
private JTable table;
|
||||
|
||||
private String[] columns = new String[] { "Name", "Value" };
|
||||
|
||||
public DataSourcePanel(DataSourceInfo dataSourceInfo){
|
||||
this.dataSourceInfo = dataSourceInfo;
|
||||
|
||||
Object[][] rows = new Object[][] {
|
||||
{ "ID", dataSourceInfo.getId() },
|
||||
{ "Name", dataSourceInfo.getName() },
|
||||
{ "URL", dataSourceInfo.getUrl() },
|
||||
{ "Filters", dataSourceInfo.getFilters() },
|
||||
{ "CreatedTime", dataSourceInfo.getCreatedTime() },
|
||||
{ "RawDriverClassName", dataSourceInfo.getRawDriverClassName() },
|
||||
{ "RawUrl", dataSourceInfo.getRawUrl() },
|
||||
{ "RawDriverMajorVersion", dataSourceInfo.getRawDriverMajorVersion() },
|
||||
{ "RawDriverMinorVersion", dataSourceInfo.getRawDriverMinorVersion() },
|
||||
{ "Properties", dataSourceInfo.getProperties() },
|
||||
};
|
||||
table = new JTable(rows, columns);
|
||||
|
||||
JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
this.add(tableScrollPane, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
public JConsoleContext getJConsoleContext() {
|
||||
return context;
|
||||
public DataSourceInfo getDataSourceInfo() {
|
||||
return dataSourceInfo;
|
||||
}
|
||||
|
||||
public void setDataSourceInfo(DataSourceInfo dataSourceInfo) {
|
||||
this.dataSourceInfo = dataSourceInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.alibaba.druid.jconsole;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.sql.Connection;
|
||||
@@ -29,6 +28,7 @@ import javax.swing.JTree;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
@@ -56,6 +56,7 @@ public class DruidPanel extends JPanel {
|
||||
rootNode.add(dataSourcesNode);
|
||||
|
||||
tree = new JTree(rootNode);
|
||||
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
tree.setRootVisible(false);
|
||||
|
||||
tree.addTreeSelectionListener(new TreeSelectionListener() {
|
||||
@@ -76,12 +77,20 @@ public class DruidPanel extends JPanel {
|
||||
|
||||
add(mainSplit);
|
||||
|
||||
this.setBackground(Color.BLUE);
|
||||
|
||||
// init();
|
||||
}
|
||||
|
||||
private void treeSelect(TreeSelectionEvent e) {
|
||||
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
|
||||
Object userData = node.getUserObject();
|
||||
|
||||
if (userData instanceof DataSourceInfo) {
|
||||
DataSourceInfo dataSourceInfo = (DataSourceInfo) userData;
|
||||
mainSplit.setRightComponent(new DataSourcePanel(dataSourceInfo));
|
||||
} else {
|
||||
mainSplit.setRightComponent(sheet);
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
@@ -144,7 +153,7 @@ public class DruidPanel extends JPanel {
|
||||
for (Object item : tabularValue.values()) {
|
||||
CompositeData rowData = (CompositeData) item;
|
||||
|
||||
DataSourceInfo dataSourceInfo = new DataSourceInfo(rowData);
|
||||
DataSourceInfo dataSourceInfo = new DataSourceInfo(conn, rowData);
|
||||
|
||||
DefaultMutableTreeNode dataSourceNode = new DefaultMutableTreeNode(dataSourceInfo.getName(), true);
|
||||
dataSourceNode.setUserObject(dataSourceInfo);
|
||||
|
||||
Reference in New Issue
Block a user