use of org.drools.core.common.EqualityKey in project drools by kiegroup.
the class JTMSBeliefSystem method delete.
@Override
public void delete(M mode, RuleImpl rule, Activation activation, Object payload, BeliefSet<M> beliefSet, PropagationContext context) {
if (log.isTraceEnabled()) {
log.trace("TMSDelete {} {}", payload, mode.getValue());
}
JTMSBeliefSet<M> jtmsBeliefSet = (JTMSBeliefSet<M>) beliefSet;
boolean wasDecided = jtmsBeliefSet.isDecided();
boolean wasNegated = jtmsBeliefSet.isNegated();
InternalFactHandle fh = jtmsBeliefSet.getFactHandle();
beliefSet.remove(mode);
if (wasDecided && fh.isNegated() != beliefSet.isNegated()) {
// if it was decided, first remove it and re-add it. So it's in the correct map
ep.getObjectStore().removeHandle(fh);
fh.setNegated(beliefSet.isNegated());
ep.getObjectStore().addHandle(fh, fh.getObject());
} else {
fh.setNegated(beliefSet.isNegated());
}
if (beliefSet.isEmpty() && fh.getEqualityKey().getStatus() == EqualityKey.JUSTIFIED) {
// the set is empty, so delete form the EP, so things are cleaned up.
ep.delete(fh, fh.getObject(), getObjectTypeConf(beliefSet), context.getRuleOrigin(), null, activation != null ? activation.getTuple().getTupleSink() : null);
} else if (!(processBeliefSet(rule, activation, payload, context, jtmsBeliefSet, wasDecided, wasNegated, fh) && beliefSet.isEmpty())) {
// The state of the BS did not change, but maybe the prime did
if (fh.getObject() == payload) {
// prime, node.object which is the current fh.object, has changed and object is decided, so update
String value;
Object object = null;
if (jtmsBeliefSet.isNegated()) {
value = MODE.NEGATIVE.getId();
// Find the new node, and update the handle to it, Negatives iterate from the last
for (JTMSMode entry = (JTMSMode) jtmsBeliefSet.getLast(); entry != null; entry = (JTMSMode) entry.getPrevious()) {
if (entry.getValue().equals(value)) {
object = entry.getLogicalDependency().getObject();
break;
}
}
} else {
value = MODE.POSITIVE.getId();
// Find the new node, and update the handle to it, Positives iterate from the front
for (JTMSMode entry = jtmsBeliefSet.getFirst(); entry != null; entry = (JTMSMode) entry.getNext()) {
if (entry.getValue() == null || entry.getValue().equals(value)) {
object = entry.getLogicalDependency().getObject();
break;
}
}
}
// Equality might have changed on the object, so remove (which uses the handle id) and add back in
if (fh.getObject() != object) {
fh.getEntryPoint().getObjectStore().updateHandle(fh, object);
fh.getEntryPoint().update(fh, fh.getObject(), allSetButTraitBitMask(), object.getClass(), null);
}
}
}
if (beliefSet.isEmpty()) {
// if the beliefSet is empty, we must null the logical handle
EqualityKey key = fh.getEqualityKey();
key.setLogicalFactHandle(null);
key.setBeliefSet(null);
if (key.getStatus() == EqualityKey.JUSTIFIED) {
// if it's stated, there will be other handles, so leave it in the TMS
tms.remove(key);
}
}
}
Aggregations