diff --git a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java index 4adcfc1b34..b8951ea8ba 100644 --- a/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/main/java/com/fr/design/DesignerEnvManager.java @@ -20,6 +20,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.locale.impl.ProductImproveMark; import com.fr.design.mainframe.vcs.VcsConfigManager; import com.fr.design.notification.SnapChatConfig; +import com.fr.design.port.DesignerPortContext; import com.fr.design.update.push.DesignerPushUpdateConfigManager; import com.fr.design.style.color.ColorSelectConfigManager; import com.fr.design.utils.DesignUtils; @@ -844,9 +845,9 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { * 返回Jetty服务器的端口号 */ public int getEmbedServerPort() { - DesignerPortProvider portProvider = StableFactory.getMarkedInstanceObjectFromClass(DesignerPortProvider.MARK_STRING, DesignerPortProvider.class); - if (portProvider != null) { - return portProvider.embeddedServerPort(); + int embeddedServerPort = DesignerPortContext.getEmbeddedServerPort(); + if (embeddedServerPort >= DesignerPort.MIN_PORT && embeddedServerPort <= DesignerPort.MAX_PORT) { + return embeddedServerPort; } return this.jettyServerPort; } diff --git a/designer-base/src/main/java/com/fr/design/port/DesignerPortContext.java b/designer-base/src/main/java/com/fr/design/port/DesignerPortContext.java new file mode 100644 index 0000000000..e1e40ddfb0 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/port/DesignerPortContext.java @@ -0,0 +1,32 @@ +package com.fr.design.port; + +import com.fr.design.fun.DesignerPortProvider; +import com.fr.stable.bridge.StableFactory; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2021/1/27 + */ +public class DesignerPortContext { + + private static int messagePort = -1; + + private static int embeddedServerPort = -1; + + static { + DesignerPortProvider designerPortProvider = StableFactory.getMarkedInstanceObjectFromClass(DesignerPortProvider.MARK_STRING, DesignerPortProvider.class); + if (designerPortProvider != null) { + messagePort = designerPortProvider.messagePort(); + embeddedServerPort = designerPortProvider.embeddedServerPort(); + } + } + + public static int getMessagePort() { + return messagePort; + } + + public static int getEmbeddedServerPort() { + return embeddedServerPort; + } +} diff --git a/designer-base/src/main/java/com/fr/design/utils/DesignerPort.java b/designer-base/src/main/java/com/fr/design/utils/DesignerPort.java index 474c29a8f5..28ab5e4c14 100644 --- a/designer-base/src/main/java/com/fr/design/utils/DesignerPort.java +++ b/designer-base/src/main/java/com/fr/design/utils/DesignerPort.java @@ -10,6 +10,7 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.port.DesignerPortContext; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.exit.DesignerExiter; import com.fr.general.ComparatorUtils; @@ -36,8 +37,8 @@ import java.awt.event.ActionListener; public class DesignerPort implements XMLReadable, XMLWriter { public static final String XML_TAG = "DesignerPort"; - private static final int MIN_PORT = 1024; - private static final int MAX_PORT = 65535; + public static final int MIN_PORT = 1024; + public static final int MAX_PORT = 65535; public static final DesignerPort INSTANCE = new DesignerPort(); @@ -59,9 +60,9 @@ public class DesignerPort implements XMLReadable, XMLWriter { private int debugMessagePort = 51463; public int getMessagePort() { - DesignerPortProvider portProvider = StableFactory.getMarkedInstanceObjectFromClass(DesignerPortProvider.MARK_STRING, DesignerPortProvider.class); - if (portProvider != null) { - return portProvider.messagePort(); + int extraMessagePort = DesignerPortContext.getMessagePort(); + if (extraMessagePort >= MIN_PORT && extraMessagePort <= MAX_PORT) { + return extraMessagePort; } return messagePort; }