mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
修改TraceFilter
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@224 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -19,21 +19,24 @@ import java.util.Date;
|
||||
|
||||
public class TraceAfterEvent extends TraceEvent {
|
||||
|
||||
private long timespan;
|
||||
|
||||
public TraceAfterEvent(){
|
||||
}
|
||||
|
||||
public TraceAfterEvent(String eventType, Date eventTime, long timespan){
|
||||
super(eventType, eventTime);
|
||||
this.timespan = timespan;
|
||||
this.getContext().put("timespan", timespan);
|
||||
}
|
||||
|
||||
public long getTimespan() {
|
||||
return timespan;
|
||||
Long timespan = ((Long) getContext().get("timespan"));
|
||||
if (timespan == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return timespan.longValue();
|
||||
}
|
||||
|
||||
public void setTimespan(long timespan) {
|
||||
this.timespan = timespan;
|
||||
this.getContext().put("timespan", timespan);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ import java.util.Date;
|
||||
|
||||
public class TraceErrorEvent extends TraceEvent {
|
||||
|
||||
private Throwable error;
|
||||
private Date errorTime = new Date();
|
||||
|
||||
public TraceErrorEvent(){
|
||||
|
||||
}
|
||||
@@ -29,23 +26,23 @@ public class TraceErrorEvent extends TraceEvent {
|
||||
public TraceErrorEvent(String eventType, Date eventTime, Throwable error){
|
||||
super(eventType, eventTime);
|
||||
|
||||
this.error = error;
|
||||
this.getContext().put("error", error);
|
||||
}
|
||||
|
||||
public Throwable getError() {
|
||||
return error;
|
||||
return (Throwable) getContext().get("error");
|
||||
}
|
||||
|
||||
public void setError(Throwable error) {
|
||||
this.error = error;
|
||||
this.getContext().put("error", error);
|
||||
}
|
||||
|
||||
public Date getErrorTime() {
|
||||
return errorTime;
|
||||
return (Date) getContext().get("errorTime");
|
||||
}
|
||||
|
||||
public void setErrorTime(Date errorTime) {
|
||||
this.errorTime = errorTime;
|
||||
this.getContext().put("errorTime", errorTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ public class DataSourceInfo {
|
||||
|
||||
private String rawDriverClassName;
|
||||
private String rawUrl;
|
||||
private String rawDriverMajorVersion;
|
||||
private String rawDriverMinorVersion;
|
||||
private int rawDriverMajorVersion;
|
||||
private int rawDriverMinorVersion;
|
||||
private String properties;
|
||||
|
||||
public DataSourceInfo(){
|
||||
@@ -35,8 +35,8 @@ public class DataSourceInfo {
|
||||
|
||||
this.rawDriverClassName = (String) data.get("RawDriverClassName");
|
||||
this.rawUrl = (String) data.get("RawUrl");
|
||||
this.rawDriverMajorVersion = (String) data.get("RawDriverMajorVersion");
|
||||
this.rawDriverMinorVersion = (String) data.get("RawDriverMinorVersion");
|
||||
this.rawDriverMajorVersion = ((Number) data.get("RawDriverMajorVersion")).intValue();
|
||||
this.rawDriverMinorVersion = ((Number) data.get("RawDriverMinorVersion")).intValue();
|
||||
this.properties = (String) data.get("Properties");
|
||||
}
|
||||
|
||||
@@ -96,19 +96,19 @@ public class DataSourceInfo {
|
||||
this.rawUrl = rawUrl;
|
||||
}
|
||||
|
||||
public String getRawDriverMajorVersion() {
|
||||
public int getRawDriverMajorVersion() {
|
||||
return rawDriverMajorVersion;
|
||||
}
|
||||
|
||||
public void setRawDriverMajorVersion(String rawDriverMajorVersion) {
|
||||
public void setRawDriverMajorVersion(int rawDriverMajorVersion) {
|
||||
this.rawDriverMajorVersion = rawDriverMajorVersion;
|
||||
}
|
||||
|
||||
public String getRawDriverMinorVersion() {
|
||||
public int getRawDriverMinorVersion() {
|
||||
return rawDriverMinorVersion;
|
||||
}
|
||||
|
||||
public void setRawDriverMinorVersion(String rawDriverMinorVersion) {
|
||||
public void setRawDriverMinorVersion(int rawDriverMinorVersion) {
|
||||
this.rawDriverMinorVersion = rawDriverMinorVersion;
|
||||
}
|
||||
|
||||
|
||||
@@ -122,9 +122,10 @@ public class DruidPanel extends JPanel {
|
||||
for (Object item : tabularValue.values()) {
|
||||
CompositeData rowData = (CompositeData) item;
|
||||
|
||||
String name = (String) rowData.get("Name");
|
||||
|
||||
DefaultMutableTreeNode dataSourceNode = new DefaultMutableTreeNode(name, true);
|
||||
DataSourceInfo dataSourceInfo = new DataSourceInfo(rowData);
|
||||
|
||||
DefaultMutableTreeNode dataSourceNode = new DefaultMutableTreeNode(dataSourceInfo.getName(), true);
|
||||
dataSourceNode.setUserObject(dataSourceInfo);
|
||||
|
||||
DefaultMutableTreeNode connections = new DefaultMutableTreeNode("Connections", true);
|
||||
{
|
||||
@@ -160,8 +161,8 @@ public class DruidPanel extends JPanel {
|
||||
dataSourcesNode.add(dataSource);
|
||||
}
|
||||
|
||||
TreePath path = new TreePath(dataSourcesNode.children());
|
||||
tree.scrollPathToVisible(path);
|
||||
// TreePath path = new TreePath(dataSourcesNode.children());
|
||||
// tree.scrollPathToVisible(path);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -19,13 +19,16 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.management.Notification;
|
||||
import javax.management.NotificationBroadcasterSupport;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.alibaba.druid.filter.trace.TraceEvent;
|
||||
import com.alibaba.druid.filter.trace.TraceEventListener;
|
||||
|
||||
public class JdbcTraceManager implements JdbcTraceManagerMBean {
|
||||
public class JdbcTraceManager extends NotificationBroadcasterSupport implements JdbcTraceManagerMBean {
|
||||
|
||||
public final static Log LOG = LogFactory.getLog(JdbcTraceManager.class);
|
||||
|
||||
@@ -82,4 +85,15 @@ public class JdbcTraceManager implements JdbcTraceManagerMBean {
|
||||
public List<TraceEventListener> getEventListeners() {
|
||||
return eventListeners;
|
||||
}
|
||||
|
||||
public class NotificationTraceEventListener implements TraceEventListener {
|
||||
private long sequenceNumber = 0;
|
||||
@Override
|
||||
public void fireEvent(TraceEvent event) {
|
||||
Notification notification = new Notification(event.getEventType(), null, sequenceNumber++);
|
||||
notification.setTimeStamp(event.getEventTime().getTime());
|
||||
notification.setUserData(event.getContext());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user