-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopologyCache.java
More file actions
79 lines (61 loc) · 2.15 KB
/
TopologyCache.java
File metadata and controls
79 lines (61 loc) · 2.15 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
package tech.stackable.hadoop;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import io.fabric8.kubernetes.api.model.Node;
import io.fabric8.kubernetes.api.model.Pod;
import java.util.List;
import java.util.concurrent.TimeUnit;
/** Manages all caching layers for the topology provider. */
public class TopologyCache {
private final Cache<String, String> topology;
private final Cache<String, Node> nodes;
private final Cache<String, GenericKubernetesResource> listeners;
private final Cache<String, Pod> pods;
TopologyCache(int expirationSeconds, int defaultExpirationSeconds) {
this.topology =
Caffeine.newBuilder().expireAfterWrite(expirationSeconds, TimeUnit.SECONDS).build();
this.nodes =
Caffeine.newBuilder().expireAfterWrite(defaultExpirationSeconds, TimeUnit.SECONDS).build();
this.listeners =
Caffeine.newBuilder().expireAfterWrite(defaultExpirationSeconds, TimeUnit.SECONDS).build();
this.pods =
Caffeine.newBuilder().expireAfterWrite(defaultExpirationSeconds, TimeUnit.SECONDS).build();
}
String getTopology(String key) {
return topology.getIfPresent(key);
}
void putTopology(String key, String value) {
topology.put(key, value);
}
void invalidateAllTopologyKeys() {
topology.invalidateAll();
}
void invalidateTopologyKeys(List<String> keys) {
keys.forEach(topology::invalidate);
}
Node getNode(String name) {
return nodes.getIfPresent(name);
}
void putNode(String name, Node node) {
nodes.put(name, node);
}
GenericKubernetesResource getListener(String name) {
return listeners.getIfPresent(name);
}
void putListener(String name, GenericKubernetesResource listener) {
listeners.put(name, listener);
}
Pod getPod(String name) {
return pods.getIfPresent(name);
}
void putPod(String name, Pod pod) {
pods.put(name, pod);
}
void deletePod(String name) {
pods.invalidate(name);
}
boolean hasAllPods(List<String> names) {
return names.stream().noneMatch(name -> pods.getIfPresent(name) == null);
}
}