WANG 5 ani în urmă
părinte
comite
fc977b1566

+ 11 - 8
src/main/java/cn/com/qmth/examcloud/web/interceptor/ApiFlowLimitedInterceptor.java

@@ -55,7 +55,7 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
 
 	private static Map<String, RateLimiter> limiterMap = Maps.newConcurrentMap();
 
-	private static Map<String, Long> permitsPerSecondMap = Maps.newConcurrentMap();
+	private static Map<String, Integer> permitsPerSecondMap = Maps.newConcurrentMap();
 
 	static {
 		init();
@@ -63,7 +63,7 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
 
 	private static void init() {
 
-		double permitsPerSecond = PropertyHolder.getInt("examcloud.api.permitsPerSecond", 100000);
+		int permitsPerSecond = PropertyHolder.getInt("examcloud.api.permitsPerSecond", 100000);
 		rateLimiter = RateLimiter.create(permitsPerSecond);
 
 		enable = PropertyHolder.getBoolean("examcloud.api.flowLimited.enable", true);
@@ -77,9 +77,9 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
 			String value = (String) entry.getValue();
 
 			if (key.endsWith("[S]")) {
-				Long curPermitsPerSecond = null;
+				Integer curPermitsPerSecond = null;
 				try {
-					curPermitsPerSecond = Long.parseLong(value);
+					curPermitsPerSecond = Integer.parseInt(value);
 				} catch (NumberFormatException e) {
 					LOG.error("error value. key= " + key, e);
 					continue;
@@ -108,14 +108,17 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
 				while (true) {
 					refreshConfig();
 
-					for (Entry<String, Long> entry : permitsPerSecondMap.entrySet()) {
+					for (Entry<String, Integer> entry : permitsPerSecondMap.entrySet()) {
 						String key = entry.getKey();
-						Long value = entry.getValue();
+						Integer value = entry.getValue();
 
 						String curValue = (String) props.get(key);
-						Long curPermitsPerSecond = null;
+						if (StringUtils.isBlank(curValue)) {
+							continue;
+						}
+						Integer curPermitsPerSecond = null;
 						try {
-							curPermitsPerSecond = Long.parseLong(curValue);
+							curPermitsPerSecond = Integer.parseInt(curValue);
 						} catch (NumberFormatException e) {
 							LOG.error("error value. key= " + key, e);
 							continue;