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