Skip to content

Instantly share code, notes, and snippets.

@ge0ffrey
Created December 16, 2011 15:59
Show Gist options
  • Save ge0ffrey/1486586 to your computer and use it in GitHub Desktop.
Save ge0ffrey/1486586 to your computer and use it in GitHub Desktop.
private static Method hackMethod;
static {
try {
hackMethod = Class.forName("org.drools.planner.core.score.buildin.simple.SimpleScoreCalculator").getMethod("increment");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("No such class", e);
} catch (NoSuchMethodException e) {
throw new IllegalStateException("No such method", e);
}
}
...
public void retractLeftTuple(final LeftTuple leftTuple,
final PropagationContext context,
final InternalWorkingMemory workingMemory) {
final Activation activation = (Activation) leftTuple.getObject();
// activation can be null if the LeftTuple previous propagated into a no-loop
if ( activation == null ) {
return;
}
final DefaultAgenda agenda = (DefaultAgenda) workingMemory.getAgenda();
AgendaItem item = ( AgendaItem ) activation;
item.removeAllBlockersAndBlocked(agenda);
if ( agenda.isDeclarativeAgenda() && activation.getFactHandle() == null ) {
// This a control rule activation, nothing to do except update counters. As control rules are not in agenda-groups etc.
agenda.decreaseDormantActivations(); // because we know ControlRules fire straight away and then become dormant
return;
} else {
// we are retracting an actual Activation, so also remove it and it's handle from the WM.
agenda.removeActivation( (AgendaItem) activation );
}
if ( activation.isActivated() ) {
// on fact expiration, we don't remove the activation, but let it fire
if ( context.getType() == PropagationContext.EXPIRATION && context.getFactHandleOrigin() != null ) {
} else {
activation.remove();
if ( activation.getActivationGroupNode() != null ) {
activation.getActivationGroupNode().getActivationGroup().removeActivation( activation );
}
if ( activation.getActivationNode() != null ) {
final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) activation.getActivationNode().getParentContainer();
ruleFlowGroup.removeActivation( activation );
}
leftTuple.decreaseActivationCountForEvents();
((EventSupport) workingMemory).getAgendaEventSupport().fireActivationCancelled( activation,
workingMemory,
ActivationCancelledCause.WME_MODIFY );
agenda.decreaseActiveActivations();
}
} else {
agenda.decreaseDormantActivations();
}
// ge0ffrey stuff start <===================================
Object scoreCalculator = workingMemory.getGlobal("scoreCalculator");
try {
hackMethod.invoke(scoreCalculator);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Problem invoking method", e);
} catch (InvocationTargetException e) {
throw new IllegalStateException("Problem invoking method", e);
}
// ge0ffrey stuff stop <===================================
workingMemory.getTruthMaintenanceSystem().removeLogicalDependencies( activation,
context,
this.rule );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment