mirror of
https://github.com/Geniusay/ChopperBot.git
synced 2026-05-23 21:00:18 +08:00
v1.0.3一些bug修改和一些模块重构优化
This commit is contained in:
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.example.common.ConfigFile;
|
||||
import org.example.common.FileType;
|
||||
import org.example.exception.FileCacheException;
|
||||
import org.example.util.JsonFileUtil;
|
||||
import org.example.util.TimeUtil;
|
||||
@@ -71,7 +72,7 @@ public class FileCache <T extends ConfigFile>{
|
||||
this.logger = LoggerFactory.getLogger("FileCache:"+this.configFile.getFileName());
|
||||
|
||||
this.autoSyncTime = autoSyncTime;
|
||||
if(!load(getFileName())){
|
||||
if(!load(getFullFilePath())){
|
||||
throw new FileCacheException("FileCache Init Error,please Check if your path is correct");
|
||||
}
|
||||
|
||||
@@ -240,7 +241,7 @@ public class FileCache <T extends ConfigFile>{
|
||||
*/
|
||||
public void forceSync(){
|
||||
if(writeByte.get()==0){
|
||||
logger.debug("未发生版本变化");
|
||||
logger.info("未发生版本变化");
|
||||
return;
|
||||
}
|
||||
clearWriteBytes();
|
||||
@@ -248,7 +249,7 @@ public class FileCache <T extends ConfigFile>{
|
||||
try {
|
||||
syncChannel.put(temp);
|
||||
} catch (InterruptedException e) {
|
||||
logger.debug("自动刷入失败");
|
||||
logger.error("自动刷入失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,25 +259,40 @@ public class FileCache <T extends ConfigFile>{
|
||||
*/
|
||||
private boolean sync(ConcurrentHashMap<String,Object> take){
|
||||
configFile.updateConfigTime(); //刷新配置文件刷入时间
|
||||
String dir = getFileName();
|
||||
String dir = getFullFilePath();
|
||||
configFile.onlyUpdateTime(take);
|
||||
File file = JsonFileUtil.writeJsonFile(dir, take);
|
||||
logger.debug("正在写入{}新版本",dir);
|
||||
return Objects.isNull(file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public BlockingQueue getFileChannel(){
|
||||
return this.syncChannel;
|
||||
}
|
||||
|
||||
public String getFileName(){
|
||||
public String getFullFilePath(){
|
||||
return Paths.get(this.configFile.getFilePath(), this.configFile.getFileName()).toString();
|
||||
}
|
||||
|
||||
public String getFilePath(){
|
||||
return this.configFile.getFilePath();
|
||||
}
|
||||
|
||||
public String getFileName(){
|
||||
return this.configFile.getFileName();
|
||||
}
|
||||
|
||||
public long getSyncTime(){
|
||||
return this.autoSyncTime;
|
||||
}
|
||||
|
||||
public FileType getFileType(){
|
||||
return this.configFile.getFileType();
|
||||
}
|
||||
|
||||
class SyncMan implements Runnable{
|
||||
|
||||
@Override
|
||||
@@ -300,7 +316,7 @@ public class FileCache <T extends ConfigFile>{
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof FileCache){
|
||||
if(((FileCache) obj).getFileName().equals(this.getFileName())){
|
||||
if(((FileCache) obj).getFullFilePath().equals(this.getFullFilePath())){
|
||||
return true;
|
||||
}else if(obj.hashCode() == this.hashCode()){
|
||||
return true;
|
||||
|
||||
@@ -75,6 +75,10 @@ public class FileCacheManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<FileCache> getRunnableFileCaches(){
|
||||
return this.fileCaches;
|
||||
}
|
||||
|
||||
class Watcher implements Runnable{
|
||||
|
||||
@Override
|
||||
@@ -85,7 +89,7 @@ public class FileCacheManager {
|
||||
BlockingQueue fileChannel = cache.getFileChannel();
|
||||
if(fileChannel.isEmpty()){
|
||||
if(cache.needAutoSync()){
|
||||
logger.debug("检测到需要强制刷新的文件 {}",cache.getFileName());
|
||||
logger.info("检测到需要强制刷新的文件 {}",cache.getFileName());
|
||||
autoSyncer.submit(new AutoSyncer(cache));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.example.init;
|
||||
|
||||
import org.example.cache.FileCacheManagerInstance;
|
||||
|
||||
/**
|
||||
* @author Genius
|
||||
* @date 2023/04/26 02:09
|
||||
**/
|
||||
public class FileCacheManagerInit implements InitMachine{
|
||||
|
||||
@Override
|
||||
public boolean init() {
|
||||
FileCacheManagerInstance.getInstance().start();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.example.pojo.configfile;
|
||||
|
||||
import org.example.common.ConfigFile;
|
||||
import org.example.common.FileType;
|
||||
import org.example.constpool.ConstPool;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -44,7 +45,7 @@ public class ModuleSrcConfigFile extends ConfigFile<Map<String, ModuleSrcConfigF
|
||||
public ModuleSrcConfigFile() {
|
||||
super("E:\\Project\\ChopperBot\\config\\"
|
||||
, "moduleConfig.json"
|
||||
, config);
|
||||
, config, FileType.CHOPPER_BOT);
|
||||
}
|
||||
|
||||
public Map<String,Object> packageConfig() {
|
||||
|
||||
20
FileModule/src/main/java/org/example/pojo/vo/ConfigVO.java
Normal file
20
FileModule/src/main/java/org/example/pojo/vo/ConfigVO.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.example.pojo.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Genius
|
||||
* @date 2023/04/26 02:07
|
||||
**/
|
||||
@Data
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ConfigVO {
|
||||
private String fileName;
|
||||
private String filePath;
|
||||
private String moduleType;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.example.service;
|
||||
|
||||
import org.example.pojo.vo.ConfigVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Genius
|
||||
* @date 2023/04/26 00:59
|
||||
**/
|
||||
|
||||
public interface FileService {
|
||||
|
||||
//获取所有模块
|
||||
List<String> getAllModule();
|
||||
|
||||
//获取所有文件
|
||||
List<ConfigVO> getAllConfigs();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.example.service.impl;
|
||||
|
||||
import org.example.cache.FileCache;
|
||||
import org.example.cache.FileCacheManager;
|
||||
import org.example.cache.FileCacheManagerInstance;
|
||||
import org.example.common.ConfigFile;
|
||||
import org.example.common.FileType;
|
||||
import org.example.pojo.vo.ConfigVO;
|
||||
import org.example.service.FileService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Genius
|
||||
* @date 2023/04/26 01:01
|
||||
**/
|
||||
|
||||
@Service
|
||||
public class FileServiceImpl implements FileService {
|
||||
|
||||
@Override
|
||||
public List<String> getAllModule() {
|
||||
List<String> moduleList = new ArrayList<>();
|
||||
for (FileType value : FileType.values()) {
|
||||
if(!value.equals(FileType.COMMON)){
|
||||
moduleList.add(value.getName());
|
||||
}
|
||||
}
|
||||
return moduleList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConfigVO> getAllConfigs() {
|
||||
List<ConfigVO> configVOList = new ArrayList<>();
|
||||
List<FileCache> runnableFileCaches = FileCacheManagerInstance.getInstance().getRunnableFileCaches();
|
||||
for (FileCache runnableFileCache : runnableFileCaches) {
|
||||
if (runnableFileCache.getFileType().equals(FileType.COMMON)) {
|
||||
continue;
|
||||
}
|
||||
configVOList.add(new ConfigVO(runnableFileCache.getFileName()
|
||||
,runnableFileCache.getFullFilePath()
|
||||
,runnableFileCache.getFileType().getName()));
|
||||
}
|
||||
return configVOList;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user