-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathRateLimiterInitialization.java
More file actions
109 lines (85 loc) · 2.49 KB
/
RateLimiterInitialization.java
File metadata and controls
109 lines (85 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package org.tron.common.parameter;
import com.typesafe.config.ConfigObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import lombok.Getter;
public class RateLimiterInitialization {
@Getter
private boolean httpFlag;
@Getter
private boolean rpcFlag;
@Getter
private Map<String, HttpRateLimiterItem> httpMap = new HashMap();
@Getter
private Map<String, RpcRateLimiterItem> rpcMap = new HashMap();
@Nullable
public static HttpRateLimiterItem createHttpItem(final ConfigObject asset) {
try {
return new HttpRateLimiterItem(asset);
} catch (Exception e) {
return null;
}
}
@Nullable
public static RpcRateLimiterItem createRpcItem(final ConfigObject asset) {
try {
return new RpcRateLimiterItem(asset);
} catch (Exception e) {
return null;
}
}
public void setHttpMap(List<HttpRateLimiterItem> list) {
for (HttpRateLimiterItem item : list) {
if (item != null) {
httpMap.put(item.component, item);
}
}
httpFlag = httpMap.size() > 0;
}
public void setRpcMap(List<RpcRateLimiterItem> list) {
for (RpcRateLimiterItem item : list) {
if (item != null) {
rpcMap.put(item.component, item);
}
}
rpcFlag = rpcMap.size() > 0;
}
public static class HttpRateLimiterItem {
@Getter
private String component;
@Getter
private String strategy;
@Getter
private String params;
public HttpRateLimiterItem(ConfigObject asset) {
component = asset.get("component").unwrapped().toString();
strategy = asset.get("strategy").unwrapped().toString();
params = asset.get("paramString").unwrapped().toString();
}
public HttpRateLimiterItem(String component, String strategy, String params) {
this.component = component;
this.strategy = strategy;
this.params = params;
}
}
public static class RpcRateLimiterItem {
@Getter
private String component;
@Getter
private String strategy;
@Getter
private String params;
public RpcRateLimiterItem(ConfigObject asset) {
component = asset.get("component").unwrapped().toString();
strategy = asset.get("strategy").unwrapped().toString();
params = asset.get("paramString").unwrapped().toString();
}
public RpcRateLimiterItem(String component, String strategy, String params) {
this.component = component;
this.strategy = strategy;
this.params = params;
}
}
}