Authored by hugufei

添加try_catch

... ... @@ -22,22 +22,27 @@ public class PersionalRateLimitService {
private Map<String, Integer> oldCountMap = new ConcurrentHashMap<String, Integer>();
public boolean isPersionalRateLimit(String rateLimitName, PersionalRateLimitConfig limitConfig) {
long expireTime = System.currentTimeMillis() + limitConfig.getSecond() * 1000L;
KeyCountWithExpiredTime keyCountWithExpiredTime = keyCountMap.putIfAbsent(rateLimitName, new KeyCountWithExpiredTime(expireTime));
if (keyCountWithExpiredTime == null) {
keyCountWithExpiredTime = keyCountMap.get(rateLimitName);
}
int currentCount = keyCountWithExpiredTime.incrementAndGet(expireTime);
if (currentCount == 1 && oldCountMap.containsKey(rateLimitName)) {
DOWNGRADE.error("PersionalRateLimit happen ,rateLimitName is [{}], oldCount is[{}], limitConfig is [{}]", rateLimitName,oldCountMap.get(rateLimitName), limitConfig.toLogInfo());
oldCountMap.remove(rateLimitName);
}
if (currentCount <= limitConfig.getLimit()) {
try {
long expireTime = System.currentTimeMillis() + limitConfig.getSecond() * 1000L;
KeyCountWithExpiredTime keyCountWithExpiredTime = keyCountMap.putIfAbsent(rateLimitName, new KeyCountWithExpiredTime(expireTime));
if (keyCountWithExpiredTime == null) {
keyCountWithExpiredTime = keyCountMap.get(rateLimitName);
}
int currentCount = keyCountWithExpiredTime.incrementAndGet(expireTime);
if (currentCount == 1 && oldCountMap.containsKey(rateLimitName)) {
DOWNGRADE.error("PersionalRateLimit happen ,rateLimitName is [{}], oldCount is[{}], limitConfig is [{}]", rateLimitName,oldCountMap.get(rateLimitName), limitConfig.toLogInfo());
oldCountMap.remove(rateLimitName);
}
if (currentCount <= limitConfig.getLimit()) {
return false;
}
oldCountMap.put(rateLimitName, currentCount);
DOWNGRADE.error("PersionalRateLimit happen ,rateLimitName is [{}],currentCount is[{}], limitConfig is [{}]", rateLimitName,currentCount, limitConfig.toLogInfo());
return true;
}catch (Exception e){
DOWNGRADE.error(e.getMessage(),e);
return false;
}
oldCountMap.put(rateLimitName, currentCount);
DOWNGRADE.error("PersionalRateLimit happen ,rateLimitName is [{}],currentCount is[{}], limitConfig is [{}]", rateLimitName,currentCount, limitConfig.toLogInfo());
return true;
}
}
... ...