Commit 76cdabcb authored by Luna Riegel's avatar Luna Riegel
Browse files

Refactor: Make Schematron run in background thread

parent 58f0a808
......@@ -191,13 +191,26 @@ public class Checker {
if (config == null) {
config = ValidationConfiguration.loadStandardValidationConfig();
}
Thread schematronThread = new Thread(() -> {
SvrlContentHandler handler = executeSchematronValidationIfAvailable(config, model.getFile());
if (handler != null) {
handleSchematronResults(handler);
}
});
schematronThread.start();
checkCityModel(model, l);
if (logger.isInfoEnabled()) {
logger.info(Localization.getText("Checker.checksFinished"));
}
SvrlContentHandler handler = executeSchematronValidationIfAvailable(config, model.getFile());
if (handler != null) {
handleSchematronResults(handler);
if (schematronThread.isAlive()) {
//TODO: Localize String
logger.info("Schematron thread still running, waiting for completion. This may take some time");
try{
schematronThread.join();
} catch (InterruptedException e) {
logger.error("Main Thread was interrupted while waiting for Schematron", e);
schematronThread.interrupt();
}
}
model.setValidated(createValidationPlan());
}
......@@ -443,6 +456,7 @@ public class Checker {
logger.info(Localization.getText("Checker.schematronValidation"));
}
if (!Files.exists(Path.of(config.getSchematronFilePath()))) {
//TODO: Localize String
logger.warn("Schematron file {} could not be found", config.getSchematronFilePath());
return null;
}
......@@ -563,6 +577,7 @@ public class Checker {
for (Entry<String, RequirementConfiguration> e : config.getRequirements().entrySet()) {
de.hft.stuttgart.citydoctor2.check.Requirement req = Checks.getAvailableRequirements().get(e.getKey());
if (req == null) {
//TODO: Localize String
logger.warn("Could not find any check that satisfies requirement {}, it will not be checked",
e.getKey());
} else {
......@@ -638,7 +653,6 @@ public class Checker {
AtomicInteger missingCount = new AtomicInteger(0);
// clear global errors
model.getGlobalErrors().clear();
CheckerThreadsSynchronizer sync = new CheckerThreadsSynchronizer(model, l);
int threadCount = Runtime.getRuntime().availableProcessors() * 5;
ExecutorService exec = new ThreadPoolExecutor
......@@ -669,9 +683,13 @@ public class Checker {
try {
exec.awaitTermination(30, TimeUnit.DAYS);
long endTime = System.nanoTime();
logger.info("Checks finished in " + (endTime -startTime) / 1_000_000 + " ms");
if (logger.isDebugEnabled()){
logger.debug("Checks finished in {} ms", (endTime - startTime) / 1_000_000);
}
if (missingCount.get() > 0) {
int missing = missingCount.get();
//TODO: Localize String
String msg = String.format("Checker could not load %d/%.0f features (%.2f%%)", missing, featureSum, (missing/featureSum) * 100);
logger.warn(msg);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment