mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-07-02 05:17:26 +00:00
[Fix] BotEventHandler, ImageCacheStore 增加ShutdownHook用于关闭线程池, 解决线程池阻塞关闭过程的问题; [Change] BotEventHandler 调整'match(String)'方法; [Change] BotAdminCommandProcess 调整'savePushList()'方法对文件创建失败的行为;
57 lines
1.6 KiB
Java
57 lines
1.6 KiB
Java
package net.lamgc.cgj.bot.boot;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import redis.clients.jedis.JedisPool;
|
|
|
|
import java.io.File;
|
|
import java.net.URI;
|
|
|
|
public final class BotGlobal {
|
|
|
|
private final static BotGlobal instance = new BotGlobal();
|
|
|
|
public static BotGlobal getGlobal() {
|
|
if(instance == null) {
|
|
throw new IllegalStateException("");
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
private final static Logger log = LoggerFactory.getLogger(BotGlobal.class);
|
|
|
|
private final URI redisUri;
|
|
|
|
/**
|
|
* 所有缓存共用的JedisPool
|
|
*/
|
|
private final JedisPool redisServer;
|
|
|
|
private final File dataStoreDir;
|
|
|
|
private BotGlobal() {
|
|
this.redisUri = URI.create("redis://" + System.getProperty("cgj.redisAddress"));
|
|
this.redisServer = new JedisPool(
|
|
getRedisUri().getHost(),
|
|
getRedisUri().getPort() == -1 ? 6379 : getRedisUri().getPort());
|
|
String dataStoreDirPath = System.getProperty("cgj.botDataDir");
|
|
this.dataStoreDir = new File((!dataStoreDirPath.endsWith("/") || !dataStoreDirPath.endsWith("\\")) ?
|
|
dataStoreDirPath + System.getProperty("file.separator") : dataStoreDirPath);
|
|
}
|
|
|
|
public URI getRedisUri() {
|
|
return redisUri;
|
|
}
|
|
|
|
public File getDataStoreDir() {
|
|
if(!dataStoreDir.exists() && !dataStoreDir.mkdirs()) {
|
|
log.error("DataStoreDir 创建失败, 数据存储可能失效!");
|
|
}
|
|
return dataStoreDir;
|
|
}
|
|
|
|
public JedisPool getRedisServer() {
|
|
return redisServer;
|
|
}
|
|
}
|