mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
添加jconsole plugin
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@212 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -1,9 +1,76 @@
|
||||
package com.alibaba.druid.jconsole;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.management.MBeanInfo;
|
||||
import javax.management.MBeanServerConnection;
|
||||
import javax.management.ObjectInstance;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JTree;
|
||||
|
||||
import com.sun.tools.jconsole.JConsoleContext;
|
||||
|
||||
public class DruidPanel extends JPanel {
|
||||
|
||||
protected JSplitPane mainSplit;
|
||||
protected JTree tree;
|
||||
protected JPanel sheet;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public DruidPanel(){
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
|
||||
mainSplit.setDividerLocation(160);
|
||||
mainSplit.setBorder(BorderFactory.createEmptyBorder());
|
||||
|
||||
tree = new JTree();
|
||||
|
||||
JScrollPane theScrollPane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||||
JPanel treePanel = new JPanel(new BorderLayout());
|
||||
treePanel.add(theScrollPane, BorderLayout.CENTER);
|
||||
mainSplit.add(treePanel, JSplitPane.LEFT, 0);
|
||||
|
||||
sheet = new JPanel();
|
||||
mainSplit.add(sheet, JSplitPane.RIGHT, 0);
|
||||
|
||||
add(mainSplit);
|
||||
|
||||
this.setBackground(Color.BLUE);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
protected Object doInBackground(JConsoleContext context) throws Exception {
|
||||
MBeanServerConnection conn = context.getMBeanServerConnection();
|
||||
List<ObjectInstance> stats = new ArrayList<ObjectInstance>();
|
||||
|
||||
Set<ObjectInstance> instances = conn.queryMBeans(null, null);
|
||||
for (ObjectInstance instance : instances) {
|
||||
MBeanInfo info = conn.getMBeanInfo(instance.getObjectName());
|
||||
if ("com.alibaba.druid.stat.JdbcStatManager".equals(info.getClassName())) {
|
||||
stats.add(instance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (stats.size() == 0) {
|
||||
|
||||
}
|
||||
|
||||
this.setPreferredSize(new Dimension(400, 500));
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user