Files
VisualSapfor/src/_VisualDVM/Repository/RepositoryClient.java

74 lines
2.5 KiB
Java
Raw Normal View History

2024-10-09 22:21:57 +03:00
package _VisualDVM.Repository;
2024-10-14 15:19:13 +03:00
import Common.Passes.PassException;
2024-10-11 00:00:30 +03:00
import Common.Utils.Utils_;
2024-10-14 15:19:13 +03:00
import _VisualDVM.Passes.Server.TestingSystemPass;
2024-10-09 22:21:57 +03:00
import _VisualDVM.Repository.Server.ServerCode;
import _VisualDVM.Repository.Server.ServerExchangeUnit_2021;
2024-04-26 17:57:58 +03:00
import java.io.FileWriter;
import java.io.Serializable;
import java.util.Date;
public abstract class RepositoryClient {
//--
protected int getSleepMillis() {
return 2000;
}
//---
protected boolean isPrintOn() {
return true;
}
protected void Print(String message) {
try {
if (isPrintOn()) {
FileWriter testLog = new FileWriter(getClass().getSimpleName() + "_Log.txt", true);
2024-10-11 00:00:30 +03:00
String dmessage = Utils_.Brackets(new Date()) + " " + message;
2024-04-26 17:57:58 +03:00
testLog.write(dmessage + "\n");
testLog.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
//--
protected Object ServerCommand(ServerCode code_in, String arg, Serializable object_in) throws Exception {
TestingSystemPass<Object> pass = new TestingSystemPass<Object>() {
@Override
public String getDescription() {
return "";
}
@Override
protected void ServerAction() throws Exception {
Command(new ServerExchangeUnit_2021(code_in, arg, object_in));
target = response.object;
}
@Override
protected boolean validate() {
return Log.isEmpty();
}
};
2024-04-26 19:54:34 +03:00
if (!pass.Do()) {
2024-04-26 17:57:58 +03:00
ServerConnectionError(code_in, pass.Log.toString());
2024-04-26 19:54:34 +03:00
}
2024-04-26 17:57:58 +03:00
return pass.target;
}
protected Object ServerCommand(ServerCode code_in, Serializable object_in) throws Exception {
return ServerCommand(code_in, "", object_in);
}
protected Object ServerCommand(ServerCode code_in) throws Exception {
return ServerCommand(code_in, "", null);
}
protected void ServerConnectionError(ServerCode code_in, String logText) throws Exception {
2024-10-14 15:19:13 +03:00
throw new PassException(Utils_.Brackets(new Date().toString()) + " Ошибка взаимодействия с сервером " + code_in);
2024-04-26 17:57:58 +03:00
}
public abstract void perform() throws Exception;
2024-10-14 15:19:13 +03:00
public void Perform() {
2024-04-26 17:57:58 +03:00
try {
2024-10-14 15:19:13 +03:00
perform();
2024-04-26 17:57:58 +03:00
} catch (Exception ex) {
ex.printStackTrace();
} finally {
2024-10-11 00:00:30 +03:00
Utils_.sleep(getSleepMillis());
2024-04-26 17:57:58 +03:00
}
}
}