diff --git a/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java b/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java index 1174a8a73..d39f6a1d5 100644 --- a/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java +++ b/designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceGenerator.java @@ -1,15 +1,35 @@ package com.fr.design.env; +import com.fr.concurrent.NamedThreadFactory; +import com.fr.design.EnvChangeEntrance; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.messagecollect.StartErrorMessageCollector; +import com.fr.design.mainframe.messagecollect.entity.DesignerErrorMessage; +import com.fr.general.IOUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.module.ModuleContext; +import com.fr.stable.StringUtils; import com.fr.workspace.WorkContext; import com.fr.workspace.Workspace; import com.fr.workspace.connect.WorkspaceClient; +import javax.swing.*; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + /** * 根据配置生成运行环境 */ public class DesignerWorkspaceGenerator { - public static Workspace generate(DesignerWorkspaceInfo config) throws Exception { + private static final int WAIT_FREQ = 60; + private static ExecutorService service = ModuleContext.getExecutor().newSingleThreadExecutor( + new NamedThreadFactory("DesignerWorkspaceGenerator")); + + public static Workspace generate(final DesignerWorkspaceInfo config) throws Exception { if (config == null || config.getType() == null) { return null; @@ -22,7 +42,19 @@ public class DesignerWorkspaceGenerator { break; } case Remote: { - WorkspaceClient client = WorkContext.getConnector().connect(config.getConnection()); + Future future = service.submit(new Callable() { + @Override + public WorkspaceClient call() throws Exception { + return WorkContext.getConnector().connect(config.getConnection()); + } + }); + WorkspaceClient client = null; + try { + client = future.get(WAIT_FREQ, TimeUnit.SECONDS); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + RemoteHandler.handle(config); + } if (client != null) { workspace = new RemoteWorkspace(client, config.getConnection()); } @@ -31,4 +63,30 @@ public class DesignerWorkspaceGenerator { } return workspace; } + + enum RemoteHandler { + SELF; + public static void handle(DesignerWorkspaceInfo config) { + StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.REMOTE_DESIGN_NO_RESPONSE.getId(), + DesignerErrorMessage.REMOTE_DESIGN_NO_RESPONSE.getMessage(), + StringUtils.EMPTY); + int result = FineJOptionPane.showOptionDialog(null, + Toolkit.i18nText("Fine-Design_Error_Remote_No_Response_Tip"), + Toolkit.i18nText("Fine-Design_Basic_Error_Tittle"), + JOptionPane.YES_NO_OPTION, + JOptionPane.ERROR_MESSAGE, + IOUtils.readIcon("com/fr/design/images/error/error2.png"), + new Object[] {Toolkit.i18nText("Fine-Design_Error_Remote_No_Response_Wait"), Toolkit.i18nText("Fine-Design_Error_Remote_No_Response_Switch")}, + null); + if (result == JOptionPane.YES_OPTION) { + try { + generate(config); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } else { + EnvChangeEntrance.getInstance().dealEvnExceptionWhenStartDesigner(); + } + } + } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java b/designer-base/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java similarity index 94% rename from designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java rename to designer-base/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java index 9bfd729dd..99950edae 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java @@ -21,6 +21,9 @@ import java.util.Date; */ public class ErrorInfo { + private static final String SUFFIX = ".json"; + private static final String FOLDER_NAME = "errorInfo"; + private String username; private String uuid; private String activekey; @@ -128,8 +131,8 @@ public class ErrorInfo { public void saveFileToCache(JSONObject jo) { String content = jo.toString(); - String fileName = UUID.randomUUID() + ErrorInfoUploader.SUFFIX; - File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), ErrorInfoUploader.FOLDER_NAME, fileName)); + String fileName = UUID.randomUUID() + SUFFIX; + File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FOLDER_NAME, fileName)); FileOutputStream out = null; try (InputStream in = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) { StableUtils.makesureFileExist(file); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java b/designer-base/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java similarity index 90% rename from designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java rename to designer-base/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java index 0b6a6b0e4..3f31bf9aa 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java @@ -1,8 +1,8 @@ package com.fr.design.mainframe.messagecollect; -import com.fr.config.MarketConfig; import com.fr.design.DesignerEnvManager; import com.fr.design.mainframe.errorinfo.ErrorInfo; +import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; /** @@ -30,6 +30,7 @@ public class StartErrorMessageCollector { } public void record(String id, String msg, String detail) { + FineLoggerFactory.getLogger().error(id + ": " + msg + "detail: " + detail); ErrorInfo errorInfo = new ErrorInfo(StringUtils.EMPTY, uuid, activeKey); errorInfo.setLogid(id); errorInfo.setLog(msg); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/DesignerErrorMessage.java b/designer-base/src/main/java/com/fr/design/mainframe/messagecollect/entity/DesignerErrorMessage.java similarity index 100% rename from designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/DesignerErrorMessage.java rename to designer-base/src/main/java/com/fr/design/mainframe/messagecollect/entity/DesignerErrorMessage.java