use of com.googlecode.prolog_cafe.lang.PrologMachineCopy in project gerrit by GerritCodeReview.
the class RulesCache method createMachine.
private PrologMachineCopy createMachine(Project.NameKey project, ObjectId rulesId) throws CompileException {
//
if (rulesDir != null) {
Path jarPath = rulesDir.resolve("rules-" + rulesId.getName() + ".jar");
if (Files.isRegularFile(jarPath)) {
URL[] cp = new URL[] { toURL(jarPath) };
return save(newEmptyMachine(new URLClassLoader(cp, systemLoader)));
}
}
// Dynamically consult the rules into the machine's internal database.
//
String rules = read(project, rulesId);
PrologMachineCopy pmc = consultRules("rules.pl", new StringReader(rules));
if (pmc == null) {
throw new CompileException("Cannot consult rules of " + project);
}
return pmc;
}
use of com.googlecode.prolog_cafe.lang.PrologMachineCopy in project gerrit by GerritCodeReview.
the class ProjectState method newPrologEnvironment.
/** @return Construct a new PrologEnvironment for the calling thread. */
public PrologEnvironment newPrologEnvironment() throws CompileException {
PrologMachineCopy pmc = rulesMachine;
if (pmc == null) {
pmc = rulesCache.loadMachine(getProject().getNameKey(), config.getRulesId());
rulesMachine = pmc;
}
return envFactory.create(pmc);
}
use of com.googlecode.prolog_cafe.lang.PrologMachineCopy in project gerrit by GerritCodeReview.
the class RulesCache method loadMachine.
/**
* Locate a cached Prolog machine state, or create one if not available.
*
* @return a Prolog machine, after loading the specified rules.
* @throws CompileException the machine cannot be created.
*/
public synchronized PrologMachineCopy loadMachine(Project.NameKey project, ObjectId rulesId) throws CompileException {
if (!enableProjectRules || project == null || rulesId == null) {
return defaultMachine;
}
Reference<? extends PrologMachineCopy> ref = machineCache.get(rulesId);
if (ref != null) {
PrologMachineCopy pmc = ref.get();
if (pmc != null) {
return pmc;
}
machineCache.remove(rulesId);
ref.enqueue();
}
gc();
PrologMachineCopy pcm = createMachine(project, rulesId);
MachineRef newRef = new MachineRef(rulesId, pcm, dead);
machineCache.put(rulesId, newRef);
return pcm;
}
Aggregations