Browse Source

KERNEL-6380 解耦 仅处理插件afterRun生命周期 + 重命名

feature/big-screen
hades 4 years ago
parent
commit
6442a43639
  1. 38
      designer-base/src/main/java/com/fr/design/PluginClassRefreshManager.java
  2. 57
      designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java
  3. 4
      designer-realize/src/main/java/com/fr/start/module/DesignerInitActivator.java

38
designer-base/src/main/java/com/fr/design/PluginRefreshManager.java → 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<String> 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);
}
}

57
designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java

@ -46,8 +46,6 @@ public class HistoryTemplateListCache implements CallbackEvent {
private List<JTemplate<?, ?>> historyList;
private JTemplate<?, ?> editingTemplate;
private Map<String, Boolean> 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<ClassLoader> 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<ClassLoader> 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;
}
}

4
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());
}

Loading…
Cancel
Save