完善了jconsole相关的部分javadoc注释

This commit is contained in:
yunnysunny
2012-09-08 10:00:03 +08:00
parent f2123801a8
commit c42ed6ca8c
4 changed files with 186 additions and 30 deletions
@@ -30,35 +30,29 @@ import com.alibaba.druid.support.jconsole.util.TableDataProcessor;
import com.alibaba.druid.support.jconsole.util.TableDataProcessor.ColumnData;
/**
* 请求地址:/datasource.json
* service的请求地址:/datasource.json
*
* 请求返回的json格式: {"ResultCode":1, "Content":
* [{"Identity":31375837,"Name":"DataSource-31375837","DbType":"mysql",
* "DriverClassName":"com.mysql.jdbc.Driver",
* "URL":"jdbc:mysql://localhost:3306/dragoon_v25_masterdb","UserName":"root",
* "FilterClassNames":["com.alibaba.druid.filter.stat.StatFilter"],
* "WaitThreadCount"
* :0,"NotEmptyWaitCount":0,"NotEmptyWaitMillis":0,"PoolingCount":1,
* "PoolingPeak":0,"ActiveCount":0,"ActivePeak":1,"ActivePeakTime":
* "Tue Aug 21 21:22:33 CST 2012",
* "InitialSize":1,"MinIdle":1,"MaxActive":20,"QueryTimeout"
* :0,"TransactionQueryTimeout":0,
* "LoginTimeout":0,"ValidConnectionCheckerClassName"
* :"com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker",
* "ExceptionSorterClassName"
* :"com.alibaba.druid.pool.vendor.MySqlExceptionSorter",
* "TestOnBorrow":false,"TestOnReturn"
* :false,"TestWhileIdle":true,"DefaultAutoCommit":true,
* "DefaultReadOnly":true,"LogicConnectCount"
* :93,"LogicCloseCount":93,"LogicConnectErrorCount":0,
* "PhysicalConnectCount":1,
* "PhysicalCloseCount":0,"PhysicalConnectErrorCount":0,
* "ExecuteCount":93,"ErrorCount"
* :0,"CommitCount":0,"RollbackCount":0,"PSCacheAccessCount":31,
* "PSCacheHitCount":30,"PSCacheMissCount":1,"StartTransactionCount":0,
* "TransactionHistogram"
* :[0,0,0,0,0,0],"ConnectionHoldTimeHistogram":[0,0,48,45,0,0,0,0],
* "RemoveAbandoned":false }] }
* 请求service返回的json格式:
* {"ResultCode":1,
* "Content":
* [{"Identity":31375837,"Name":"DataSource-31375837","DbType":"mysql",
* "DriverClassName":"com.mysql.jdbc.Driver",
* "URL":"jdbc:mysql://localhost:3306/dragoon_v25_masterdb","UserName":"root",
* "FilterClassNames":["com.alibaba.druid.filter.stat.StatFilter"],
* "WaitThreadCount":0,"NotEmptyWaitCount":0,"NotEmptyWaitMillis":0,"PoolingCount":1,
* "PoolingPeak":0,"ActiveCount":0,"ActivePeak":1,"ActivePeakTime":"Tue Aug 21 21:22:33 CST 2012",
* "InitialSize":1,"MinIdle":1,"MaxActive":20,"QueryTimeout":0,"TransactionQueryTimeout":0,
* "LoginTimeout":0,"ValidConnectionCheckerClassName":"com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker",
* "ExceptionSorterClassName":"com.alibaba.druid.pool.vendor.MySqlExceptionSorter",
* "TestOnBorrow":false,"TestOnReturn":false,"TestWhileIdle":true,"DefaultAutoCommit":true,
* "DefaultReadOnly":true,"LogicConnectCount":93,"LogicCloseCount":93,"LogicConnectErrorCount":0,
* "PhysicalConnectCount":1,"PhysicalCloseCount":0,"PhysicalConnectErrorCount":0,
* "ExecuteCount":93,"ErrorCount":0,"CommitCount":0,"RollbackCount":0,"PSCacheAccessCount":31,
* "PSCacheHitCount":30,"PSCacheMissCount":1,"StartTransactionCount":0,
* "TransactionHistogram":[0,0,0,0,0,0],"ConnectionHoldTimeHistogram":[0,0,48,45,0,0,0,0],
* "RemoveAbandoned":false
* }]
* }
* */
public class DruidDataSourcePanel extends DruidPanel {
@@ -39,34 +39,63 @@ import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.sun.tools.jconsole.JConsoleContext;
/**
* druid面板的抽象类
* 在类在实现的时候,通过url地址获取数据,解析此数据,然后显示在界面中
*/
public abstract class DruidPanel extends JPanel {
private static final long serialVersionUID = 1L;
/** 成功的返回码 */
protected static final int RESP_SUCCESS_RESULT = 1;
/**返回码在json中的键名 */
protected static final String RESP_JSON_RESULT_KEY = "ResultCode";
/** 内容在json中的键名 */
protected static final String RESP_JSON_CONTENT_KEY = "Content";
/** 默认面板刷新的间隔时间 */
protected static final long DEFAULT_ACTIVE_TIME = 5*60*1000;
/**版权信息字符串 */
private static final String COPYRIGHT_STRING = "<html>powered by <a href=\"http://blog.csdn.net/yunnysunny\">yunnysunny</a></html>";
/**滚动条面板*/
protected JScrollPane scrollPane;
/** 表格模板 */
protected DruidTableModel tableModel;
/** 表格 */
protected JTable table;
/** 版权面板 */
protected JPanel copyrightPanel;
/** json请求的地址 */
protected String url;
/** 界面刷新的间隔时间,单位为毫秒. */
protected long activeTime;
/**上次刷新的时间*/
protected long lastRefreshTime;
private final static Log LOG = LogFactory.getLog(DruidPanel.class);
/**
* 根据传入的刷新时间间隔来初始化.
*
* @param activeTime 刷新时间间隔
*/
protected DruidPanel(long activeTime) {
this.activeTime = activeTime;
}
}
/**
* 初始化刷新时间间隔为默认值
* */
protected DruidPanel() {
activeTime = DEFAULT_ACTIVE_TIME;
}
/**
* 解析调用service后得到JSON数据
*
* @param respData 获取到的json对象
* @return 返回解析后的数据
*/
@SuppressWarnings("unchecked")
protected ArrayList<LinkedHashMap<String,Object>> parseData(Object respData) {
ArrayList<LinkedHashMap<String,Object>> data = null;
@@ -89,6 +118,14 @@ public abstract class DruidPanel extends JPanel {
return data;
}
/**
* 调用service,返回数据
*
* @param url service的地址
* @param conn MBeanServerConnection对象
* @return 调用service后返回的数据
* @throws Exception
*/
protected Object getData(String url,MBeanServerConnection conn) throws Exception {
Object o = null;
ObjectName name = new ObjectName(DruidStatService.MBEAN_NAME);
@@ -102,8 +139,21 @@ public abstract class DruidPanel extends JPanel {
return o;
}
/**
* 调用完service之后,各个子类对于解析后的数据的具体处理
*
* @param data 解析后的数据
*/
protected abstract void tableDataProcess(ArrayList<LinkedHashMap<String,Object>> data);
/**
* 如果是第一次调用,则生成表格对象;否则根据当前时间来和上次刷新时间的间隔,
* 是否大于对象初始化时设定的时间间隔来判断是否刷新表格数据。
*
* @param url service的地址
* @param conn MBeanServerConnection对象
* @throws Exception
*/
protected void addOrRefreshTable(String url,MBeanServerConnection conn) throws Exception {
if (url != null) {
boolean needRefresh = false;
@@ -21,8 +21,15 @@ import java.util.LinkedHashMap;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
/**
* 自定义duird监控数据表格模板类
*/
public class DruidTableModel implements TableModel {
/** 数据内容. */
private ArrayList<LinkedHashMap<String,Object>> list;
/** 自定义列名集合. */
private ArrayList<String> showKeys;
public DruidTableModel(ArrayList<LinkedHashMap<String, Object>> list) {
@@ -44,6 +51,9 @@ public class DruidTableModel implements TableModel {
return String.class;
}
/* 如果设置了列名,就是列名的长度;否则返回数据的第一条LinkedHashmap的长度
* @see javax.swing.table.TableModel#getColumnCount()
*/
@Override
public int getColumnCount() {
int colCount = 0;
@@ -58,6 +68,10 @@ public class DruidTableModel implements TableModel {
return colCount;
}
/* 如果设置了自定义列名,则使用自定义列名,并且在返回前拆除掉'-'前面的内容;
* 如果没有设置,则返回第一条内容的LinkedHashMap的键名。
* @see javax.swing.table.TableModel#getColumnName(int)
*/
@Override
public String getColumnName(int columnIndex) {
if (showKeys != null && showKeys.size() > 0) {
@@ -79,6 +93,10 @@ public class DruidTableModel implements TableModel {
return list.size();
}
/* 如果设置了自定义列名,则返回当前列数对应的列名在LinkedHashMap中对应的值;
* 否则,返回当前LinkedHashMap在当前列数位置对应的值。
* @see javax.swing.table.TableModel#getValueAt(int, int)
*/
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if (list != null && rowIndex < list.size()) {//没有超出最大行数
@@ -19,13 +19,32 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* The Class TableDataProcessor.
*/
public final class TableDataProcessor {
/** The Constant COLUMN_KEY_NAME. */
private static final String COLUMN_KEY_NAME = "名称";
/** The Constant COLUMN_VALUE_NAME. */
private static final String COLUMN_VALUE_NAME = "值";
/**
* Instantiates a new table data processor.
*/
private TableDataProcessor() {
}
/**
* 将行数据转化为列数据
* 由于json中的数据是按照一条条的记录返回的,而在显示的时候需要按照“名称”、“值”两列显示,所以要做转化。
*
* @param rowDatas 原始数据
* @param keyword 关键字,可以为null
* @return 生成的列数据的对象
*/
public static ColumnData row2col(
ArrayList<LinkedHashMap<String, Object>> rowDatas, String keyword) {
ColumnData datas = new ColumnData();
@@ -58,6 +77,15 @@ public final class TableDataProcessor {
return datas;
}
/**
* 将行数据转化为多个表格中的列数据
* 和{@link #row2col(ArrayList<LinkedHashMap<String,Object>>, String)}类似,
* 只不过这里是返回多个表格数据
*
* @param rowDatas 原始数据
* @param keyword the keyword
* @return 生成的列数据的对象
*/
public static ColumnData mutilRow2col(
ArrayList<LinkedHashMap<String, Object>> rowDatas, String keyword) {
ColumnData datas = new ColumnData();
@@ -92,44 +120,110 @@ public final class TableDataProcessor {
return datas;
}
/**
* 将行数据转化为列数据,这里只是调用了{@link #row2col(ArrayList<LinkedHashMap<String,Object>>, String)},
* 将第二个参数置为null。
*
* @param rowDatas 原始数据
* @return 生成的列数据的对象
*/
public static ColumnData row2col(
ArrayList<LinkedHashMap<String, Object>> rowDatas) {
return row2col(rowDatas,null);
}
/**
* The Class ColumnData.
*/
public static class ColumnData {
/** 关键字集合. */
private ArrayList<String> names;
/** 单个表格数据. */
private ArrayList<LinkedHashMap<String, Object>> datas;
/** 多个表格数据. */
private ArrayList<ArrayList<LinkedHashMap<String, Object>>> tableDatas;
/** 返回的数据总数,如果返回单个表格,则为表格行数;如果返回多个表格数据,则为表格个数. */
private int count;
/**
* Instantiates a new column data.
*/
public ColumnData() {
super();
}
/**
* 获取关键字集合
*
* @return the names
*/
public ArrayList<String> getNames() {
return names;
}
/**
* 设置关键字集合
*
* @param names the new names
*/
public void setNames(ArrayList<String> names) {
this.names = names;
}
/**
* 获取单个表格数据
*
* @return the datas
*/
public ArrayList<LinkedHashMap<String, Object>> getDatas() {
return datas;
}
/**
* 设置单个表格数据
*
* @param datas the datas
*/
public void setDatas(ArrayList<LinkedHashMap<String, Object>> datas) {
this.datas = datas;
}
/**
* 返回的数据总数,如果返回单个表格,则为表格行数;如果返回多个表格数据,则为表格个数
*
* @return the count
*/
public int getCount() {
return count;
}
/**
* Sets the count.
*
* @param count the new count
*/
public void setCount(int count) {
this.count = count;
}
/**
* 返回多个表格数据
*
* @return the table datas
*/
public ArrayList<ArrayList<LinkedHashMap<String, Object>>> getTableDatas() {
return tableDatas;
}
/**
* 设置多个表格数据
*
* @param tableDatas the table datas
*/
public void setTableDatas(
ArrayList<ArrayList<LinkedHashMap<String, Object>>> tableDatas) {
this.tableDatas = tableDatas;