Run #fetchMojangServerStatuses in parallel
This commit is contained in:
parent
b800badcc3
commit
9c4a39641d
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
package me.braydon.mc.model.cache;
|
package me.braydon.mc.model.cache;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import me.braydon.mc.model.MinecraftServer;
|
import me.braydon.mc.model.MinecraftServer;
|
||||||
@ -45,7 +46,7 @@ public final class CachedMinecraftServer implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* The cached server.
|
* The cached server.
|
||||||
*/
|
*/
|
||||||
@NonNull private final MinecraftServer value;
|
@JsonBackReference @NonNull private final MinecraftServer value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The unix timestamp of when this
|
* The unix timestamp of when this
|
||||||
|
@ -520,14 +520,12 @@ public final class MojangService {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private void fetchMojangServerStatuses() {
|
private void fetchMojangServerStatuses() {
|
||||||
log.info("Checking Mojang server statuses...");
|
log.info("Checking Mojang server statuses...");
|
||||||
long before = System.currentTimeMillis();
|
Arrays.stream(MojangServer.values()).parallel().forEach(server -> {
|
||||||
for (MojangServer server : MojangServer.values()) {
|
|
||||||
log.info("Pinging {}...", server.getEndpoint());
|
log.info("Pinging {}...", server.getEndpoint());
|
||||||
MojangServer.Status status = server.getStatus(); // Retrieve the server status
|
MojangServer.Status status = server.getStatus(); // Retrieve the server status
|
||||||
log.info("Retrieved status of {}: {}", server.getEndpoint(), status.name());
|
log.info("Retrieved status of {}: {}", server.getEndpoint(), status.name());
|
||||||
mojangServerStatuses.put(server, status); // Cache the server status
|
mojangServerStatuses.put(server, status); // Cache the server status
|
||||||
}
|
});
|
||||||
log.info("Mojang server status check took {}ms", System.currentTimeMillis() - before);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -561,7 +559,7 @@ public final class MojangService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String hashed = Hashing.sha1().hashBytes(hostname.toLowerCase().getBytes(StandardCharsets.ISO_8859_1)).toString();
|
String hashed = Hashing.sha1().hashBytes(hostname.toLowerCase().getBytes(StandardCharsets.ISO_8859_1)).toString();
|
||||||
boolean blocked = bannedServerHashes.contains(hashed); // Is the hostname blocked?
|
boolean blocked = bannedServerHashes != null && (bannedServerHashes.contains(hashed)); // Is the hostname blocked?
|
||||||
if (blocked) { // Cache the blocked hostname
|
if (blocked) { // Cache the blocked hostname
|
||||||
blockedServersCache.add(hostname);
|
blockedServersCache.add(hostname);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user