1
2
3
4
5
6
7
8
9
10
11 package org.apache.hadoop.hbase.quotas;
12
13 import org.apache.hadoop.hbase.classification.InterfaceAudience;
14 import org.apache.hadoop.hbase.classification.InterfaceStability;
15 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
16 import com.google.common.annotations.VisibleForTesting;
17
18
19
20
21 @InterfaceAudience.Private
22 @InterfaceStability.Evolving
23 public class FixedIntervalRateLimiter extends RateLimiter {
24 private long nextRefillTime = -1L;
25
26 @Override
27 public long refill(long limit) {
28 final long now = EnvironmentEdgeManager.currentTime();
29 if (now < nextRefillTime) {
30 return 0;
31 }
32 nextRefillTime = now + super.getTimeUnitInMillis();
33 return limit;
34 }
35
36 @Override
37 public long getWaitInterval(long limit, long available, long amount) {
38 if (nextRefillTime == -1) {
39 return 0;
40 }
41 final long now = EnvironmentEdgeManager.currentTime();
42 final long refillTime = nextRefillTime;
43 return refillTime - now;
44 }
45
46
47 @VisibleForTesting
48 @Override
49 public void setNextRefillTime(long nextRefillTime) {
50 this.nextRefillTime = nextRefillTime;
51 }
52
53 @VisibleForTesting
54 @Override
55 public long getNextRefillTime() {
56 return this.nextRefillTime;
57 }
58 }