mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-19 22:05:11 +00:00
shutdown logic
This commit is contained in:
parent
c5c4d0bc05
commit
bd7ec574fb
7 changed files with 44 additions and 34 deletions
|
|
@ -159,20 +159,17 @@ public class DMCC {
|
|||
EventManager.clear();
|
||||
|
||||
// Shutdown OkHttpClient
|
||||
try (ExecutorService executorService = OK_HTTP_CLIENT.dispatcher().executorService();
|
||||
try (ExecutorService executor = OK_HTTP_CLIENT.dispatcher().executorService();
|
||||
Cache ignored1 = OK_HTTP_CLIENT.cache()) {
|
||||
executorService.shutdown();
|
||||
try {
|
||||
if (ConfigManager.getBoolean("shutdown.graceful_shutdown")) {
|
||||
// Allow up to 10 minutes for ongoing requests to complete
|
||||
boolean ignored2 = executorService.awaitTermination(10, TimeUnit.MINUTES);
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
} finally {
|
||||
executor.shutdown();
|
||||
if (ConfigManager.getBoolean("shutdown.graceful_shutdown")) {
|
||||
// Allow up to 10 minutes for ongoing requests to complete
|
||||
boolean ignored2 = executor.awaitTermination(10, TimeUnit.MINUTES);
|
||||
} else {
|
||||
// Allow up to 5 seconds for ongoing requests to complete
|
||||
boolean ignored2 = executorService.awaitTermination(5, TimeUnit.SECONDS);
|
||||
boolean ignored2 = executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
}
|
||||
executorService.shutdownNow();
|
||||
executor.shutdownNow();
|
||||
|
||||
OK_HTTP_CLIENT.connectionPool().evictAll();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.xujiayao.discord_mc_chat.client;
|
||||
|
||||
import com.xujiayao.discord_mc_chat.utils.config.ConfigManager;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -43,13 +45,16 @@ public class ClientDMCC {
|
|||
|
||||
executor.shutdown();
|
||||
try {
|
||||
if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
|
||||
executor.shutdownNow();
|
||||
if (ConfigManager.getBoolean("shutdown.graceful_shutdown")) {
|
||||
// Allow up to 10 minutes for ongoing requests to complete
|
||||
boolean ignored = executor.awaitTermination(10, TimeUnit.MINUTES);
|
||||
} else {
|
||||
// Allow up to 5 seconds for ongoing requests to complete
|
||||
boolean ignored = executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
executor.shutdownNow();
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
executor.shutdownNow();
|
||||
|
||||
LOGGER.info("DMCC Client component shut down.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ public class NettyServer {
|
|||
}
|
||||
|
||||
public int start() {
|
||||
// The bound port would be returned here after starting the server.
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.xujiayao.discord_mc_chat.server;
|
||||
|
||||
import com.xujiayao.discord_mc_chat.server.discord.DiscordManager;
|
||||
import com.xujiayao.discord_mc_chat.utils.config.ConfigManager;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
|
@ -69,22 +70,20 @@ public class ServerDMCC {
|
|||
nettyServer.stop();
|
||||
}
|
||||
|
||||
try {
|
||||
DiscordManager.shutdown();
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error("Discord manager shutdown was interrupted.", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
DiscordManager.shutdown();
|
||||
|
||||
executor.shutdown();
|
||||
try {
|
||||
if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
|
||||
executor.shutdownNow();
|
||||
if (ConfigManager.getBoolean("shutdown.graceful_shutdown")) {
|
||||
// Allow up to 10 minutes for ongoing requests to complete
|
||||
boolean ignored = executor.awaitTermination(10, TimeUnit.MINUTES);
|
||||
} else {
|
||||
// Allow up to 5 seconds for ongoing requests to complete
|
||||
boolean ignored = executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
executor.shutdownNow();
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
executor.shutdownNow();
|
||||
|
||||
LOGGER.info("DMCC Server component shut down.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import net.dv8tion.jda.api.requests.GatewayIntent;
|
|||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static com.xujiayao.discord_mc_chat.Constants.LOGGER;
|
||||
|
||||
|
|
@ -55,15 +56,20 @@ public class DiscordManager {
|
|||
/**
|
||||
* Shuts down the Discord bot.
|
||||
*/
|
||||
public static void shutdown() throws InterruptedException {
|
||||
public static void shutdown() {
|
||||
if (jda != null) {
|
||||
jda.shutdown();
|
||||
|
||||
if (!jda.awaitShutdown(Duration.ofSeconds(5))) {
|
||||
if (!ConfigManager.getBoolean("shutdown.graceful_shutdown")) {
|
||||
jda.shutdownNow();
|
||||
try {
|
||||
if (ConfigManager.getBoolean("shutdown.graceful_shutdown")) {
|
||||
// Allow up to 10 minutes for ongoing requests to complete
|
||||
boolean ignored = jda.awaitShutdown(Duration.ofMinutes(10));
|
||||
} else {
|
||||
// Allow up to 5 seconds for ongoing requests to complete
|
||||
boolean ignored = jda.awaitShutdown(Duration.ofSeconds(5));
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
jda.shutdownNow();
|
||||
|
||||
LOGGER.info("Discord bot shutdown successfully!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,5 @@ commands:
|
|||
failure: "DMCC reload failed. Reason: {}"
|
||||
shutdown:
|
||||
description: "Shut down the Standalone DMCC application"
|
||||
shutting_down: "Shutting down the Standalone DMCC application... Goodbye!"
|
||||
success: "DMCC shut down successfully. Goodbye!"
|
||||
failure: "DMCC shutdown failed. Reason: {}"
|
||||
|
|
|
|||
|
|
@ -19,4 +19,5 @@ commands:
|
|||
failure: "DMCC 重新加载失败。原因:{}"
|
||||
shutdown:
|
||||
description: "关闭独立 DMCC 应用程序"
|
||||
shutting_down: "正在关闭独立 DMCC 应用程序... 再见!"
|
||||
success: "DMCC 关闭成功。再见!"
|
||||
failure: "DMCC 关闭失败。原因:{}"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue