mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-29 22:27:33 +00:00
[Change] Main, SpringCQApplication 移除仅与SpringCQ相关的Spring相关代码, 转移到SpringCQApplication;
[Change] FrameworkManager 调整"registerFramework"返回值, 调整"shutdownAllFramework"的过程;
This commit is contained in:
parent
6ec99dbf17
commit
a87735d9e0
@ -26,7 +26,6 @@ import org.apache.http.util.EntityUtils;
|
||||
import org.apache.tomcat.util.http.fileupload.util.Streams;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -36,7 +35,6 @@ import java.util.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Main {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(Main.class);
|
||||
@ -91,17 +89,29 @@ public class Main {
|
||||
|
||||
@Command
|
||||
public static void botMode(@Argument(name = "args", force = false) String argsStr) {
|
||||
FrameworkManager.registerFramework(new MiraiMain());
|
||||
try {
|
||||
FrameworkManager.registerFramework(new MiraiMain()).join();
|
||||
} catch (InterruptedException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Command
|
||||
public static void consoleMode() {
|
||||
FrameworkManager.registerFramework(new ConsoleMain());
|
||||
try {
|
||||
FrameworkManager.registerFramework(new ConsoleMain()).join();
|
||||
} catch (InterruptedException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Command
|
||||
public static void pluginMode(@Argument(name = "args", force = false) String argsStr) {
|
||||
FrameworkManager.registerFramework(new SpringCQApplication());
|
||||
try {
|
||||
FrameworkManager.registerFramework(new SpringCQApplication()).join();
|
||||
} catch (InterruptedException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Command
|
||||
|
@ -19,26 +19,30 @@ public final class FrameworkManager {
|
||||
.addShutdownHook(new Thread(FrameworkManager::shutdownAllFramework, "FrameworkManager-Shutdown"));
|
||||
}
|
||||
|
||||
public static void registerFramework(Framework framework) {
|
||||
public static Thread registerFramework(Framework framework) {
|
||||
FrameworkResources resources = new FrameworkResources(framework);
|
||||
resourcesMap.put(framework, resources);
|
||||
new Thread(resources.getFrameworkThreadGroup(),
|
||||
() -> FrameworkManager.runFramework(framework), "FrameworkThread-" + framework.getName()).start();
|
||||
Thread frameworkThread = new Thread(resources.getFrameworkThreadGroup(),
|
||||
() -> FrameworkManager.runFramework(framework), "FrameworkThread-" + framework.getName());
|
||||
|
||||
frameworkThread.start();
|
||||
return frameworkThread;
|
||||
}
|
||||
|
||||
public static void shutdownAllFramework() {
|
||||
for (Framework framework : resourcesMap.keySet()) {
|
||||
Logger frameworkLogger = resourcesMap.get(framework).getLogger();
|
||||
FrameworkResources frameworkResources = resourcesMap.get(framework);
|
||||
Logger frameworkLogger = frameworkResources.getLogger();
|
||||
try {
|
||||
frameworkLogger.info("正在关闭框架...");
|
||||
framework.close();
|
||||
frameworkLogger.info("框架已关闭.");
|
||||
frameworkResources.getFrameworkThreadGroup().interrupt();
|
||||
resourcesMap.remove(framework);
|
||||
} catch(Throwable e) {
|
||||
frameworkLogger.error("退出框架时发生异常", e);
|
||||
}
|
||||
}
|
||||
frameworkRootGroup.interrupt();
|
||||
}
|
||||
|
||||
private static void runFramework(Framework framework) {
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.lamgc.cgj.bot.framework.coolq;
|
||||
|
||||
import net.lamgc.cgj.Main;
|
||||
import net.lamgc.cgj.bot.boot.BotGlobal;
|
||||
import net.lamgc.cgj.bot.framework.Framework;
|
||||
import net.lamgc.cgj.bot.framework.FrameworkManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.ContextStoppedEvent;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringCQApplication implements Framework {
|
||||
|
||||
private Logger log;
|
||||
@ -25,7 +26,7 @@ public class SpringCQApplication implements Framework {
|
||||
|
||||
public void run() {
|
||||
log.info("酷Q机器人根目录: {}", BotGlobal.getGlobal().getDataStoreDir().getPath());
|
||||
ConfigurableApplicationContext context = SpringApplication.run(Main.class);
|
||||
ConfigurableApplicationContext context = SpringApplication.run(SpringCQApplication.class);
|
||||
registerShutdownHook(context);
|
||||
try {
|
||||
synchronized (quitLock) {
|
||||
|
Loading…
Reference in New Issue
Block a user