Fixed offline servers sometimes not being marked as offline on velocity

This commit is contained in:
ajgeiss0702
2022-10-20 13:48:31 -07:00
parent 11dcda49fd
commit d78c795288
4 changed files with 38 additions and 19 deletions
@@ -6,6 +6,8 @@ import us.ajg0702.queue.api.util.QueueLogger;
import us.ajg0702.utils.common.Config;
import us.ajg0702.utils.common.Messages;
import java.util.concurrent.ExecutorService;
public abstract class AjQueueAPI {
public static AjQueueAPI INSTANCE;
@@ -106,4 +108,6 @@ public abstract class AjQueueAPI {
* Tells ajQueue to shut down.
*/
public abstract void shutdown();
public abstract ExecutorService getServersUpdateExecutor();
}
@@ -13,6 +13,7 @@ import us.ajg0702.utils.common.Updater;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.concurrent.ExecutorService;
import java.util.regex.Pattern;
public class QueueMain extends AjQueueAPI {
@@ -123,6 +124,11 @@ public class QueueMain extends AjQueueAPI {
updater.shutdown();
}
@Override
public ExecutorService getServersUpdateExecutor() {
return taskManager.getServersUpdateExecutor();
}
private final File dataFolder;
@@ -52,16 +52,7 @@ public class BungeeServer implements AdaptedServer {
handle.ping((pp, error) -> {
if(error != null) {
long lastOnline = lastSuccessfullPing == null ? 0 : lastSuccessfullPing.getFetchedTime();
offlineTime = (int) Math.min(sent - lastOnline, Integer.MAX_VALUE);
lastOffline = sent;
future.completeExceptionally(error);
lastPing = null;
if(debug) logger.info("[pinger] [" + getName() + "] offline:", error);
return;
markOffline(debug, logger, future, sent, error);
}
offlineTime = 0;
@@ -80,6 +71,17 @@ public class BungeeServer implements AdaptedServer {
return future;
}
private void markOffline(boolean debug, QueueLogger logger, CompletableFuture<AdaptedServerPing> future, long sent, Throwable e) {
long lastOnline = lastSuccessfullPing == null ? 0 : lastSuccessfullPing.getFetchedTime();
offlineTime = (int) Math.min(sent - lastOnline, Integer.MAX_VALUE);
lastOffline = sent;
future.completeExceptionally(e);
lastPing = null;
if(debug) logger.info("[pinger] [" + getName() + "] offline:", e);
}
@Override
public Optional<AdaptedServerPing> getLastPing() {
return Optional.ofNullable(lastPing);
@@ -53,19 +53,12 @@ public class VelocityServer implements AdaptedServer {
if(debug) logger.info("[pinger] [" + getName() + "] sending ping");
serverPing.thenRunAsync(() -> {
System.out.println("thenRunAsync " + getName());
VelocityServerPing ping;
try {
ping = new VelocityServerPing(serverPing.get(), sent);
} catch (Throwable e) {
long lastOnline = lastSuccessfullPing == null ? 0 : lastSuccessfullPing.getFetchedTime();
offlineTime = (int) Math.min(sent - lastOnline, Integer.MAX_VALUE);
lastOffline = sent;
future.completeExceptionally(e);
lastPing = null;
if(debug) logger.info("[pinger] [" + getName() + "] offline:", e);
markOffline(debug, logger, future, sent, e);
return;
}
@@ -79,10 +72,24 @@ public class VelocityServer implements AdaptedServer {
future.complete(ping);
lastPing = ping;
}).exceptionally(e -> {
markOffline(debug, logger, future, sent, e);
return null;
});
return future;
}
private void markOffline(boolean debug, QueueLogger logger, CompletableFuture<AdaptedServerPing> future, long sent, Throwable e) {
long lastOnline = lastSuccessfullPing == null ? 0 : lastSuccessfullPing.getFetchedTime();
offlineTime = (int) Math.min(sent - lastOnline, Integer.MAX_VALUE);
lastOffline = sent;
future.completeExceptionally(e);
lastPing = null;
if(debug) logger.info("[pinger] [" + getName() + "] offline:", e);
}
@Override
public Optional<AdaptedServerPing> getLastPing() {
return Optional.ofNullable(lastPing);