Search in sources :

Example 1 with ApplicationEventLoad

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);
    }
}
Also used : ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) ApplicationEventLoad(cn.jiangzeyin.common.spring.event.ApplicationEventLoad) ExtConfigBean(io.jpom.system.ExtConfigBean) ConfigBean(io.jpom.system.ConfigBean) IOException(java.io.IOException) File(java.io.File) FileUtil(cn.hutool.core.io.FileUtil) JsonFileUtil(io.jpom.util.JsonFileUtil) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent)

Aggregations

FileUtil (cn.hutool.core.io.FileUtil)1 ApplicationEventLoad (cn.jiangzeyin.common.spring.event.ApplicationEventLoad)1 ConfigBean (io.jpom.system.ConfigBean)1 ExtConfigBean (io.jpom.system.ExtConfigBean)1 JsonFileUtil (io.jpom.util.JsonFileUtil)1 File (java.io.File)1 IOException (java.io.IOException)1 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)1 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)1