com.logicbus.service.PooledServiceList Maven / Gradle / Ivy
package com.logicbus.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.logicbus.backend.message.YamlMessage;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.anysoft.util.Settings;
import com.logicbus.backend.AbstractServant;
import com.logicbus.backend.Context;
import com.logicbus.backend.ServantFactory;
import com.logicbus.backend.ServantPool;
import com.logicbus.backend.message.JsonMessage;
import com.logicbus.backend.message.XMLMessage;
import com.logicbus.models.servant.ServiceDescription;
/**
* PooledServiceList
*
* @version 1.6.12.27 [20190403 duanyy]
* - 增加对yaml的支持
*/
public class PooledServiceList extends AbstractServant {
@Override
protected void onDestroy() {
// nothing to do
}
@Override
protected void onCreate(ServiceDescription sd){
// nothing to do
}
protected int onXml(Context ctx){
XMLMessage msg = (XMLMessage)ctx.asMessage(XMLMessage.class);
Element root = msg.getRoot();
Document doc = root.getOwnerDocument();
Element service = doc.createElement("service");
Settings settings = Settings.get();
ServantFactory sf = (ServantFactory)settings.get("servantFactory");
ServantPool [] pools = sf.getPools();
for (ServantPool pool:pools){
ServiceDescription sd = pool.getDescription();
Element svc = doc.createElement("service");
//仅仅输出简要信息
//id
svc.setAttribute("id",sd.getServiceID());
//name
svc.setAttribute("name", sd.getName());
//note
svc.setAttribute("note", sd.getNote());
//module
svc.setAttribute("module",sd.getModule());
//visible
svc.setAttribute("visible",sd.getVisible());
//path
svc.setAttribute("path",sd.getPath());
//Properties
svc.setAttribute("log", sd.getLogType().toString());
svc.setAttribute("guard", Boolean.toString(sd.guard()));
svc.setAttribute("healthScore", String.valueOf(pool.getHealthScore()));
svc.setAttribute("activeScore", String.valueOf(pool.getActiveScore()));
service.appendChild(svc);
}
root.appendChild(service);
return 0;
}
protected int onJson(Context ctx){
JsonMessage msg = (JsonMessage)ctx.asMessage(JsonMessage.class);
Settings settings = Settings.get();
ServantFactory sf = (ServantFactory)settings.get("servantFactory");
ServantPool [] pools = sf.getPools();
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy