local variable type inference changes (#1043)
local variable type inference changes for throttling design pattern
This commit is contained in:
parent
03e1e92b52
commit
954e7300e9
@ -53,11 +53,11 @@ public class App {
|
|||||||
* @param args main arguments
|
* @param args main arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
CallsCount callsCount = new CallsCount();
|
var callsCount = new CallsCount();
|
||||||
Tenant adidas = new Tenant("Adidas", 5, callsCount);
|
var adidas = new Tenant("Adidas", 5, callsCount);
|
||||||
Tenant nike = new Tenant("Nike", 6, callsCount);
|
var nike = new Tenant("Nike", 6, callsCount);
|
||||||
|
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
var executorService = Executors.newFixedThreadPool(2);
|
||||||
|
|
||||||
executorService.execute(() -> makeServiceCalls(adidas, callsCount));
|
executorService.execute(() -> makeServiceCalls(adidas, callsCount));
|
||||||
executorService.execute(() -> makeServiceCalls(nike, callsCount));
|
executorService.execute(() -> makeServiceCalls(nike, callsCount));
|
||||||
@ -74,8 +74,8 @@ public class App {
|
|||||||
* Make calls to the B2BService dummy API
|
* Make calls to the B2BService dummy API
|
||||||
*/
|
*/
|
||||||
private static void makeServiceCalls(Tenant tenant, CallsCount callsCount) {
|
private static void makeServiceCalls(Tenant tenant, CallsCount callsCount) {
|
||||||
Throttler timer = new ThrottleTimerImpl(10, callsCount);
|
var timer = new ThrottleTimerImpl(10, callsCount);
|
||||||
B2BService service = new B2BService(timer, callsCount);
|
var service = new B2BService(timer, callsCount);
|
||||||
for (int i = 0; i < 20; i++) {
|
for (int i = 0; i < 20; i++) {
|
||||||
service.dummyCustomerApi(tenant);
|
service.dummyCustomerApi(tenant);
|
||||||
// Sleep is introduced to keep the output in check and easy to view and analyze the results.
|
// Sleep is introduced to keep the output in check and easy to view and analyze the results.
|
||||||
|
@ -48,8 +48,8 @@ class B2BService {
|
|||||||
* @return customer id which is randomly generated
|
* @return customer id which is randomly generated
|
||||||
*/
|
*/
|
||||||
public int dummyCustomerApi(Tenant tenant) {
|
public int dummyCustomerApi(Tenant tenant) {
|
||||||
String tenantName = tenant.getName();
|
var tenantName = tenant.getName();
|
||||||
long count = callsCount.getCount(tenantName);
|
var count = callsCount.getCount(tenantName);
|
||||||
LOGGER.debug("Counter for {} : {} ", tenant.getName(), count);
|
LOGGER.debug("Counter for {} : {} ", tenant.getName(), count);
|
||||||
if (count >= tenant.getAllowedCallsPerSecond()) {
|
if (count >= tenant.getAllowedCallsPerSecond()) {
|
||||||
LOGGER.error("API access per second limit reached for: {}", tenantName);
|
LOGGER.error("API access per second limit reached for: {}", tenantName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user