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