Browse Source

Merge pull request #1489 in DESIGN/design from ~HADES/design:release/10.0 to release/10.0

* commit 'a1cddd627db811ebe76b3dcdcabdc450939225c8':
  fix
  REPORT-27945 && REPORT-27934 && REPORT-27940
feature/big-screen
Hades 5 years ago
parent
commit
4a09eab479
  1. 59
      designer-base/src/main/java/com/fr/common/detect/CommonPortDetector.java
  2. 2
      designer-base/src/main/java/com/fr/start/BaseDesigner.java
  3. 45
      designer-base/src/test/java/com/fr/common/detect/CommonPortDetectorTest.java
  4. 5
      designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

59
designer-base/src/main/java/com/fr/common/detect/CommonPortDetector.java

@ -0,0 +1,59 @@
package com.fr.common.detect;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager;
import com.fr.log.FineLoggerFactory;
import com.fr.module.ModuleContext;
import com.fr.web.WebSocketConfig;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
/**
* @author hades
* @version 10.0
* Created by hades on 2020/3/10
*/
public class CommonPortDetector {
private static final CommonPortDetector INSTANCE = new CommonPortDetector();
private ExecutorService service = ModuleContext.getExecutor().newSingleThreadExecutor(new NamedThreadFactory("CommonPortDetector"));
public static CommonPortDetector getInstance() {
return INSTANCE;
}
public void execute() {
service.submit(new Runnable() {
@Override
public void run() {
detectTomcatPort();
detectWebSocketPort();
}
});
}
private void detectTomcatPort() {
int port = DesignerEnvManager.getEnvManager().getEmbedServerPort();
if (checkPort(port)) {
FineLoggerFactory.getLogger().error("EmbedTomcat Port: {} is not available, maybe occupied by other programs, please check it!", port);
}
}
private void detectWebSocketPort() {
Integer[] ports = WebSocketConfig.getInstance().getPort();
for (int port : ports) {
if (checkPort(port)) {
FineLoggerFactory.getLogger().error("WebSocKet Port: {} is not available, maybe occupied by other programs, please check it!", port);
}
}
}
private boolean checkPort(int port) {
try (Socket socket = new Socket("localhost", port)) {
return true;
} catch (Exception e) {
return false;
}
}
}

2
designer-base/src/main/java/com/fr/start/BaseDesigner.java

@ -3,6 +3,7 @@
*/ */
package com.fr.start; package com.fr.start;
import com.fr.common.detect.CommonPortDetector;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.constants.DesignerLaunchStatus; import com.fr.design.constants.DesignerLaunchStatus;
@ -76,6 +77,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock {
public void on(Event event, Null param) { public void on(Event event, Null param) {
EventDispatcher.stopListen(this); EventDispatcher.stopListen(this);
collectUserInformation(); collectUserInformation();
CommonPortDetector.getInstance().execute();
} }
}); });
} }

45
designer-base/src/test/java/com/fr/common/detect/CommonPortDetectorTest.java

@ -0,0 +1,45 @@
package com.fr.common.detect;
import com.fr.invoke.Reflect;
import com.fr.log.FineLoggerFactory;
import junit.framework.TestCase;
import org.junit.Assert;
import java.io.IOException;
import java.net.ServerSocket;
/**
* @author hades
* @version 10.0
* Created by hades on 2020/3/10
*/
public class CommonPortDetectorTest extends TestCase {
private ServerSocket serverSocket;
@Override
public void setUp() throws Exception {
serverSocket = new ServerSocket(55555);
new Thread(new Runnable() {
@Override
public void run() {
try {
serverSocket.accept();
} catch (IOException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}).start();
}
public void testCheckPort() {
CommonPortDetector detector = CommonPortDetector.getInstance();
boolean access = Reflect.on(detector).call("checkPort", 55555).get();
Assert.assertTrue(access);
}
@Override
public void tearDown() throws Exception {
serverSocket.close();
}
}

5
designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

@ -24,6 +24,7 @@ import com.fr.record.analyzer.Metrics;
import com.fr.stable.BuildContext; import com.fr.stable.BuildContext;
import com.fr.stable.ProductConstants; import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.start.DesignerProcessType; import com.fr.start.DesignerProcessType;
import com.fr.start.OemHandler; import com.fr.start.OemHandler;
import com.fr.start.ServerStarter; import com.fr.start.ServerStarter;
@ -91,6 +92,10 @@ public class DesignerStartup extends Activator {
} }
}; };
dialog.setVisible(true); dialog.setVisible(true);
StartErrorMessageCollector.getInstance().record(DesignerErrorMessage.DESIGNER_PROCESS_OCCUPIED.getId(),
DesignerErrorMessage.DESIGNER_PROCESS_OCCUPIED.getMessage(),
StringUtils.EMPTY);
FineLoggerFactory.getLogger().error(DesignerErrorMessage.DESIGNER_PROCESS_OCCUPIED.getId() + ": " + DesignerErrorMessage.DESIGNER_PROCESS_OCCUPIED.getMessage());
} }
DesignerExiter.getInstance().execute(); DesignerExiter.getInstance().execute();
return; return;

Loading…
Cancel
Save