You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
7.5 KiB
194 lines
7.5 KiB
package com.fanruan.boot; |
|
|
|
import com.fanruan.carina.Carina; |
|
import com.fanruan.carina.annotions.FineComponent; |
|
import com.fanruan.carina.annotions.Start; |
|
import com.fanruan.carina.annotions.Stop; |
|
import com.fanruan.boot.key.StartupArgsShell; |
|
import com.fanruan.product.BuildContext; |
|
import com.fr.base.OptimizeUtil; |
|
import com.fr.config.dao.DaoSelectorFactory; |
|
import com.fr.config.dao.PropertiesConstants; |
|
import com.fr.decision.webservice.v10.encryption.EncryptionConstants; |
|
import com.fr.design.DesignerEnvManager; |
|
import com.fr.design.RestartHelper; |
|
import com.fr.design.dialog.TipDialog; |
|
import com.fr.design.env.DesignerWorkspaceInfo; |
|
import com.fr.design.env.DesignerWorkspaceType; |
|
import com.fr.design.file.TemplateResourceManager; |
|
import com.fr.design.fun.impl.GlobalListenerProviderManager; |
|
import com.fr.design.i18n.Toolkit; |
|
import com.fr.design.mainframe.messagecollect.StartErrorMessageCollector; |
|
import com.fr.design.mainframe.messagecollect.StartupMessageCollector; |
|
import com.fr.design.mainframe.messagecollect.entity.DesignerErrorMessage; |
|
import com.fr.design.utils.DesignUtils; |
|
import com.fr.env.utils.WorkspaceUtils; |
|
import com.fr.event.Event; |
|
import com.fr.event.EventDispatcher; |
|
import com.fr.event.Listener; |
|
import com.fr.event.Null; |
|
import com.fr.exit.DesignerExiter; |
|
import com.fr.file.TmpFileUtils; |
|
import com.fr.general.CloudCenter; |
|
import com.fr.general.GeneralContext; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.record.analyzer.EnableMetrics; |
|
import com.fr.record.analyzer.Metrics; |
|
import com.fr.stable.ArrayUtils; |
|
import com.fr.stable.StableUtils; |
|
import com.fr.stable.StringUtils; |
|
import com.fr.stable.project.ProjectConstants; |
|
import com.fr.start.DesignerProcessType; |
|
import com.fr.start.ServerStarter; |
|
import com.fr.start.common.DesignerStartupContext; |
|
import com.fr.start.event.LazyStartupEvent; |
|
import com.fr.start.module.StartupArgs; |
|
import com.fr.start.preload.PreLoadService; |
|
import com.fr.start.server.FineEmbedServer; |
|
import com.fr.third.guava.base.Stopwatch; |
|
import com.fr.value.NotNullLazyValue; |
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import java.io.File; |
|
import java.util.concurrent.TimeUnit; |
|
|
|
/** |
|
* 设计器启动检查模块 |
|
* <p>负责设计器启动的前置清理与检查,是一切设计器模块的起点</p> |
|
* |
|
* @author Destiny.Lin |
|
* @since 11.0 |
|
* Created on 2024/5/24 |
|
*/ |
|
@EnableMetrics |
|
@FineComponent(name = "design_start_up") |
|
public class DesignerStartupComponent { |
|
|
|
private NotNullLazyValue<StartupArgs> startupArgsValue = new NotNullLazyValue<StartupArgs>() { |
|
@NotNull |
|
@Override |
|
protected StartupArgs compute() { |
|
return Carina.getApplicationContext().singleton(StartupArgsShell.class).get(); |
|
} |
|
}; |
|
|
|
/** |
|
* start准备 |
|
*/ |
|
public void beforeAllStart() { |
|
|
|
BuildContext.setBuildFilePath("/com/fr/stable/build.properties"); |
|
|
|
registerDaoSelector(); |
|
|
|
Stopwatch beforeWatch = Stopwatch.createStarted(); |
|
PreLoadService.getInstance().waitForCommon(); |
|
FineLoggerFactory.getLogger().debug( "DesignerStartup cost {} ms to wait load", beforeWatch.elapsed(TimeUnit.MILLISECONDS)); |
|
|
|
if (DesignUtils.isStarted()) { |
|
// 如果端口被占用了 说明程序已经运行了一次,也就是说,已经建立一个监听服务器,现在只要给服务器发送命令就好了 |
|
final String[] args = startupArgsValue.getValue().get(); |
|
if (ArrayUtils.isNotEmpty(args)) { |
|
DesignUtils.clientSend(args); |
|
} |
|
FineLoggerFactory.getLogger().info("The Designer Has Been Started"); |
|
if (args.length == 0) { |
|
TipDialog dialog = new TipDialog(null, |
|
DesignerProcessType.INSTANCE.obtain(), |
|
Toolkit.i18nText("Fine-Design_Last_Designer_Process_Not_Exist"), |
|
Toolkit.i18nText("Fine-Design_End_Occupied_Process"), |
|
Toolkit.i18nText("Fine-Design_Basic_Cancel")) { |
|
@Override |
|
protected void endEvent() { |
|
dispose(); |
|
DesignUtils.clientSend(new String[]{"end"}); |
|
RestartHelper.restart(); |
|
} |
|
|
|
@Override |
|
protected void cancelEvent() { |
|
dispose(); |
|
} |
|
}; |
|
dialog.setVisible(true); |
|
StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.DESIGNER_PROCESS_OCCUPIED.getId(), |
|
DesignerErrorMessage.DESIGNER_PROCESS_OCCUPIED.getMessage(), |
|
StringUtils.EMPTY); |
|
FineLoggerFactory.getLogger().error( "{}: {}", DesignerErrorMessage.DESIGNER_PROCESS_OCCUPIED.getId(), DesignerErrorMessage.DESIGNER_PROCESS_OCCUPIED.getMessage()); |
|
} |
|
DesignerExiter.getInstance().execute(); |
|
} |
|
|
|
} |
|
|
|
/** |
|
* start |
|
*/ |
|
@Start |
|
@Metrics |
|
public void start() { |
|
beforeAllStart(); |
|
|
|
//清空临时文件 |
|
TmpFileUtils.cleanUpInnerTmpFiles(); |
|
RestartHelper.deleteRecordFilesWhenStart(); |
|
|
|
CloudCenter.getInstance(); |
|
|
|
// 创建监听服务 |
|
DesignUtils.createListeningServer(DesignUtils.getPort(), startFileSuffix()); |
|
|
|
// 在插件引擎模块起来前 初始化下插件接口监听 |
|
TemplateResourceManager.getResource(); |
|
|
|
initLanguage(); |
|
} |
|
|
|
private void registerDaoSelector() { |
|
// 注入设计器db cache 是否可用 |
|
DesignerWorkspaceInfo info = WorkspaceUtils.getWorkspaceInfo(); |
|
if (info.getType() == DesignerWorkspaceType.Remote) { |
|
DaoSelectorFactory.registerDaoSelector(() -> false); |
|
} else { |
|
String webInfPath = WorkspaceUtils.getWorkspaceInfo().getPath(); |
|
String dbConfigPath = StableUtils.pathJoin(webInfPath, ProjectConstants.CONFIG_DIRECTORY, |
|
EncryptionConstants.PROPERTY_NAME); |
|
String entityPath = generatePath(webInfPath, PropertiesConstants.ENTITY_PROP); |
|
String xmlEntityPath = generatePath(webInfPath, PropertiesConstants.XML_ENTITY_PROP); |
|
String classNamePath = generatePath(webInfPath, PropertiesConstants.CLASS_NAME_PROP); |
|
// 校验 平台迁移文件/缓存文件 |
|
boolean existPropCache = new File(entityPath).exists() && new File(xmlEntityPath).exists() && new File(classNamePath).exists(); |
|
DaoSelectorFactory.registerDaoSelector(() -> DesignerEnvManager.getEnvManager().isPropertiesUsable() |
|
&& OptimizeUtil.isOpen() |
|
&& existPropCache |
|
// demo启动时 前后目录可能会不一致 造成读取缓存失败 |
|
&& !startupArgsValue.getValue().isDemo() |
|
&& !new File(dbConfigPath).exists()); |
|
|
|
} |
|
} |
|
|
|
private String generatePath(String webInfPath, String name) { |
|
return StableUtils.pathJoin(webInfPath, ProjectConstants.EMBED_DB_DIRECTORY, |
|
ProjectConstants.PROPERTIES_CACHE_FOR_CONFIG, name); |
|
} |
|
|
|
|
|
/** |
|
* stop |
|
*/ |
|
@Stop |
|
public void stop() { |
|
// void |
|
} |
|
|
|
private void initLanguage() { |
|
//这两句的位置不能随便调换,因为会影响语言切换的问题 |
|
GeneralContext.setLocale(DesignerEnvManager.getEnvManager(false).getLanguage()); |
|
} |
|
|
|
private String[] startFileSuffix() { |
|
|
|
return new String[]{".cpt", ".xls", ".xlsx", ".frm", ".form", ".cht", ".chart"}; |
|
} |
|
}
|
|
|