From 6442a43639cadc24dde7d7d1828fdf8472dae83e Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 30 Dec 2020 15:44:29 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-6380=20=E8=A7=A3=E8=80=A6=20=E4=BB=85?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=8F=92=E4=BB=B6afterRun=E7=94=9F=E5=91=BD?= =?UTF-8?q?=E5=91=A8=E6=9C=9F=20+=20=E9=87=8D=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...er.java => PluginClassRefreshManager.java} | 38 +++---------- .../design/file/HistoryTemplateListCache.java | 57 ++++++++++--------- .../start/module/DesignerInitActivator.java | 4 +- 3 files changed, 38 insertions(+), 61 deletions(-) rename designer-base/src/main/java/com/fr/design/{PluginRefreshManager.java => PluginClassRefreshManager.java} (65%) diff --git a/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java b/designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java similarity index 65% rename from designer-base/src/main/java/com/fr/design/PluginRefreshManager.java rename to designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java index 6ccf1f1906..22f791f4fd 100644 --- a/designer-base/src/main/java/com/fr/design/PluginRefreshManager.java +++ b/designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java @@ -17,47 +17,30 @@ import java.util.Set; * @version 10.0 * Created by hades on 2020/12/17 */ -public class PluginRefreshManager { +public class PluginClassRefreshManager { - private static final PluginRefreshManager INSTANCE = new PluginRefreshManager(); + private static final PluginClassRefreshManager INSTANCE = new PluginClassRefreshManager(); private final Set context = new HashSet<>(); private final PluginEventListener pluginAfterRunEventListener = new PluginEventListener() { @Override public void on(PluginEvent event) { - boolean mustReload = false; // 兼容之前版本特性 for (String tag : context) { if (event.getContext().contain(tag)) { - mustReload = true; + HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(); break; } } // 重新载入模板xml内容 到 Workbook/Form对象中 - HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(mustReload); - } - }; - - private final PluginEventListener pluginBeforeStopEventListener = new PluginEventListener() { - @Override - public void on(PluginEvent event) { - boolean canCal = true; - for (String tag : context) { - if (event.getContext().contain(tag)) { - canCal = false; - break; - } - } - if (canCal) { - HistoryTemplateListCache.getInstance().calNeedReloadTemplate(event.getContext()); - } + HistoryTemplateListCache.getInstance().reloadAllEditingTemplateByPlugin(event.getContext()); } }; - public static PluginRefreshManager getInstance() { + public static PluginClassRefreshManager getInstance() { return INSTANCE; } @@ -66,7 +49,7 @@ public class PluginRefreshManager { context.add(HyperlinkProvider.XML_TAG); } - private PluginRefreshManager() { + private PluginClassRefreshManager() { PluginListenerRegistration.getInstance().listen(PluginEventType.BeforeAllActive, new PluginEventListener() { @Override public void on(PluginEvent event) { @@ -78,25 +61,18 @@ public class PluginRefreshManager { public void on(PluginEvent event) { addPluginListener(); if (DesignerLaunchStatus.getStatus() != DesignerLaunchStatus.WORKSPACE_INIT_COMPLETE) { - HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(true); + HistoryTemplateListCache.getInstance().reloadAllEditingTemplate(); } } }); } - public void registerItem(String xmlTag) { - context.add(xmlTag); - } - public void removePluginListener() { PluginListenerRegistration.getInstance().stopListen(this.pluginAfterRunEventListener); - PluginListenerRegistration.getInstance().stopListen(this.pluginBeforeStopEventListener); - } public void addPluginListener() { PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, this.pluginAfterRunEventListener); - PluginListenerRegistration.getInstance().listen(PluginEventType.BeforeStop, this.pluginBeforeStopEventListener); } } diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index 88f64a4d5d..5184c7d0d5 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -46,8 +46,6 @@ public class HistoryTemplateListCache implements CallbackEvent { private List> historyList; private JTemplate editingTemplate; - private Map templateNeedReloadMap = new HashMap<>(); - public static HistoryTemplateListCache getInstance() { return Holder.INSTANCE; } @@ -78,9 +76,6 @@ public class HistoryTemplateListCache implements CallbackEvent { selected.fireJTemplateClosed(); selected.stopEditing(); try { - if (!templateNeedReloadMap.isEmpty()) { - templateNeedReloadMap.remove(selected.getEditingFILE().getName()); - } historyList.remove(contains(selected)); selected.getEditingFILE().closeTemplate(); FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Closed_Warn_Text", selected.getEditingFILE().getName())); @@ -412,7 +407,7 @@ public class HistoryTemplateListCache implements CallbackEvent { */ @Deprecated public void reloadCurrentTemplate() { - reloadAllEditingTemplate(true); + reloadAllEditingTemplate(); } /** @@ -430,15 +425,14 @@ public class HistoryTemplateListCache implements CallbackEvent { /** * 插件安装后/启用 重新加载模板资源 */ - public void reloadAllEditingTemplate(boolean mustReload) { + private void _reloadAllEditingTemplate(PluginContext context) { FineLoggerFactory.getLogger().info("Plugin env change reload all template started"); long start = System.currentTimeMillis(); int size = historyList.size(); for (int i = 0; i < size; i++) { JTemplate template = historyList.get(i); FILE file = template.getEditingFILE(); - Boolean value = templateNeedReloadMap.get(file.getName()); - boolean needReload = mustReload || (value != null && value); + boolean needReload = context == null || needReloadTemplate(context, template); if (needReload) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @@ -455,31 +449,38 @@ public class HistoryTemplateListCache implements CallbackEvent { } } } - templateNeedReloadMap.clear(); FineLoggerFactory.getLogger().info("Plugin env change reload all template ended"); FineLoggerFactory.getLogger().info("Reload all template spend: {} ms", (System.currentTimeMillis() - start)); } - public void calNeedReloadTemplate(PluginContext context) { - for (JTemplate template : historyList) { - BaseBook baseBook = template.getTarget(); - if (baseBook != null) { - String name = template.getEditingFILE().getName(); - long start = System.currentTimeMillis(); - Set set = ClassHelper.getClassLoaders(baseBook); - FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start)); - if (set != null) { - for (ClassLoader classLoader : set) { - PluginContext pluginContext = PluginManager.getContext(classLoader); - if (pluginContext != null && ComparatorUtils.equals(context.getName(), pluginContext.getName())) { - templateNeedReloadMap.put(name, true); - } - } - } else { - templateNeedReloadMap.put(name, true); - } + + public void reloadAllEditingTemplateByPlugin(PluginContext context) { + _reloadAllEditingTemplate(context); + } + + public void reloadAllEditingTemplate() { + _reloadAllEditingTemplate(null); + } + + private boolean needReloadTemplate(PluginContext context, JTemplate template) { + BaseBook baseBook = template.getTarget(); + if (baseBook != null) { + String name = template.getEditingFILE().getName(); + String pluginId = context.getID(); + long start = System.currentTimeMillis(); + Set set = ClassHelper.getClassLoaders(baseBook); + FineLoggerFactory.getLogger().info("{} find plugin classloader spend: {} ms", name, (System.currentTimeMillis() - start)); + if (set != null) { + for (ClassLoader classLoader : set) { + if (PluginManager.isBeforeLoadBy(classLoader, pluginId)) { + return true; + } + } + } else { + return true; } } + return false; } } diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java index 5ca7efdd6b..ebea410bba 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java @@ -1,6 +1,6 @@ package com.fr.start.module; -import com.fr.design.PluginRefreshManager; +import com.fr.design.PluginClassRefreshManager; import com.fr.module.Activator; import com.fr.start.DesignerInitial; @@ -16,7 +16,7 @@ public class DesignerInitActivator extends Activator { @Override public void start() { - PluginRefreshManager.getInstance().load(); + PluginClassRefreshManager.getInstance().load(); DesignerInitial.init(findSingleton(StartupArgs.class).get()); }