Skip to content

Commit

Permalink
Gentle refactor + track session number
Browse files Browse the repository at this point in the history
  • Loading branch information
dotasek committed Jun 17, 2024
1 parent fbf2d01 commit 563d6fe
Showing 1 changed file with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -489,24 +489,7 @@ public String initializeValidator(CliContext cliContext, String definitions, Tim
if (sessionId != null) {
System.out.println("No such cached session exists for session id " + sessionId + ", re-instantiating validator.");
}
ValidationEngine validationEngine;
if (cliContext.getBaseEngine() != null && hasBaseEngineForKey(cliContext.getBaseEngine())) {
System.out.println("Building new validator engine from base engine: " + cliContext.getBaseEngine());
validationEngine = new ValidationEngine(getBaseEngine(cliContext.getBaseEngine()));
/* As a service, it wouldn't be efficient to have a base validation engine
* for every language. So we just use the baseEngine and set the language
* manually afterward.
*/
validationEngine.setLanguage(cliContext.getLang());
validationEngine.setLocale(cliContext.getLocale());
} else {
System.out.println("Building new validator engine from CliContext");
if (cliContext.getSv() == null) {
String sv = determineVersion(cliContext);
cliContext.setSv(sv);
}
validationEngine = buildValidationEngine(cliContext, definitions, tt);
}
ValidationEngine validationEngine = getValidationEngineFromCliContext(cliContext, definitions, tt);
sessionId = sessionCache.cacheSession(validationEngine);
System.out.println("Cached new session. Cache size = " + sessionCache.getSessionIds().size());
} else {
Expand All @@ -515,6 +498,28 @@ public String initializeValidator(CliContext cliContext, String definitions, Tim
return sessionId;
}

private ValidationEngine getValidationEngineFromCliContext(CliContext cliContext, String definitions, TimeTracker tt) throws Exception {
ValidationEngine validationEngine;
if (cliContext.getBaseEngine() != null && hasBaseEngineForKey(cliContext.getBaseEngine())) {
System.out.println("Building new validator engine from base engine: " + cliContext.getBaseEngine());
validationEngine = new ValidationEngine(getBaseEngine(cliContext.getBaseEngine()));
/* As a service, it wouldn't be efficient to have a base validation engine
* for every language. So we just use the baseEngine and set the language
* manually afterward.
*/
validationEngine.setLanguage(cliContext.getLang());
validationEngine.setLocale(cliContext.getLocale());
} else {
System.out.println("Building new validator engine from CliContext");
if (cliContext.getSv() == null) {
String sv = determineVersion(cliContext);
cliContext.setSv(sv);
}
validationEngine = buildValidationEngine(cliContext, definitions, tt);
}
return validationEngine;
}

protected ValidationEngine.ValidationEngineBuilder getValidationEngineBuilder() {
return new ValidationEngine.ValidationEngineBuilder();
}
Expand Down

0 comments on commit 563d6fe

Please sign in to comment.