use of org.drools.core.reteoo.SubnetworkTuple in project drools by kiegroup.
the class RuleNetworkEvaluator method doRiaNode2.
private void doRiaNode2(InternalWorkingMemory wm, TupleSets<LeftTuple> srcTuples, RightInputAdapterNode riaNode) {
ObjectSink[] sinks = riaNode.getObjectSinkPropagator().getSinks();
BetaNode betaNode = (BetaNode) sinks[0];
BetaMemory bm;
Memory nodeMem = wm.getNodeMemory(betaNode);
if (NodeTypeEnums.AccumulateNode == betaNode.getType()) {
bm = ((AccumulateMemory) nodeMem).getBetaMemory();
} else {
bm = (BetaMemory) nodeMem;
}
TupleSets<RightTuple> rightTuples = bm.getStagedRightTuples();
// Build up iteration array for other sinks
BetaNode[] bns = null;
BetaMemory[] bms = null;
int length = sinks.length;
if (length > 1) {
bns = new BetaNode[sinks.length - 1];
bms = new BetaMemory[sinks.length - 1];
for (int i = 1; i < length; i++) {
bns[i - 1] = (BetaNode) sinks[i];
Memory nodeMem2 = wm.getNodeMemory(bns[i - 1]);
if (NodeTypeEnums.AccumulateNode == betaNode.getType()) {
bms[i - 1] = ((AccumulateMemory) nodeMem2).getBetaMemory();
} else {
bms[i - 1] = (BetaMemory) nodeMem2;
}
}
}
// subtract one, as first is not in the array;
length--;
for (SubnetworkTuple subnetworkTuple = (SubnetworkTuple) srcTuples.getInsertFirst(); subnetworkTuple != null; ) {
SubnetworkTuple next = (SubnetworkTuple) subnetworkTuple.getStagedNext();
if (bm.getStagedRightTuples().isEmpty()) {
bm.setNodeDirtyWithoutNotify();
}
subnetworkTuple.prepareStagingOnRight();
rightTuples.addInsert(subnetworkTuple);
if (bns != null) {
for (int i = 0; i < length; i++) {
if (bms[i].getStagedRightTuples().isEmpty()) {
bms[i].setNodeDirtyWithoutNotify();
}
subnetworkTuple = riaNode.createPeer(subnetworkTuple);
bms[i].getStagedRightTuples().addInsert(subnetworkTuple);
}
}
subnetworkTuple = next;
}
for (SubnetworkTuple subnetworkTuple = (SubnetworkTuple) srcTuples.getDeleteFirst(); subnetworkTuple != null; ) {
SubnetworkTuple next = (SubnetworkTuple) subnetworkTuple.getStagedNext();
if (rightTuples.isEmpty()) {
bm.setNodeDirtyWithoutNotify();
}
switch(subnetworkTuple.getStagedTypeOnRight()) {
// handle clash with already staged entries
case Tuple.INSERT:
rightTuples.removeInsert(subnetworkTuple);
break;
case Tuple.UPDATE:
rightTuples.removeUpdate(subnetworkTuple);
break;
}
subnetworkTuple.prepareStagingOnRight();
rightTuples.addDelete(subnetworkTuple);
if (bns != null) {
for (int i = 0; i < length; i++) {
subnetworkTuple = (SubnetworkTuple) subnetworkTuple.getPeer();
if (bms[i].getStagedRightTuples().isEmpty()) {
bms[i].setNodeDirtyWithoutNotify();
}
bms[i].getStagedRightTuples().addDelete(subnetworkTuple);
subnetworkTuple.setStagedOnRight();
}
}
subnetworkTuple = next;
}
for (SubnetworkTuple subnetworkTuple = (SubnetworkTuple) srcTuples.getUpdateFirst(); subnetworkTuple != null; ) {
SubnetworkTuple next = (SubnetworkTuple) subnetworkTuple.getStagedNext();
if (rightTuples.isEmpty()) {
bm.setNodeDirtyWithoutNotify();
}
subnetworkTuple.prepareStagingOnRight();
rightTuples.addUpdate(subnetworkTuple);
if (bns != null) {
for (int i = 0; i < length; i++) {
subnetworkTuple = (SubnetworkTuple) subnetworkTuple.getPeer();
if (bms[i].getStagedRightTuples().isEmpty()) {
bms[i].setNodeDirtyWithoutNotify();
}
bms[i].getStagedRightTuples().addUpdate(subnetworkTuple);
subnetworkTuple.setStagedOnRight();
}
}
subnetworkTuple = next;
}
srcTuples.resetAll();
}
use of org.drools.core.reteoo.SubnetworkTuple in project drools by kiegroup.
the class AddRemoveRulesTest method testRemoveRuleWithSharedRia.
@Test
public void testRemoveRuleWithSharedRia() {
final String rule1Name = "rule1";
final String rule2Name = "rule2";
final String rule1 = "rule " + rule1Name + " \n" + "when \n" + " Integer() \n" + " not(Integer() and Integer()) \n" + "then \n" + "System.out.println('test rule 1'); \n" + "end";
final String rule2 = "rule " + rule2Name + " \n" + "when \n" + " Integer() \n" + " exists(Integer() and Integer()) \n" + "then \n" + "System.out.println('test rule 2'); \n" + "end";
final KieSession session = base.newKieSession();
this.addRuleToEngine(rule1);
final InternalFactHandle fh = (InternalFactHandle) session.insert(1);
session.fireAllRules();
this.addRuleToEngine(rule2);
final SubnetworkTuple tuple = (SubnetworkTuple) fh.getFirstLeftTuple().getFirstChild().getFirstChild();
assertNotNull(tuple.getPeer());
this.deleteRule(rule2Name);
assertNull(tuple.getPeer());
}
Aggregations