use of cn.jiangzeyin.common.spring.event.ApplicationEventLoad in project Jpom by dromara.
the class JpomApplicationEvent method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEvent event) {
// 启动最后的预加载
if (event instanceof ApplicationReadyEvent) {
//
checkPath();
JpomManifest jpomManifest = JpomManifest.getInstance();
ConfigBean instance = ConfigBean.getInstance();
// 清理旧进程新文件
File dataDir = FileUtil.file(instance.getDataPath());
List<File> files = FileUtil.loopFiles(dataDir, 1, pathname -> pathname.getName().startsWith("pid."));
files.forEach(FileUtil::del);
try {
this.lockFile(jpomManifest.getPid());
} catch (IOException e) {
DefaultSystemLog.getLog().error("lockFile", e);
}
// 写入Jpom 信息 、 写入全局信息
File appJpomFile = instance.getApplicationJpomInfo(JpomApplication.getAppType());
FileUtil.writeString(jpomManifest.toString(), appJpomFile, CharsetUtil.CHARSET_UTF_8);
// 检查更新文件
checkUpdate();
//
if (ApplicationEventLoad.class.isAssignableFrom(JpomApplication.getAppClass())) {
ApplicationEventLoad eventLoad = (ApplicationEventLoad) SpringUtil.getBean(JpomApplication.getAppClass());
eventLoad.applicationLoad();
}
Console.log("Jpom Successful start preparation. start loading module");
} else if (event instanceof ContextClosedEvent) {
// 应用关闭
this.unLockFile();
//
ConfigBean instance = ConfigBean.getInstance();
FileUtil.del(instance.getPidFile());
//
File appJpomFile = instance.getApplicationJpomInfo(JpomApplication.getAppType());
FileUtil.del(appJpomFile);
}
}
Aggregations