|
@@ -58,17 +58,20 @@ public class RateLimiterController implements TrafficShapingController { |
|
|
} else { |
|
|
} else { |
|
|
// Calculate the time to wait. |
|
|
// Calculate the time to wait. |
|
|
long waitTime = costTime + latestPassedTime.get() - TimeUtil.currentTimeMillis(); |
|
|
long waitTime = costTime + latestPassedTime.get() - TimeUtil.currentTimeMillis(); |
|
|
if (waitTime >= maxQueueingTimeMs) { |
|
|
|
|
|
|
|
|
if (waitTime > maxQueueingTimeMs) { |
|
|
return false; |
|
|
return false; |
|
|
} else { |
|
|
} else { |
|
|
long oldTime = latestPassedTime.addAndGet(costTime); |
|
|
long oldTime = latestPassedTime.addAndGet(costTime); |
|
|
try { |
|
|
try { |
|
|
waitTime = oldTime - TimeUtil.currentTimeMillis(); |
|
|
waitTime = oldTime - TimeUtil.currentTimeMillis(); |
|
|
if (waitTime >= maxQueueingTimeMs) { |
|
|
|
|
|
|
|
|
if (waitTime > maxQueueingTimeMs) { |
|
|
latestPassedTime.addAndGet(-costTime); |
|
|
latestPassedTime.addAndGet(-costTime); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
Thread.sleep(waitTime); |
|
|
|
|
|
|
|
|
// in race condition waitTime may <= 0 |
|
|
|
|
|
if (waitTime > 0) { |
|
|
|
|
|
Thread.sleep(waitTime); |
|
|
|
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} catch (InterruptedException e) { |
|
|
} catch (InterruptedException e) { |
|
|
} |
|
|
} |
|
|