use of org.drools.core.reteoo.SegmentMemory in project drools by kiegroup.
the class SegmentPropagator method processPeers.
private static void processPeers(SegmentMemory sourceSegment, TupleSets<LeftTuple> leftTuples, InternalWorkingMemory wm) {
SegmentMemory firstSmem = sourceSegment.getFirst();
// Process Deletes
processPeerDeletes(leftTuples, leftTuples.getDeleteFirst(), firstSmem, wm);
processPeerDeletes(leftTuples, leftTuples.getNormalizedDeleteFirst(), firstSmem, wm);
// Process Updates
for (LeftTuple leftTuple = leftTuples.getUpdateFirst(); leftTuple != null; leftTuple = leftTuple.getStagedNext()) {
SegmentMemory smem = firstSmem.getNext();
if (smem != null) {
for (LeftTuple peer = leftTuple.getPeer(); peer != null; peer = peer.getPeer()) {
// only stage, if not already staged, if insert, leave as insert
if (peer.getStagedType() == LeftTuple.NONE) {
peer.setPropagationContext(leftTuple.getPropagationContext());
smem.getStagedLeftTuples().addUpdate(peer);
}
smem = smem.getNext();
}
}
}
// Process Inserts
for (LeftTuple leftTuple = leftTuples.getInsertFirst(); leftTuple != null; leftTuple = leftTuple.getStagedNext()) {
SegmentMemory smem = firstSmem.getNext();
if (smem != null) {
LeftTuple peer = leftTuple;
for (; smem != null; smem = smem.getNext()) {
if (peer.getPeer() != null) {
// if the tuple already has a peer avoid to create a new one ...
peer = peer.getPeer();
peer.setPropagationContext(leftTuple.getPropagationContext());
// ... and update the staged LeftTupleSets according to its current staged state
PhreakJoinNode.updateChildLeftTuple(peer, smem.getStagedLeftTuples(), smem.getStagedLeftTuples());
} else {
peer = ((LeftTupleSink) smem.getRootNode()).createPeer(peer);
smem.getStagedLeftTuples().addInsert(peer);
if (smem.hasDataDrivenPathMemories()) {
for (PathMemory dataDrivenPmem : smem.getDataDrivenPathMemories()) {
// on insert only totally linked pmems need to be flushed
if (dataDrivenPmem.isRuleLinked()) {
forceFlushLeftTuple(dataDrivenPmem, smem, wm, smem.getStagedLeftTuples());
break;
}
}
}
}
}
}
}
firstSmem.getStagedLeftTuples().addAll(leftTuples);
leftTuples.resetAll();
}
use of org.drools.core.reteoo.SegmentMemory in project drools by kiegroup.
the class SegmentPropagator method processPeerDeletes.
private static void processPeerDeletes(TupleSets<LeftTuple> leftTuples, LeftTuple leftTuple, SegmentMemory firstSmem, InternalWorkingMemory wm) {
for (; leftTuple != null; leftTuple = leftTuple.getStagedNext()) {
SegmentMemory smem = firstSmem.getNext();
if (smem != null) {
for (LeftTuple peer = leftTuple.getPeer(); peer != null; peer = peer.getPeer()) {
peer.setPropagationContext(leftTuple.getPropagationContext());
TupleSets<LeftTuple> stagedLeftTuples = smem.getStagedLeftTuples();
// if the peer is already staged as insert or update the LeftTupleSets will reconcile it internally
stagedLeftTuples.addDelete(peer);
if (smem.hasDataDrivenPathMemories()) {
forceFlushLeftTuple(smem.getFirstDataDrivenPathMemory(), smem, wm, smem.getStagedLeftTuples());
}
smem = smem.getNext();
}
}
}
}
use of org.drools.core.reteoo.SegmentMemory in project drools by kiegroup.
the class SegmentUtilities method createRiaSegmentMemory.
private static RightInputAdapterNode createRiaSegmentMemory(BetaNode betaNode, InternalWorkingMemory wm) {
RightInputAdapterNode riaNode = (RightInputAdapterNode) betaNode.getRightInput();
LeftTupleSource subnetworkLts = riaNode.getLeftTupleSource();
while (subnetworkLts.getLeftTupleSource() != riaNode.getStartTupleSource()) {
subnetworkLts = subnetworkLts.getLeftTupleSource();
}
Memory rootSubNetwokrMem = wm.getNodeMemory((MemoryFactory) subnetworkLts);
SegmentMemory subNetworkSegmentMemory = rootSubNetwokrMem.getSegmentMemory();
if (subNetworkSegmentMemory == null) {
// we need to stop recursion here
createSegmentMemory(subnetworkLts, rootSubNetwokrMem, wm);
}
return riaNode;
}
use of org.drools.core.reteoo.SegmentMemory in project drools by kiegroup.
the class SegmentUtilities method processQueryNode.
private static boolean processQueryNode(QueryElementNode queryNode, InternalWorkingMemory wm, LeftTupleSource segmentRoot, SegmentMemory smem, long nodePosMask) {
// Initialize the QueryElementNode and have it's memory reference the actual query SegmentMemory
SegmentMemory querySmem = getQuerySegmentMemory(wm, segmentRoot, queryNode);
QueryElementNodeMemory queryNodeMem = smem.createNodeMemory(queryNode, wm);
queryNodeMem.setNodePosMaskBit(nodePosMask);
queryNodeMem.setQuerySegmentMemory(querySmem);
queryNodeMem.setSegmentMemory(smem);
return !queryNode.getQueryElement().isAbductive();
}
use of org.drools.core.reteoo.SegmentMemory in project drools by kiegroup.
the class SegmentUtilities method getQuerySegmentMemory.
public static SegmentMemory getQuerySegmentMemory(InternalWorkingMemory wm, LeftTupleSource segmentRoot, QueryElementNode queryNode) {
LeftInputAdapterNode liaNode = getQueryLiaNode(queryNode.getQueryElement().getQueryName(), getQueryOtn(segmentRoot));
LiaNodeMemory liam = wm.getNodeMemory(liaNode);
SegmentMemory querySmem = liam.getSegmentMemory();
if (querySmem == null) {
querySmem = createSegmentMemory(liaNode, liam, wm);
}
return querySmem;
}
Aggregations