Skip to content

Instantly share code, notes, and snippets.

@tkobayas
Created March 12, 2021 01:22
Show Gist options
  • Save tkobayas/1044be7c0760ed1c426a1b84157cc0d4 to your computer and use it in GitHub Desktop.
Save tkobayas/1044be7c0760ed1c426a1b84157cc0d4 to your computer and use it in GitHub Desktop.
fully synchronized MVELConditionEvaluator
protected boolean evaluate(InternalFactHandle handle, InternalWorkingMemory workingMemory, Tuple tuple) {
if (!jitted) {
int jittingThreshold = TEST_JITTING ? 0 : workingMemory.getKnowledgeBase().getConfiguration().getJittingThreshold();
if (conditionEvaluator == null) {
if (jittingThreshold == 0 && !isDynamic) { // Only for test purposes or when jitting is enforced at first evaluation
synchronized (this) {
if (conditionEvaluator == null) {
conditionEvaluator = forceJitEvaluator(handle, workingMemory, tuple);
}
}
} else {
synchronized (this) {
if (conditionEvaluator == null) {
conditionEvaluator = createMvelConditionEvaluator(workingMemory);
}
}
}
}
if (jittingThreshold != 0 && !isDynamic && invocationCounter.getAndIncrement() == jittingThreshold) {
jitEvaluator(handle, workingMemory, tuple);
}
}
try {
if (conditionEvaluator instanceof MVELConditionEvaluator) {
synchronized (this) {
return conditionEvaluator.evaluate(handle, workingMemory, tuple);
}
} else {
return conditionEvaluator.evaluate(handle, workingMemory, tuple);
}
} catch (Exception e) {
throw new RuntimeException("Error evaluating constraint '" + expression + "' in " + evaluationContext, e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment