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

73 lines
2.1 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-20 00:53:45 +03:00
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.charset.Charset;
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-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);
//--->>
for (String test : scenario.tests)
waitingTests.push(test);
}
public boolean isFinished(String test){
return true;
}
//--->>
public void checkActiveTests() throws Exception {
Vector<String> finishedTests = new Vector<>();
for (String test: activeTests){
if (isFinished(test))
finishedTests.add(test);
}
for (String test: finishedTests){
activeTests.remove(test);
}
}
public void startWaitingTests() throws Exception {
}
//--->>
public void Do() {
try {
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-21 20:55:14 +03:00
do {
checkActiveTests();
startWaitingTests();
Thread.sleep(1000);
} while (!activeTests.isEmpty() && !waitingTests.isEmpty());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}