76 lines
2.6 KiB
Java
76 lines
2.6 KiB
Java
|
|
package Repository;
|
|||
|
|
import Common.Utils.Utils;
|
|||
|
|
import Repository.Server.ServerCode;
|
|||
|
|
import Repository.Server.ServerExchangeUnit_2021;
|
|||
|
|
import Visual_DVM_2021.Passes.PassException;
|
|||
|
|
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
|
|||
|
|
|
|||
|
|
import java.io.FileWriter;
|
|||
|
|
import java.io.Serializable;
|
|||
|
|
import java.util.Date;
|
|||
|
|
import java.util.Vector;
|
|||
|
|
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);
|
|||
|
|
String dmessage = Utils.Brackets(new Date()) + " " + message;
|
|||
|
|
System.out.println(dmessage);
|
|||
|
|
testLog.write(dmessage + "\n");
|
|||
|
|
testLog.close();
|
|||
|
|
}
|
|||
|
|
} catch (Exception ex) {
|
|||
|
|
ex.printStackTrace();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//--
|
|||
|
|
protected Object ServerCommand(ServerCode code_in, String arg, Serializable object_in) throws Exception {
|
|||
|
|
System.out.println("Команда серверу " + code_in.toString() + "arg=" + arg + " object=" + object_in);
|
|||
|
|
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();
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
if (!pass.Do())
|
|||
|
|
ServerConnectionError(code_in, pass.Log.toString());
|
|||
|
|
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 {
|
|||
|
|
throw new PassException("Ошибка взаимодействия с сервером " + code_in);
|
|||
|
|
}
|
|||
|
|
public abstract void perform() throws Exception;
|
|||
|
|
public void Perform(){
|
|||
|
|
try {
|
|||
|
|
perform();
|
|||
|
|
} catch (Exception ex) {
|
|||
|
|
ex.printStackTrace();
|
|||
|
|
} finally {
|
|||
|
|
Utils.sleep(getSleepMillis());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|