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
17
18
19
20 @InterfaceAudience.Private
21 @InterfaceStability.Evolving
22 public class FixedIntervalRateLimiter extends RateLimiter {
23 private long nextRefillTime = -1L;
24
25 @Override
26 public long refill(long limit) {
27 final long now = EnvironmentEdgeManager.currentTime();
28 if (now < nextRefillTime) {
29 return 0;
30 }
31 nextRefillTime = now + super.getTimeUnitInMillis();
32 return limit;
33 }
34
35 @Override
36 public long getWaitInterval(long limit, long available, long amount) {
37 if (nextRefillTime == -1) {
38 return 0;
39 }
40 final long now = EnvironmentEdgeManager.currentTime();
41 final long refillTime = nextRefillTime;
42 return refillTime - now;
43 }
44
45
46 @Override
47 public void setNextRefillTime(long nextRefillTime) {
48 this.nextRefillTime = nextRefillTime;
49 }
50
51 @Override
52 public long getNextRefillTime() {
53 return this.nextRefillTime;
54 }
55 }