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.Config;
import us.ajg0702.utils.common.Messages; import us.ajg0702.utils.common.Messages;
import java.util.concurrent.ExecutorService;
public abstract class AjQueueAPI { public abstract class AjQueueAPI {
public static AjQueueAPI INSTANCE; public static AjQueueAPI INSTANCE;
@@ -106,4 +108,6 @@ public abstract class AjQueueAPI {
* Tells ajQueue to shut down. * Tells ajQueue to shut down.
*/ */
public abstract void shutdown(); public abstract void shutdown();
public abstract ExecutorService getServersUpdateExecutor();
} }
@@ -13,6 +13,7 @@ import us.ajg0702.utils.common.Updater;
import java.io.File; import java.io.File;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.concurrent.ExecutorService;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class QueueMain extends AjQueueAPI { public class QueueMain extends AjQueueAPI {
@@ -123,6 +124,11 @@ public class QueueMain extends AjQueueAPI {
updater.shutdown(); updater.shutdown();
} }
@Override
public ExecutorService getServersUpdateExecutor() {
return taskManager.getServersUpdateExecutor();
}
private final File dataFolder; private final File dataFolder;
@@ -52,16 +52,7 @@ public class BungeeServer implements AdaptedServer {
handle.ping((pp, error) -> { handle.ping((pp, error) -> {
if(error != null) { if(error != null) {
markOffline(debug, logger, future, sent, error);
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;
} }
offlineTime = 0; offlineTime = 0;
@@ -80,6 +71,17 @@ public class BungeeServer implements AdaptedServer {
return future; 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 @Override
public Optional<AdaptedServerPing> getLastPing() { public Optional<AdaptedServerPing> getLastPing() {
return Optional.ofNullable(lastPing); return Optional.ofNullable(lastPing);
@@ -53,19 +53,12 @@ public class VelocityServer implements AdaptedServer {
if(debug) logger.info("[pinger] [" + getName() + "] sending ping"); if(debug) logger.info("[pinger] [" + getName() + "] sending ping");
serverPing.thenRunAsync(() -> { serverPing.thenRunAsync(() -> {
System.out.println("thenRunAsync " + getName());
VelocityServerPing ping; VelocityServerPing ping;
try { try {
ping = new VelocityServerPing(serverPing.get(), sent); ping = new VelocityServerPing(serverPing.get(), sent);
} catch (Throwable e) { } catch (Throwable e) {
markOffline(debug, logger, future, sent, 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);
return; return;
} }
@@ -79,10 +72,24 @@ public class VelocityServer implements AdaptedServer {
future.complete(ping); future.complete(ping);
lastPing = ping; lastPing = ping;
}).exceptionally(e -> {
markOffline(debug, logger, future, sent, e);
return null;
}); });
return future; 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 @Override
public Optional<AdaptedServerPing> getLastPing() { public Optional<AdaptedServerPing> getLastPing() {
return Optional.ofNullable(lastPing); return Optional.ofNullable(lastPing);