generated from root/miduo_server
parent
fd49891145
commit
e5573dfcaf
|
@ -15,6 +15,8 @@ import java.io.IOException;
|
|||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class GetServerListController extends HttpServlet {
|
||||
private final static String _COLLECTION_NAME = "server_info";
|
||||
|
@ -38,6 +40,7 @@ public class GetServerListController extends HttpServlet {
|
|||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String regEx="[^0-9]";
|
||||
try {
|
||||
String openId = request.getParameter("openId");
|
||||
String channel = request.getParameter("channel");
|
||||
|
@ -119,6 +122,15 @@ public class GetServerListController extends HttpServlet {
|
|||
ip = "";
|
||||
port = "";
|
||||
}
|
||||
String a = (String) serverInfo.get("name");
|
||||
Pattern p = Pattern.compile(regEx);
|
||||
Matcher m = p.matcher(a);
|
||||
String result = m.replaceAll("").trim();
|
||||
if (result.isEmpty()) {
|
||||
res.put("sort", 9999);
|
||||
} else {
|
||||
res.put("sort", Integer.parseInt(result));
|
||||
}
|
||||
res.put("ip", ip);
|
||||
res.put("port", port);
|
||||
serverList.add(res);
|
||||
|
@ -154,7 +166,12 @@ public class GetServerListController extends HttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(serverList, new Comparator<DBObject>() {
|
||||
@Override
|
||||
public int compare(DBObject dbObject1, DBObject dbObject2) {
|
||||
return Integer.compare((int) dbObject1.get("sort"), (int) dbObject2.get("sort"));
|
||||
}
|
||||
});
|
||||
DBObject resp = new BasicDBObject();
|
||||
resp.put("serverList", serverList);
|
||||
resp.put("myServerList", myServerList);
|
||||
|
|
Loading…
Reference in New Issue