Files
VisualSapfor/src/Common/ModesSupervisors/PackageModeSupervisor.java

90 lines
2.5 KiB
Java
Raw Normal View History

package Common.ModesSupervisors;
2023-09-20 00:53:45 +03:00
import Common.Global;
import Common.Utils.InterruptThread;
2023-09-20 00:53:45 +03:00
import Common.Utils.Utils;
2023-09-21 20:55:14 +03:00
import SapforTestingSystem.Json.Scenario_json;
2023-09-22 00:16:46 +03:00
import SapforTestingSystem.SapforTest.SapforTest;
2023-09-20 00:53:45 +03:00
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.charset.Charset;
2023-09-22 00:16:46 +03:00
import java.util.LinkedHashMap;
2023-09-21 20:55:14 +03:00
import java.util.Stack;
import java.util.Vector;
public class PackageModeSupervisor {
2023-09-20 00:53:45 +03:00
Thread interruptThread = new InterruptThread(5000, () -> {
2023-09-19 19:16:15 +03:00
System.exit(0);
return null;
});
2023-09-20 00:53:45 +03:00
//--->>
2023-09-21 20:55:14 +03:00
int kernels = 4;
2023-09-20 00:53:45 +03:00
//--->>
Scenario_json scenario;
//--->>
File packageWorkspace;
//--->>
File sapfor_drv;
File scenarioFile;
//--->>
2023-09-22 00:16:46 +03:00
LinkedHashMap<String, SapforTest> allTests = new LinkedHashMap<>();
//--->>>
2023-09-21 20:55:14 +03:00
Vector<String> activeTests = new Vector<>();
Stack<String> waitingTests = new Stack<>();
//--->>
public void init() throws Exception {
packageWorkspace = new File(Global.Home);
scenarioFile = new File(packageWorkspace, "scenario.txt");
sapfor_drv = new File(packageWorkspace, "SAPFOR_F.exe");
String packed = FileUtils.readFileToString(scenarioFile, Charset.defaultCharset());
scenario = Utils.gson.fromJson(packed, Scenario_json.class);
//--->>
2023-09-22 00:16:46 +03:00
for (String test : scenario.tests) {
allTests.put(test, new SapforTest(Global.Home, test));
2023-09-21 20:55:14 +03:00
waitingTests.push(test);
2023-09-22 00:16:46 +03:00
}
2023-09-21 20:55:14 +03:00
}
2023-09-22 00:16:46 +03:00
public boolean isFinished(String test) {
2023-09-21 20:55:14 +03:00
return true;
}
//--->>
2023-09-21 21:17:02 +03:00
public boolean checkActiveTests() throws Exception {
/*
2023-09-21 20:55:14 +03:00
Vector<String> finishedTests = new Vector<>();
for (String test: activeTests){
if (isFinished(test))
finishedTests.add(test);
}
for (String test: finishedTests){
activeTests.remove(test);
}
2023-09-21 21:17:02 +03:00
*/
2023-09-22 00:16:46 +03:00
return false;
2023-09-21 20:55:14 +03:00
}
2023-09-21 21:17:02 +03:00
public boolean startWaitingTests() throws Exception {
2023-09-22 00:16:46 +03:00
return false;
}
public void finalize(){
Global.Log.Print("END");
2023-09-21 20:55:14 +03:00
}
//--->>
public void Do() {
try {
2023-09-22 00:16:46 +03:00
Global.Log.Print("START");
interruptThread.start();
2023-09-20 00:53:45 +03:00
//--->>
2023-09-21 20:55:14 +03:00
init();
2023-09-20 00:53:45 +03:00
//--->>
2023-09-22 00:16:46 +03:00
while (checkActiveTests() && startWaitingTests()) {
2023-09-21 20:55:14 +03:00
Thread.sleep(1000);
2023-09-21 21:17:02 +03:00
}
2023-09-22 00:16:46 +03:00
finalize();
//--->>
} catch (Exception ex) {
ex.printStackTrace();
}
2023-09-22 00:16:46 +03:00
finally {
System.exit(0);
}
}
}