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@225 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -30,16 +30,31 @@ import com.alibaba.druid.filter.trace.TraceEventListener;
|
||||
|
||||
public class JdbcTraceManager extends NotificationBroadcasterSupport implements JdbcTraceManagerMBean {
|
||||
|
||||
public final static Log LOG = LogFactory.getLog(JdbcTraceManager.class);
|
||||
public final static Log LOG = LogFactory.getLog(JdbcTraceManager.class);
|
||||
|
||||
private boolean traceEnable = false;
|
||||
private boolean traceEnable = false;
|
||||
|
||||
private final static JdbcTraceManager instance = new JdbcTraceManager();
|
||||
private final static JdbcTraceManager instance = new JdbcTraceManager();
|
||||
|
||||
private final List<TraceEventListener> eventListeners = new ArrayList<TraceEventListener>();
|
||||
private final List<TraceEventListener> eventListeners = new ArrayList<TraceEventListener>();
|
||||
|
||||
private final AtomicLong fireEventCount = new AtomicLong();
|
||||
private final AtomicLong skipEventCount = new AtomicLong();
|
||||
private final AtomicLong fireEventCount = new AtomicLong();
|
||||
private final AtomicLong skipEventCount = new AtomicLong();
|
||||
|
||||
private boolean notificationEnable = false;
|
||||
private final NotificationTraceEventListener notificationListener = new NotificationTraceEventListener();
|
||||
|
||||
public boolean isNotificationEnable() {
|
||||
return notificationEnable;
|
||||
}
|
||||
|
||||
public void setNotificationEnable(boolean notificationEnable) {
|
||||
this.notificationEnable = notificationEnable;
|
||||
}
|
||||
|
||||
public NotificationTraceEventListener getNotificationListener() {
|
||||
return notificationListener;
|
||||
}
|
||||
|
||||
public static JdbcTraceManager getInstance() {
|
||||
return instance;
|
||||
@@ -72,6 +87,10 @@ public class JdbcTraceManager extends NotificationBroadcasterSupport implements
|
||||
skipEventCount.incrementAndGet();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNotificationEnable()) {
|
||||
notificationListener.fireEvent(event);
|
||||
}
|
||||
|
||||
for (TraceEventListener listener : this.eventListeners) {
|
||||
try {
|
||||
@@ -85,15 +104,19 @@ public class JdbcTraceManager extends NotificationBroadcasterSupport implements
|
||||
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());
|
||||
|
||||
sendNotification(notification);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user