/***********************************************/
//>将返回的namedList转换成Json格式
//>如何将CoreAdminRequest.getStatus("",server);
//>需要依赖的jar处理solr的jar之外还要orgJson.jar
/***********************************************/
/***********************************************/
>0.示例代码
public void getCoreContainerStats() {
try {
String solrServerUrl = "http://" + this.sc.getIp() + ":"
+ this.sc.getPort() + "/" + this.sc.getAppName() + "/";
CoreAdminRequest req = new CoreAdminRequest();
req.setAction(org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.STATUS);
server = new CommonsHttpSolrServer(solrServerUrl);
CoreAdminResponse cr = req.process(server);
StringBuffer sb = new StringBuffer();
NamedList ctLst = cr.getCoreStatus();// 得到所有在容器中的实例信息
NamedList headLst = cr.getResponseHeader();// 得到响应的头信息
Map mp = new HashMap();
for (int i = 0; i < headLst.size(); i++) {
mp.put(headLst.getName(i), headLst.getVal(i));
}
// 将响应的头的map转换成一个json对象然后添加到里面
List mLst = new ArrayList();
// 如果有多实例的话就看作一个数组
for (int i = 0; i < ctLst.size(); i++) {
System.out.println("=========================");
SimpleOrderedMap smp = (SimpleOrderedMap) ctLst.getVal(i);
System.out.println(ctLst.getName(i));
System.out.println(ctLst.getVal(i));
Map p = new HashMap();
SimpleOrderedMap sap = (SimpleOrderedMap) ctLst.getVal(i);
mLst.add(p);
Map a = new HashMap();
for (int k = 0; k < sap.size(); k++) {
p.put(sap.getName(k), sap.getVal(k));
// 得到index节点
SimpleOrderedMap op = (SimpleOrderedMap) sap.get("index");
p.put("index", a);
for (int j = 0; j < op.size(); j++) {
a.put(op.getName(j), op.getVal(j));
}
}
}
Map pp = new HashMap();
pp.put("status", mLst);
pp.put("responseHeader", mp);
this.sc.setSolrCoreContainerStats(pp);
} catch (Exception e) {
e.printStackTrace();
}
}
/***********************************************/
/***********************************************/
>1.实例json
//var s = {
// "appName" : "solrQuery",
// "port" : "8080",
// "hasBeenCreated" : "true",
// "solrHome" : "D:/03workspaces/solrQuery/solrhome",
// "solrCoreContainerStats" : {
// "responseHeader" : {
// "status" : 0,
// "QTime" : 0
// },
// "status" : [
// {
// "startTime" : "Thu Mar 22 13:13:42 CST 2012",
// "index" : {
// "segmentCount" : 0,
// "numDocs" : 0,
// "lastModified" : "Tue Mar 20 13:26:40 CST 2012",
// "directory" : "org.apache.lucene.store.MMapDirectory:org.apache.lucene.store.MMapDirectory@D:\\03workspaces\\solrQuery\\solrhome\\data\\index lockFactory=org.apache.lucene.store.NativeFSLockFactory@a0ccc96",
// "current" : true,
// "maxDoc" : 0,
// "hasDeletions" : false,
// "version" : 1332221200864
// },
// "instanceDir" : "D:\\03workspaces\\solrQuery\\solrhome\\.\\",
// "name" : "",
// "uptime" : 830146,
// "dataDir" : "D:\\\\03workspaces\\\\solrQuery\\\\solrhome\\.\\data\\"
// },
// {
// "startTime" : "Thu Mar 22 13:15:54 CST 2012",
// "index" : {
// "segmentCount" : 0,
// "numDocs" : 0,
// "lastModified" : "Thu Mar 22 13:15:55 CST 2012",
// "directory" : "org.apache.lucene.store.MMapDirectory:org.apache.lucene.store.MMapDirectory@D:\\03workspaces\\solrQuery\\solrhome\\solrcore10\\data\\index lockFactory=org.apache.lucene.store.NativeFSLockFactory@69b8b810",
// "current" : true,
// "maxDoc" : 0,
// "hasDeletions" : false,
// "version" : 1332393355047
// },
// "instanceDir" : "D:\\03workspaces\\solrQuery\\solrhome\\solrcore10\\",
// "name" : "solrcore10",
// "uptime" : 698103,
// "dataDir" : "D:\\03workspaces\\solrQuery\\solrhome\\solrcore10\\data\\"
// } ]
// },
// "instanceDir" : "D:/03workspaces/solrQuery/solrhome/solrcore10",
// "solrCoreName" : "solrcore10",
// "ip" : "localhost"
//};
/***********************************************/