Browse Source

无JIRA任务 designer打包引用混淆类

feature/10.0
vito 4 years ago
parent
commit
f3477809dc
  1. 2
      designer-realize/src/main/java/com/fr/design/mainframe/app/DesignerAppActivator.java
  2. 12
      designer-realize/src/main/java/com/fr/design/mainframe/app/DesignerAppUtils.java
  3. 138
      designer-realize/src/main/java/com/fr/design/mainframe/app/PluginRemote.java

2
designer-realize/src/main/java/com/fr/design/mainframe/app/DesignerAppActivator.java

@ -19,6 +19,7 @@ public class DesignerAppActivator extends Activator implements Prepare {
for (App app : appList) {
JTemplateFactory.register(app);
}
PluginRemote.getInstance().start();
}
@Override
@ -28,6 +29,7 @@ public class DesignerAppActivator extends Activator implements Prepare {
for (App app : appList) {
JTemplateFactory.remove(app);
}
PluginRemote.getInstance().stop();
}
@Override

12
designer-realize/src/main/java/com/fr/design/mainframe/app/DesignerAppUtils.java

@ -6,11 +6,11 @@ import com.fr.design.extra.exe.callback.InstallOnlineCallback;
import com.fr.design.extra.exe.callback.ModifyStatusCallback;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.app.PluginRemote.PluginStatus;
import com.fr.design.ui.util.UIUtil;
import com.fr.locale.InterProviderFactory;
import com.fr.plugin.context.PluginMarker;
import com.fr.plugin.context.PluginMarkerAdapter;
import com.fr.plugin.engine.remote.PluginRemoteSync;
import com.fr.plugin.manage.PluginManager;
import com.fr.plugin.manage.control.PluginControllerHelper;
import com.fr.plugin.manage.control.PluginTask;
@ -130,21 +130,21 @@ public class DesignerAppUtils {
* @param pendingPlugins 待处理列表
*/
public static void rearrange(Multimap<String, PluginMarkerAdapter> pendingPlugins) {
Map<String, PluginRemoteSync.PluginStatus> pluginRemoteStatusByIdIndex = PluginRemoteSync.getInstance().getPluginRemoteStatusByIdIndex();
Map<String, PluginStatus> pluginRemoteStatus = PluginRemote.getInstance().getPluginRemoteStatus();
Collection<PluginMarkerAdapter> unknownPlugins = pendingPlugins.get(TemplateIOErrorContextHolder.UNKNOWN_PLUGIN);
Collection<PluginMarkerAdapter> notInstall = pendingPlugins.get(TemplateIOErrorContextHolder.NOT_INSTALLED_PLUGIN);
Collection<PluginMarkerAdapter> disable = pendingPlugins.get(TemplateIOErrorContextHolder.DISABLE_PLUGIN);
unknownPlugins.removeIf(adapter -> pluginRemoteStatusByIdIndex.containsKey(adapter.getPluginID()));
unknownPlugins.removeIf(adapter -> pluginRemoteStatus.containsKey(adapter.getPluginID()));
// 本地未启用名单不准确添加到一起之后重新分配
notInstall.addAll(disable);
disable.clear();
// 从所有未安装中过滤远程未启用的,添加到未启用列表
disable.addAll(notInstall.stream().filter(plugin ->
pluginRemoteStatusByIdIndex.containsKey(plugin.getPluginID())
&& !pluginRemoteStatusByIdIndex.get(plugin.getPluginID()).isRunning())
pluginRemoteStatus.containsKey(plugin.getPluginID())
&& !pluginRemoteStatus.get(plugin.getPluginID()).isRunning())
.collect(Collectors.toList()));
// 清理未安装中所有远程安装过的插件(包含启用和未启用)
notInstall.removeIf(adapter -> pluginRemoteStatusByIdIndex.containsKey(adapter.getPluginID()));
notInstall.removeIf(adapter -> pluginRemoteStatus.containsKey(adapter.getPluginID()));
}
/**

138
designer-realize/src/main/java/com/fr/design/mainframe/app/PluginRemote.java

@ -0,0 +1,138 @@
package com.fr.design.mainframe.app;
import com.fr.base.FRContext;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.context.PluginMarker;
import com.fr.stable.StringUtils;
import com.fr.value.AtomicClearableLazyValue;
import com.fr.workspace.WorkContext;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* 获取远程插件情况定时刷新
*
* @author vito
* @version 10.0
* Created by vito on 2021/6/1
*/
public class PluginRemote {
private static final PluginRemote INSTANCE = new PluginRemote();
private final AtomicClearableLazyValue<Map<String, PluginStatus>> lazyValue = new AtomicClearableLazyValue<Map<String, PluginStatus>>() {
@NotNull
@Override
protected Map<String, PluginStatus> compute() {
return getRemoteStatus();
}
};
/**
* 时间间隔两分钟
*/
private static final int INTERVAL = 2;
private ScheduledExecutorService executor;
public static PluginRemote getInstance() {
return INSTANCE;
}
/**
* 获取远程插件状态
* @return 远程插件状态
*/
public Map<String, PluginStatus> getPluginRemoteStatus() {
return lazyValue.getValue();
}
private Map<String, PluginStatus> getRemoteStatus() {
JSONArray statusArray = FRContext.getCommonOperator().getPluginStatus();
JSONObject status;
String id;
String version;
boolean running;
Map<String, PluginStatus> statusMap = new HashMap<>();
for (int i = 0; i < statusArray.length(); i++) {
try {
status = statusArray.getJSONObject(i);
id = status.getString("id");
version = status.getString("version");
running = status.getBoolean("running");
if(StringUtils.isBlank(id)){
continue;
}
PluginStatus pluginStatus = PluginStatus.create(id, version, running);
if (pluginStatus != null) {
statusMap.put(id, pluginStatus);
}
} catch (JSONException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
return statusMap;
}
public void start() {
// 远程环境下开始同步插件情况
if (!WorkContext.getCurrent().isLocal()) {
executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleAtFixedRate(() -> {
lazyValue.drop();
lazyValue.getValue();
}, 0, INTERVAL, TimeUnit.MINUTES);
}
}
public void stop() {
if (executor != null) {
executor.shutdown();
executor = null;
lazyValue.drop();
}
}
public static class PluginStatus {
private final PluginMarker marker;
private final boolean running;
private PluginStatus(PluginMarker marker, boolean running) {
this.marker = marker;
this.running = running;
}
static PluginStatus create(String id, String version, boolean running) {
PluginMarker marker = PluginMarker.create(id, version);
if (marker != null && marker.valid()) {
return new PluginStatus(marker, running);
}
return null;
}
public PluginMarker getMarker() {
return marker;
}
public boolean isRunning() {
return running;
}
}
}
Loading…
Cancel
Save