From ad83e270b6c76643320df2ea3fc8e757a8dedc29 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 19 Apr 2024 18:00:22 +0100 Subject: [PATCH] maybe fix --- .../backend/service/MojangService.java | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/main/java/xyz/mcutils/backend/service/MojangService.java b/src/main/java/xyz/mcutils/backend/service/MojangService.java index 356124e..70e6956 100644 --- a/src/main/java/xyz/mcutils/backend/service/MojangService.java +++ b/src/main/java/xyz/mcutils/backend/service/MojangService.java @@ -191,27 +191,22 @@ public class MojangService { return endpointStatus.get(); } - List> futures = new ArrayList<>(); - for (EndpointStatus endpoint : MOJANG_ENDPOINTS) { - futures.add(CompletableFuture.runAsync(() -> { - try { - long start = System.currentTimeMillis(); - InetAddress address = InetAddress.getByName(endpoint.getHostname()); - if (address.isReachable((int) TimeUnit.SECONDS.toMillis(4))) { // Check if the endpoint is reachable - endpoint.setStatus(EndpointStatus.Status.ONLINE); - return; - } - // Check if the endpoint took too long to respond - if (System.currentTimeMillis() - start > TimeUnit.SECONDS.toMillis(2)) { - endpoint.setStatus(EndpointStatus.Status.DEGRADED); - } - } catch (IOException e) { - endpoint.setStatus(EndpointStatus.Status.OFFLINE); + MOJANG_ENDPOINTS.parallelStream().forEach(endpoint -> { + try { + long start = System.currentTimeMillis(); + InetAddress address = InetAddress.getByName(endpoint.getHostname()); + if (address.isReachable((int) TimeUnit.SECONDS.toMillis(4))) { // Check if the endpoint is reachable + endpoint.setStatus(EndpointStatus.Status.ONLINE); + return; } - })); - } - - CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); + // Check if the endpoint took too long to respond + if (System.currentTimeMillis() - start > TimeUnit.SECONDS.toMillis(2)) { + endpoint.setStatus(EndpointStatus.Status.DEGRADED); + } + } catch (IOException e) { + endpoint.setStatus(EndpointStatus.Status.OFFLINE); + } + }); log.info("Fetched Mojang API status for {} endpoints", MOJANG_ENDPOINTS.size()); CachedEndpointStatus status = new CachedEndpointStatus(