mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2026-10-28 09:44:56 +00:00
Improved shutdown handling
This commit is contained in:
1 parent
ccb7d5d85c
commit
a95c0f93b0
5 files changed
+28
-12
No files matched your search
@@ -1,5 +1,7 @@
|
||||
package net.coreprotect.command;
|
||||
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
@@ -59,7 +61,8 @@ public class ReloadCommand {
|
||||
}
|
||||
|
||||
static synchronized boolean performReload(CommandSender player) throws InterruptedException {
|
||||
boolean resumePersistence = !Consumer.isDatabaseReloadPaused();
|
||||
final boolean resumePersistenceAfterCancellation = !Consumer.isDatabaseReloadPaused();
|
||||
boolean resumePersistence = resumePersistenceAfterCancellation;
|
||||
Consumer.OperationStartResult startResult = Consumer.beginDatabaseReload();
|
||||
if (startResult != Consumer.OperationStartResult.STARTED) {
|
||||
Phrase phrase = startResult == Consumer.OperationStartResult.PURGE_RUNNING ? Phrase.PURGE_IN_PROGRESS
|
||||
@@ -80,7 +83,16 @@ public class ReloadCommand {
|
||||
return false;
|
||||
}
|
||||
resumePersistence = false;
|
||||
if (!ConfigHandler.performInitialization(false)) {
|
||||
boolean initialized;
|
||||
try {
|
||||
initialized = ConfigHandler.performInitialization(false);
|
||||
}
|
||||
catch (CancellationException e) {
|
||||
resumePersistence = resumePersistenceAfterCancellation;
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.RELOAD_FAILED));
|
||||
return false;
|
||||
}
|
||||
if (!initialized) {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.RELOAD_FAILED));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -700,7 +700,7 @@ public class ConfigHandler extends Queue {
|
||||
ListenerHandler.registerNetworking(); // Register channels for networking API
|
||||
}
|
||||
} catch (CancellationException e) {
|
||||
return false;
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
ErrorReporter.report(e);
|
||||
return false;
|
||||
|
||||
@@ -245,19 +245,19 @@ public class Consumer extends Process implements Runnable, Thread.UncaughtExcept
|
||||
|
||||
public static void endDatabaseReload(boolean resumePersistence) {
|
||||
try {
|
||||
if (databaseLifecycle.isWriteLockedByCurrentThread()) {
|
||||
databaseLifecycle.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
synchronized (rollbackPurgeGate) {
|
||||
databaseReloadRunning = false;
|
||||
if (resumePersistence) {
|
||||
databaseReloadPaused = false;
|
||||
if (!ConfigHandler.converterRunning) {
|
||||
isPaused = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (databaseLifecycle.isWriteLockedByCurrentThread()) {
|
||||
databaseLifecycle.writeLock().unlock();
|
||||
databaseReloadRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class ShutdownService {
|
||||
|
||||
long shutdownTime = System.currentTimeMillis();
|
||||
PurgeCommand.cancelForShutdown();
|
||||
waitForPurgeCancellation(shutdownTime);
|
||||
waitForMaintenanceCompletion(shutdownTime);
|
||||
ConfigHandler.serverRunning = false;
|
||||
long nextAlertTime = System.currentTimeMillis() + ALERT_INTERVAL_MS;
|
||||
|
||||
@@ -129,8 +129,9 @@ public class ShutdownService {
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitForPurgeCancellation(long shutdownTime) throws InterruptedException {
|
||||
while (ConfigHandler.purgeRunning || Consumer.isBackgroundPurgeRunning() || PurgeCommand.isPurgeWorkerRunning()) {
|
||||
static void waitForMaintenanceCompletion(long shutdownTime) throws InterruptedException {
|
||||
while (ConfigHandler.purgeRunning || Consumer.isBackgroundPurgeRunning() || PurgeCommand.isPurgeWorkerRunning()
|
||||
|| Consumer.isDatabaseReloadRunning()) {
|
||||
if ((System.currentTimeMillis() - shutdownTime) >= MAX_SHUTDOWN_WAIT_MS) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -252,6 +252,9 @@ public final class EntitySpawnTracking {
|
||||
return true;
|
||||
});
|
||||
if (!registered) {
|
||||
if (expectedVerification != null) {
|
||||
pendingIdentityVerifications.remove(uuid, expectedVerification);
|
||||
}
|
||||
return;
|
||||
}
|
||||
CoreProtect plugin = CoreProtect.getInstance();
|
||||
|
||||
Reference in new issue
Block a user