|
|
|
@ -66,7 +66,8 @@ import java.util.concurrent.TimeoutException;
|
|
|
|
|
* Some util method of Designer |
|
|
|
|
*/ |
|
|
|
|
public class DesignUtils { |
|
|
|
|
private static int port = DesignerPort.getInstance().getMessagePort(); |
|
|
|
|
|
|
|
|
|
private static Integer port; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static boolean started = false; |
|
|
|
@ -80,6 +81,13 @@ public class DesignUtils {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public synchronized static int getPort() { |
|
|
|
|
if (port == null) { |
|
|
|
|
if (ComparatorUtils.equals("true", System.getProperty("debug"))) { |
|
|
|
|
setPort(DesignerPort.getInstance().getDebugMessagePort()); |
|
|
|
|
} else { |
|
|
|
|
setPort(DesignerPort.getInstance().getMessagePort()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return port; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -93,7 +101,6 @@ public class DesignUtils {
|
|
|
|
|
return started; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 判断设计器端口是否被其他程序占用 |
|
|
|
|
* 尝试去通信,无回应就是其他程序占用端口,否则需要继续判断是否为设计器进程未关闭 |
|
|
|
@ -103,7 +110,7 @@ public class DesignUtils {
|
|
|
|
|
public static boolean isPortOccupied() { |
|
|
|
|
ExecutorService executor = null; |
|
|
|
|
Future<String> future = null; |
|
|
|
|
try (Socket socket = new Socket("localhost", port); |
|
|
|
|
try (Socket socket = new Socket("localhost", getPort()); |
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8)); |
|
|
|
|
PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.UTF_8)))) { |
|
|
|
|
writer.println("check"); |
|
|
|
@ -167,7 +174,7 @@ public class DesignUtils {
|
|
|
|
|
if (lines == null || lines.length == 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
try (Socket socket = new Socket("localhost", port)) { |
|
|
|
|
try (Socket socket = new Socket("localhost", getPort())) { |
|
|
|
|
clientSend(lines, socket); |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
|
|
|
|
@ -190,7 +197,7 @@ public class DesignUtils {
|
|
|
|
|
try { |
|
|
|
|
serverSocket = new ServerSocket(startPort); |
|
|
|
|
} catch (IOException e1) { |
|
|
|
|
FineLoggerFactory.getLogger().error("Cannot create server socket on " + port); |
|
|
|
|
FineLoggerFactory.getLogger().error("Cannot create server socket on " + getPort()); |
|
|
|
|
} |
|
|
|
|
while (true) { |
|
|
|
|
try { |
|
|
|
@ -250,7 +257,7 @@ public class DesignUtils {
|
|
|
|
|
reader.close(); |
|
|
|
|
socket.close(); |
|
|
|
|
} else { |
|
|
|
|
FineLoggerFactory.getLogger().error("Cannot create server socket on " + port); |
|
|
|
|
FineLoggerFactory.getLogger().error("Cannot create server socket on " + getPort()); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} catch (IOException ignored) { |
|
|
|
|