public void execute(InternalWorkingMemory workingMemory) { final PropagationContext context = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(), PropagationContext.INSERTION, this.ruleOrigin, this.leftTuple, this.factHandle); ReteooRuleBase ruleBase = (ReteooRuleBase) workingMemory.getRuleBase(); ruleBase.assertObject(this.factHandle, this.factHandle.getObject(), context, workingMemory); context.evaluateActionQueue(workingMemory); }
public static PropagationContext createPropagationContextForFact( InternalWorkingMemory workingMemory, InternalFactHandle factHandle, int propagationType) { PropagationContextFactory pctxFactory = workingMemory .getKnowledgeBase() .getConfiguration() .getComponentFactory() .getPropagationContextFactory(); // if the fact is still in the working memory (since it may have been previously retracted // already return pctxFactory.createPropagationContext( workingMemory.getNextPropagationIdCounter(), propagationType, null, null, factHandle); }
public void execute(InternalWorkingMemory workingMemory) { InternalFactHandle factHandle = (InternalFactHandle) leftTuple.getObject(); if (node.isOpenQuery()) { // iterate to the query terminal node, as the child leftTuples will get picked up there workingMemory .getEntryPointNode() .retractObject( factHandle, context, workingMemory .getObjectTypeConfigurationRegistry() .getObjectTypeConf(workingMemory.getEntryPoint(), factHandle.getObject()), workingMemory); // workingMemory.getFactHandleFactory().destroyFactHandle( factHandle ); } else { // get child left tuples, as there is no open query if (leftTuple.getFirstChild() != null) { node.getSinkPropagator().propagateRetractLeftTuple(leftTuple, context, workingMemory); } } }
public void execute(InternalWorkingMemory workingMemory) { leftTuple.setLeftTupleSink(this.node); if (leftTuple.getFirstChild() == null) { this.node.assertLeftTuple(leftTuple, context, workingMemory); } else { if (retract) { this.node .getSinkPropagator() .propagateRetractLeftTuple(leftTuple, context, workingMemory); } else { this.node .getSinkPropagator() .propagateModifyChildLeftTuple(leftTuple, context, workingMemory, true); } } if (leftTuple.getLeftParent() == null) { // It's not an open query, as we aren't recording parent chains, so we need to clear out // right memory Object node = workingMemory.getNodeMemory(this.node); RightTupleMemory rightMemory = null; if (node instanceof BetaMemory) { rightMemory = ((BetaMemory) node).getRightTupleMemory(); } else if (node instanceof AccumulateMemory) { rightMemory = ((AccumulateMemory) node).betaMemory.getRightTupleMemory(); } final TupleStartEqualsConstraint constraint = TupleStartEqualsConstraint.getInstance(); TupleStartEqualsConstraintContextEntry contextEntry = new TupleStartEqualsConstraintContextEntry(); contextEntry.updateFromTuple(workingMemory, leftTuple); FastIterator rightIt = rightMemory.fastIterator(); RightTuple temp = null; for (RightTuple rightTuple = rightMemory.getFirst( leftTuple, (InternalFactHandle) context.getFactHandle(), rightIt); rightTuple != null; ) { temp = (RightTuple) rightIt.next(rightTuple); if (constraint.isAllowedCachedLeft(contextEntry, rightTuple.getFactHandle())) { rightMemory.remove(rightTuple); } rightTuple = temp; } } }
public void execute(InternalWorkingMemory workingMemory) { if (this.factHandle.isValid()) { // if the fact is still in the working memory (since it may have been previously retracted // already final PropagationContext context = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(), PropagationContext.EXPIRATION, null, null, this.factHandle); ((EventFactHandle) factHandle).setExpired(true); this.node.retractObject(factHandle, context, workingMemory); context.evaluateActionQueue(workingMemory); // if no activations for this expired event if (((EventFactHandle) factHandle).getActivationsCount() == 0) { // remove it from the object store and clean up resources ((EventFactHandle) factHandle).getEntryPoint().retract(factHandle); } context.evaluateActionQueue(workingMemory); } }
private void doRiaNode2( InternalWorkingMemory wm, LeftTupleSets srcTuples, RightInputAdapterNode riaNode, LinkedList<StackEntry> stack) { ObjectSink[] sinks = riaNode.getSinkPropagator().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; } // 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; } } } length--; // subtract one, as first is not in the array; for (LeftTuple leftTuple = srcTuples.getInsertFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); PropagationContext pctx = leftTuple.getPropagationContext(); InternalFactHandle handle = riaNode.createFactHandle(leftTuple, pctx, wm); RightTuple rightTuple = new RightTuple(handle, betaNode); leftTuple.setObject(rightTuple); rightTuple.setPropagationContext(pctx); bm.getStagedRightTuples().addInsert(rightTuple); if (bns != null) { // Add peered RightTuples, they are attached to FH - unlink LeftTuples that has a peer ref for (int i = 0; i < length; i++) { rightTuple = new RightTuple(handle, bns[i]); rightTuple.setPropagationContext(pctx); bms[i].getStagedRightTuples().addInsert(rightTuple); } } leftTuple.clearStaged(); leftTuple = next; } for (LeftTuple leftTuple = srcTuples.getDeleteFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); RightTuple rightTuple = (RightTuple) leftTuple.getObject(); RightTupleSets rightTuples = bm.getStagedRightTuples(); switch (rightTuple.getStagedType()) { case LeftTuple.INSERT: { rightTuples.removeInsert(rightTuple); break; } case LeftTuple.UPDATE: { rightTuples.removeUpdate(rightTuple); break; } } rightTuples.addDelete(rightTuple); if (bns != null) { // Add peered RightTuples, they are attached to FH - unlink LeftTuples that has a peer ref for (int i = 0; i < length; i++) { rightTuple = rightTuple.getHandleNext(); rightTuples = bms[i].getStagedRightTuples(); switch (rightTuple.getStagedType()) { case LeftTuple.INSERT: { rightTuples.removeInsert(rightTuple); break; } case LeftTuple.UPDATE: { rightTuples.removeUpdate(rightTuple); break; } } rightTuples.addDelete(rightTuple); } } leftTuple.clearStaged(); leftTuple = next; } for (LeftTuple leftTuple = srcTuples.getUpdateFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); RightTuple rightTuple = (RightTuple) leftTuple.getObject(); RightTupleSets rightTuples = bm.getStagedRightTuples(); switch (rightTuple.getStagedType()) { case LeftTuple.INSERT: { rightTuples.removeInsert(rightTuple); break; } case LeftTuple.UPDATE: { rightTuples.removeUpdate(rightTuple); break; } } rightTuples.addUpdate(rightTuple); if (bns != null) { // Add peered RightTuples, they are attached to FH - unlink LeftTuples that has a peer ref for (int i = 0; i < length; i++) { rightTuple = rightTuple.getHandleNext(); rightTuples = bms[i].getStagedRightTuples(); switch (rightTuple.getStagedType()) { case LeftTuple.INSERT: { rightTuples.removeInsert(rightTuple); break; } case LeftTuple.UPDATE: { rightTuples.removeUpdate(rightTuple); break; } } rightTuples.addUpdate(rightTuple); } } leftTuple.clearStaged(); leftTuple = next; } srcTuples.resetAll(); }
public void execute(InternalWorkingMemory workingMemory) { workingMemory.getEntryPointNode().modifyQuery(factHandle, context, workingMemory); }
public void execute(InternalWorkingMemory workingMemory) { // we null this as it blocks this query being called, to avoid re-entrant issues. i.e. // scheduling an insert and then an update, before the insert is executed ((DroolsQuery) this.factHandle.getObject()).setAction(null); workingMemory.getEntryPointNode().assertQuery(factHandle, context, workingMemory); }
public static ActivationIterator iterator(InternalWorkingMemory wm) { return new ActivationIterator(wm, new KnowledgeBaseImpl(wm.getRuleBase())); }