com.logicbus.cache.service.CacheList Maven / Gradle / Ivy
package com.logicbus.cache.service;
import java.util.ArrayList;
import java.util.Collection;
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.alogic.cache.CacheObject;
import com.alogic.cache.naming.CacheStoreFactory;
import com.alogic.load.Store;
import com.logicbus.backend.AbstractServant;
import com.logicbus.backend.Context;
import com.logicbus.backend.message.JsonMessage;
import com.logicbus.backend.message.XMLMessage;
import com.logicbus.models.servant.ServiceDescription;
/**
* 列出当前存在的cache列表
*
* @author duanyy
* @since 1.6.3.3
* @version 1.6.4.19 [duanyy 20151218]
* - 按照SONAR建议修改代码
*
* @version 1.6.12.27 [20190403 duanyy]
* - 增加对yaml的支持
*/
public class CacheList extends AbstractServant {
@Override
protected int onXml(Context ctx){
XMLMessage msg = (XMLMessage) ctx.asMessage(XMLMessage.class);
Document doc = msg.getDocument();
Element root = msg.getRoot();
CacheStoreFactory src = CacheStoreFactory.get();
Collection> caches = src.current();
for (Store cache:caches){
Element eleCache = doc.createElement("cache");
cache.report(eleCache);
root.appendChild(eleCache);
}
return 0;
}
@Override
protected int onJson(Context ctx){
JsonMessage msg = (JsonMessage)ctx.asMessage(JsonMessage.class);
List