Add waiting for console processing to be done in shutdown, check to not queue stuff when console handler is shutdown

This commit is contained in:
Vankka 2023-10-06 22:42:31 +03:00
parent 812f459d93
commit e0bee7e2d8
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0

View File

@ -43,6 +43,7 @@ public class SingleConsoleHandler {
private final ConsoleConfig config;
private final Queue<LogEntry> queue = new LinkedBlockingQueue<>();
private Future<?> queueProcessingFuture;
private boolean shutdown = false;
// Editing
private final List<LogMessage> messageCache;
@ -163,8 +164,14 @@ public class SingleConsoleHandler {
}
public void shutdown() {
shutdown = true;
discordSRV.eventBus().unsubscribe(this);
queueProcessingFuture.cancel(false);
try {
queueProcessingFuture.wait(TimeUnit.SECONDS.toMillis(3));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
queue.clear();
if (messageCache != null) {
messageCache.clear();
@ -173,6 +180,9 @@ public class SingleConsoleHandler {
}
private void timeQueueProcess() {
if (shutdown) {
return;
}
this.queueProcessingFuture = discordSRV.scheduler().runLater(this::processQueue, 2, TimeUnit.SECONDS);
}