![JAR search and dependency download from the Maven repository](/logo.png)
top.wboost.common.system.code.CodeMessageManager Maven / Gradle / Ivy
package top.wboost.common.system.code;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import top.wboost.common.base.core.ExecutorsDaemon;
import top.wboost.common.log.entity.Logger;
import top.wboost.common.log.util.LoggerUtil;
import top.wboost.common.util.StringUtil;
import top.wboost.common.utils.web.utils.PropertiesUtil;
/**
* 返回码对应信息管理器
* @className CodeMessageManager
* @author jwSun
* @date 2017年8月1日 下午4:35:52
* @version 1.0.0
*/
public class CodeMessageManager implements ApplicationListener {
private static Logger log = LoggerUtil.getLogger(CodeMessageManager.class);
private final static String systemMessagePath = "classpath*:sys/properties/system-message-code_zh_CN.properties";
private final String messagePath;
private final String fileName;
private final String language;
private String realMessagePath;
//不需要加载说明
public static final int NO_MESSAGE_CODE = 0;
//默认重新读取配置文件时间(分钟)
private static final long defaultLoadTime = 30;
/**更新配置文件信息定时器**/
private ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1,
ExecutorsDaemon.getDaemonThreadFactory("codeMessageManagerPool"));
/**key:code,value:message**/
private static ConcurrentHashMap codeMessageMap = new ConcurrentHashMap();
static {
log.debug("init system code and message...");
for (SystemCode businessCode : SystemCode.values()) {
String message = PropertiesUtil.getProperty(String.valueOf(businessCode.getCode()), systemMessagePath);
codeMessageMap.put(businessCode.getCode(), message == null ? "" : message);
}
log.debug("init system code and message end");
}
public CodeMessageManager(String messagePath, String fileName) {
this(messagePath, fileName, "zh_CN", defaultLoadTime);
}
public CodeMessageManager(String messagePath, String fileName, String language) {
this(messagePath, fileName, language, defaultLoadTime);
}
public CodeMessageManager(String messagePath, String fileName, String language, long loadTime) {
super();
this.messagePath = messagePath;
this.fileName = fileName;
this.language = language;
this.realMessagePath = messagePath + "/" + fileName + "_" + language + ".properties";
//Executors.defaultThreadFactory();
executorService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
loadMessage();
}
}, 0, loadTime, TimeUnit.MINUTES);
}
/**
* 读取配置文件信息
*/
private void loadMessage() {
log.debug("init code and message...");
Properties messageProperties = PropertiesUtil.loadProperties(this.realMessagePath);
for (Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy