|
@@ -6,6 +6,7 @@ import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
|
@@ -16,6 +17,7 @@ import org.springframework.http.MediaType;
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.DateUtil;
|
|
|
import cn.com.qmth.examcloud.commons.util.FreeMarkerUtil;
|
|
|
import cn.com.qmth.examcloud.commons.util.ResourceLoader;
|
|
|
|
|
@@ -30,6 +32,8 @@ import cn.com.qmth.examcloud.commons.util.ResourceLoader;
|
|
|
@Endpoint(id = "api-status")
|
|
|
public class ApiStatusEndpoint {
|
|
|
|
|
|
+ private static AtomicBoolean running = new AtomicBoolean(false);
|
|
|
+
|
|
|
@Autowired
|
|
|
ApiStatusInfoCollector apiStatusInfoCollector;
|
|
|
|
|
@@ -54,44 +58,55 @@ public class ApiStatusEndpoint {
|
|
|
@ReadOperation(produces = {MediaType.TEXT_HTML_VALUE})
|
|
|
public String get(@Selector String order) {
|
|
|
|
|
|
- List<ApiStatusInfo> list = ApiStatusInfoHolder.getApiStatusInfoList();
|
|
|
-
|
|
|
- Collections.sort(list, new Comparator<ApiStatusInfo>() {
|
|
|
- @Override
|
|
|
- public int compare(ApiStatusInfo o1, ApiStatusInfo o2) {
|
|
|
-
|
|
|
- try {
|
|
|
- Field field = o1.getClass().getDeclaredField(order);
|
|
|
- field.setAccessible(true);
|
|
|
- Object value1 = field.get(o1);
|
|
|
- Object value2 = field.get(o2);
|
|
|
-
|
|
|
- if (null == value1) {
|
|
|
- return -1;
|
|
|
- } else if (null == value2) {
|
|
|
- return 1;
|
|
|
- } else if (value1 instanceof Long) {
|
|
|
- return (int) (((Long) value2) - ((Long) value1));
|
|
|
- } else if (value1 instanceof Double) {
|
|
|
- return (int) (((Double) value2) - ((Double) value1));
|
|
|
- } else if (value1 instanceof String) {
|
|
|
- return ((String) value1).compareToIgnoreCase((String) value2);
|
|
|
- } else {
|
|
|
+ if (!running.compareAndSet(false, true)) {
|
|
|
+ return DateUtil.chinaNow() + " | 请求限制";
|
|
|
+ }
|
|
|
+
|
|
|
+ String ret = null;
|
|
|
+ try {
|
|
|
+ List<ApiStatusInfo> list = ApiStatusInfoHolder.getApiStatusInfoList();
|
|
|
+
|
|
|
+ Collections.sort(list, new Comparator<ApiStatusInfo>() {
|
|
|
+ @Override
|
|
|
+ public int compare(ApiStatusInfo o1, ApiStatusInfo o2) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ Field field = o1.getClass().getDeclaredField(order);
|
|
|
+ field.setAccessible(true);
|
|
|
+ Object value1 = field.get(o1);
|
|
|
+ Object value2 = field.get(o2);
|
|
|
+
|
|
|
+ if (null == value1) {
|
|
|
+ return -1;
|
|
|
+ } else if (null == value2) {
|
|
|
+ return 1;
|
|
|
+ } else if (value1 instanceof Long) {
|
|
|
+ return (int) (((Long) value2) - ((Long) value1));
|
|
|
+ } else if (value1 instanceof Double) {
|
|
|
+ return (int) (((Double) value2) - ((Double) value1));
|
|
|
+ } else if (value1 instanceof String) {
|
|
|
+ return ((String) value1).compareToIgnoreCase((String) value2);
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
return 0;
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- return 0;
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
+ map.put("data", list);
|
|
|
+ map.put("dateTime", new Date());
|
|
|
+
|
|
|
+ String html = ResourceLoader.getResource("api-status.html");
|
|
|
|
|
|
- Map<String, Object> map = Maps.newHashMap();
|
|
|
- map.put("data", list);
|
|
|
- map.put("dateTime", new Date());
|
|
|
+ ret = FreeMarkerUtil.process(html, map);
|
|
|
|
|
|
- String html = ResourceLoader.getResource("api-status.html");
|
|
|
+ } finally {
|
|
|
+ running.compareAndSet(true, false);
|
|
|
+ }
|
|
|
|
|
|
- String ret = FreeMarkerUtil.process(html, map);
|
|
|
return ret;
|
|
|
}
|
|
|
|