2023-11-19 02:12:44 +03:00
|
|
|
|
package Repository.Component;
|
2024-10-07 14:22:52 +03:00
|
|
|
|
import Common.Utils.CommonUtils;
|
2024-10-08 22:33:49 +03:00
|
|
|
|
import Common.Visual.CommonUI;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import _VisualDVM.Global;
|
|
|
|
|
|
import Common_old.Utils.Utils;
|
2023-11-19 02:12:44 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.PassException;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
|
import java.net.InetAddress;
|
|
|
|
|
|
import java.net.Socket;
|
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
|
public class Visualizer_2 extends OSDComponent {
|
|
|
|
|
|
//</editor-fold>
|
|
|
|
|
|
//-
|
|
|
|
|
|
//<editor-fold desc="функционал">
|
|
|
|
|
|
int port;
|
|
|
|
|
|
public String PID = "";
|
|
|
|
|
|
Socket client = null;
|
|
|
|
|
|
PrintWriter out = null;
|
|
|
|
|
|
BufferedReader in = null;
|
|
|
|
|
|
String request = "";
|
|
|
|
|
|
String response = "";
|
|
|
|
|
|
public Visualizer_2(int port_in) {
|
|
|
|
|
|
port = port_in;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void UnpackVersionInfo(Component component, String packed) {
|
|
|
|
|
|
String[] data = packed.split("\\|");
|
|
|
|
|
|
//лишний пробел.
|
|
|
|
|
|
String text = data[0].substring(0, data[0].length() - 1);
|
|
|
|
|
|
component.date_text = data[1] + data[2] + data[3];
|
|
|
|
|
|
component.version = Long.parseLong(text);
|
|
|
|
|
|
}
|
|
|
|
|
|
//<editor-fold desc="компонент">
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public ComponentType getComponentType() {
|
|
|
|
|
|
return ComponentType.Visualizer_2;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String getHome() {
|
2024-10-08 22:33:49 +03:00
|
|
|
|
return CommonUtils.getHomePath();
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void GetVersionInfo() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
Command("get_version: ");
|
|
|
|
|
|
UnpackVersionInfo(this, response);
|
|
|
|
|
|
} catch (Exception e) {
|
2024-10-07 22:04:09 +03:00
|
|
|
|
CommonUtils.MainLog.PrintException(e);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public void refreshPid(){
|
|
|
|
|
|
try {
|
|
|
|
|
|
// UI.Info("Getting Server PID...");
|
|
|
|
|
|
Command("get_pid: ");
|
|
|
|
|
|
PID = response;
|
|
|
|
|
|
// UI.Info("SERVER PID = "+Utils.Brackets(PID));
|
|
|
|
|
|
} catch (Exception e) {
|
2024-10-07 22:04:09 +03:00
|
|
|
|
CommonUtils.MainLog.PrintException(e);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void Update() throws Exception {
|
|
|
|
|
|
super.Update();
|
|
|
|
|
|
SendRequest("update_server: ");
|
|
|
|
|
|
ReplaceOldFile();
|
2024-10-08 22:33:49 +03:00
|
|
|
|
CommonUI.Info("Сервер успешно обновлен.\n" +
|
2023-09-17 22:13:42 +03:00
|
|
|
|
"Визуализатор завершает работу.\n" +
|
|
|
|
|
|
"Для продолжения перезапустите визуализатор вручную.");
|
|
|
|
|
|
System.exit(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String getAssemblyCommand() {
|
|
|
|
|
|
return "cd Repo/sapfor/experts/Sapfor_2017/_src/Server\n" +
|
|
|
|
|
|
"g++ -O3 -std=c++17 checkUniq.cpp server.cpp -o Visualizer_2 -lpthread -lstdc++fs\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public File getAssemblyFile() {
|
|
|
|
|
|
return Paths.get(
|
|
|
|
|
|
Global.RepoDirectory.getAbsolutePath(),
|
|
|
|
|
|
"sapfor/experts/Sapfor_2017/_src/Server/Visualizer_2").toFile();
|
|
|
|
|
|
}
|
|
|
|
|
|
public void Connect() throws Exception {
|
|
|
|
|
|
ClearLog();
|
|
|
|
|
|
Print("соединение с Visualiser_2...");
|
|
|
|
|
|
client = Utils.createClientSocket(
|
|
|
|
|
|
InetAddress.getLoopbackAddress(),
|
|
|
|
|
|
port, 0
|
|
|
|
|
|
);
|
|
|
|
|
|
in = new BufferedReader(new InputStreamReader(client.getInputStream())); //то что нам приходит от сервера
|
|
|
|
|
|
out = new PrintWriter(client.getOutputStream(), true); //то что мы пишем серверу.
|
|
|
|
|
|
}
|
|
|
|
|
|
public void Interrupt(){
|
|
|
|
|
|
Utils.Kill(PID, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void Shutdown() throws Exception {
|
|
|
|
|
|
Print("завершение сеанса с Visualiser_2...");
|
|
|
|
|
|
SendRequest("close: ");
|
|
|
|
|
|
if (client != null)
|
|
|
|
|
|
client.close();
|
|
|
|
|
|
if (in != null)
|
|
|
|
|
|
in.close();
|
|
|
|
|
|
if (out != null)
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
//запрос.
|
|
|
|
|
|
public void SendRequest(String request_in) throws Exception {
|
|
|
|
|
|
Print("->" + request_in);
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
System.gc();
|
|
|
|
|
|
out.println(request = request_in);
|
|
|
|
|
|
}
|
|
|
|
|
|
//запрос-ответ. анализируются только общие ошибочные случаи.
|
|
|
|
|
|
public String Command(String request_in) throws Exception {
|
|
|
|
|
|
SendRequest(request_in);
|
|
|
|
|
|
response = in.readLine();
|
|
|
|
|
|
switch (response) {
|
|
|
|
|
|
case "NOT_FOUND":
|
|
|
|
|
|
case "WRONG":
|
|
|
|
|
|
case "SEG_FAULT":
|
2024-10-07 14:22:52 +03:00
|
|
|
|
throw new PassException("Команда серверу SAPFOR вернула " + CommonUtils.Brackets(response));
|
2023-09-17 22:13:42 +03:00
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
Print("<-" + response);
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
System.gc();
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
//</editor-fold>
|
|
|
|
|
|
}
|