maybe fix

This commit is contained in:
Lee 2024-04-19 18:00:22 +01:00
parent aa69970ec7
commit ad83e270b6

@ -191,27 +191,22 @@ public class MojangService {
return endpointStatus.get(); return endpointStatus.get();
} }
List<CompletableFuture<Void>> futures = new ArrayList<>(); MOJANG_ENDPOINTS.parallelStream().forEach(endpoint -> {
for (EndpointStatus endpoint : MOJANG_ENDPOINTS) { try {
futures.add(CompletableFuture.runAsync(() -> { long start = System.currentTimeMillis();
try { InetAddress address = InetAddress.getByName(endpoint.getHostname());
long start = System.currentTimeMillis(); if (address.isReachable((int) TimeUnit.SECONDS.toMillis(4))) { // Check if the endpoint is reachable
InetAddress address = InetAddress.getByName(endpoint.getHostname()); endpoint.setStatus(EndpointStatus.Status.ONLINE);
if (address.isReachable((int) TimeUnit.SECONDS.toMillis(4))) { // Check if the endpoint is reachable return;
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);
} }
})); // Check if the endpoint took too long to respond
} if (System.currentTimeMillis() - start > TimeUnit.SECONDS.toMillis(2)) {
endpoint.setStatus(EndpointStatus.Status.DEGRADED);
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); }
} catch (IOException e) {
endpoint.setStatus(EndpointStatus.Status.OFFLINE);
}
});
log.info("Fetched Mojang API status for {} endpoints", MOJANG_ENDPOINTS.size()); log.info("Fetched Mojang API status for {} endpoints", MOJANG_ENDPOINTS.size());
CachedEndpointStatus status = new CachedEndpointStatus( CachedEndpointStatus status = new CachedEndpointStatus(