@Test public void existingHostUpdated() { registry.tick("aaa"); assertEquals(1L, registry.tick("bbb")); assertEquals(2L, registry.tick("aaa")); }
public long tick(String clientHostId) { if (whiteList.contains(clientHostId)) { return 0; } else if (blackList.contains(clientHostId)) { return Long.MAX_VALUE; } IntervalCount intervalCount = hostCounts.computeIfAbsent(clientHostId, s -> new IntervalCount(intervalDurationMs)); return intervalCount.resetIfExpiredAndTick(); }
HostRequestIntervalRegistry { public long tick(String clientHostId) { if (whiteList.contains(clientHostId)) { return 0; } else if (blackList.contains(clientHostId)) { return Long.MAX_VALUE; } IntervalCount intervalCount = hostCounts.computeIfAbsent(clientHostId, s -> new IntervalCount(intervalDurationMs)); return intervalCount.resetIfExpiredAndTick(); } }
HostRequestIntervalRegistry { public long tick(String clientHostId) { if (whiteList.contains(clientHostId)) { return 0; } else if (blackList.contains(clientHostId)) { return Long.MAX_VALUE; } IntervalCount intervalCount = hostCounts.computeIfAbsent(clientHostId, s -> new IntervalCount(intervalDurationMs)); return intervalCount.resetIfExpiredAndTick(); } HostRequestIntervalRegistry(@Value("${quota.host.intervalMs}") long intervalDurationMs,
                                       @Value("${quota.host.ttlMs}") long ttlMs,
                                       @Value("${quota.host.whitelist}") String whiteList,
                                       @Value("${quota.host.blacklist}") String blackList); }
HostRequestIntervalRegistry { public long tick(String clientHostId) { if (whiteList.contains(clientHostId)) { return 0; } else if (blackList.contains(clientHostId)) { return Long.MAX_VALUE; } IntervalCount intervalCount = hostCounts.computeIfAbsent(clientHostId, s -> new IntervalCount(intervalDurationMs)); return intervalCount.resetIfExpiredAndTick(); } HostRequestIntervalRegistry(@Value("${quota.host.intervalMs}") long intervalDurationMs,
                                       @Value("${quota.host.ttlMs}") long ttlMs,
                                       @Value("${quota.host.whitelist}") String whiteList,
                                       @Value("${quota.host.blacklist}") String blackList); @PostConstruct void init(); long tick(String clientHostId); void clean(); Map<String, Long> getContent(); }
HostRequestIntervalRegistry { public long tick(String clientHostId) { if (whiteList.contains(clientHostId)) { return 0; } else if (blackList.contains(clientHostId)) { return Long.MAX_VALUE; } IntervalCount intervalCount = hostCounts.computeIfAbsent(clientHostId, s -> new IntervalCount(intervalDurationMs)); return intervalCount.resetIfExpiredAndTick(); } HostRequestIntervalRegistry(@Value("${quota.host.intervalMs}") long intervalDurationMs,
                                       @Value("${quota.host.ttlMs}") long ttlMs,
                                       @Value("${quota.host.whitelist}") String whiteList,
                                       @Value("${quota.host.blacklist}") String blackList); @PostConstruct void init(); long tick(String clientHostId); void clean(); Map<String, Long> getContent();  }