com.logicbus.service.MetricsPause Maven / Gradle / Ivy
package com.logicbus.service;
import java.util.HashMap;
import java.util.Map;
import com.logicbus.backend.message.YamlMessage;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.alogic.metrics.Fragment;
import com.alogic.metrics.stream.MetricsHandlerFactory;
import com.anysoft.stream.Handler;
import com.logicbus.backend.AbstractServant;
import com.logicbus.backend.Context;
import com.logicbus.backend.ServantException;
import com.logicbus.backend.message.JsonMessage;
import com.logicbus.backend.message.XMLMessage;
import com.logicbus.models.servant.ServiceDescription;
/**
* 暂停指标处理
*
* @author duanyy
* @version 1.4.0 [20141117 duanyy]
* - 将MessageDoc和Context进行合并整合
*
* @version 1.6.6.13 [20170109 duanyy]
* - 采用新的指标接口
* - 增加对yaml的支持
*/
public class MetricsPause extends AbstractServant{
protected void onDestroy() {
}
protected void onCreate(ServiceDescription sd) throws ServantException{
}
protected int onXml(Context ctx) {
XMLMessage msg = (XMLMessage) ctx.asMessage(XMLMessage.class);
Handler handler = MetricsHandlerFactory.getClientInstance();
if (handler != null){
handler.pause();
Element root = msg.getRoot();
Document doc = root.getOwnerDocument();
Element logger = doc.createElement(handler.getHandlerType());
handler.report(logger);
root.appendChild(logger);
}
return 0;
}
protected int onJson(Context ctx) {
JsonMessage msg = (JsonMessage)ctx.asMessage(JsonMessage.class);
Handler handler = MetricsHandlerFactory.getClientInstance();
if (handler != null){
handler.pause();
Map root = msg.getRoot();
Map logger = new HashMap();
handler.report(logger);
root.put(handler.getHandlerType(), logger);
}
return 0;
}
protected int onYaml(Context ctx) {
YamlMessage msg = (YamlMessage)ctx.asMessage(YamlMessage.class);
Handler handler = MetricsHandlerFactory.getClientInstance();
if (handler != null){
handler.pause();
Map root = msg.getRoot();
Map logger = new HashMap();
handler.report(logger);
root.put(handler.getHandlerType(), logger);
}
return 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy