PushService for DruidMonitor ,test with druid-monitor

This commit is contained in:
sandzhang
2012-10-22 08:47:37 +08:00
parent 184ffa1567
commit 0577f0f96f
3 changed files with 68 additions and 13 deletions
@@ -83,7 +83,7 @@ public class PushService {
protected void execute() {
Map<String, Object> data = collectAndReset();
String json = JSONUtils.toJSONString(data);
push(json);
push("data=" + json);
}
/**
@@ -0,0 +1,38 @@
package com.alibaba.druid.support.monitor;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
public class PushServiceListener implements ServletContextListener {
private final static Log LOG = LogFactory.getLog(PushServiceListener.class);
private final static String MONITOR_SERVER_URL = "monitorServerUrl";
@Override
public void contextInitialized(ServletContextEvent sce) {
PushService pushService = PushService.getInstance();
String serverUrl = sce.getServletContext().getInitParameter(MONITOR_SERVER_URL);
if (serverUrl == null) {
LOG.error(MONITOR_SERVER_URL + " can't be null");
return;
}
if (LOG.isDebugEnabled()) {
LOG.debug(MONITOR_SERVER_URL + "= " + serverUrl);
}
pushService.setServerUrl(serverUrl);
pushService.start();
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub
}
}