use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class PhreakQueryTerminalNode method doLeftUpdates.
public void doLeftUpdates(QueryTerminalNode qtnNode, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, LinkedList<StackEntry> stack) {
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
PropagationContext pCtx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, leftTuple.getPropagationContext());
// qtnNode.modifyLeftTuple( leftTuple, leftTuple.getPropagationContext(), wm );
LeftTuple rootEntry = leftTuple;
// find the DroolsQuery object
while (rootEntry.getParent() != null) {
rootEntry = rootEntry.getParent();
}
DroolsQuery dquery = (DroolsQuery) rootEntry.getFactHandle().getObject();
dquery.setQuery(qtnNode.getQuery());
if (dquery.getStackEntry() != null) {
checkAndTriggerQueryReevaluation(agenda, stack, rootEntry, dquery);
}
// Add results to the adapter
dquery.getQueryResultCollector().rowUpdated(qtnNode.getQuery(), leftTuple, pCtx, agenda.getWorkingMemory());
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class PhreakQueryTerminalNode method doLeftDeletes.
public void doLeftDeletes(QueryTerminalNode qtnNode, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, LinkedList<StackEntry> stack) {
for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
// qtnNode.retractLeftTuple( leftTuple, leftTuple.getPropagationContext(), wm );
PropagationContext pCtx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, leftTuple.getPropagationContext());
LeftTuple rootEntry = leftTuple;
// find the DroolsQuery object
while (rootEntry.getParent() != null) {
rootEntry = rootEntry.getParent();
}
DroolsQuery dquery = (DroolsQuery) rootEntry.getFactHandle().getObject();
dquery.setQuery(qtnNode.getQuery());
if (dquery.getStackEntry() != null) {
checkAndTriggerQueryReevaluation(agenda, stack, rootEntry, dquery);
}
// Add results to the adapter
dquery.getQueryResultCollector().rowRemoved(qtnNode.getQuery(), leftTuple, pCtx, agenda.getWorkingMemory());
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class PhreakRuleTerminalNode method doLeftTupleInsert.
public static void doLeftTupleInsert(TerminalNode rtnNode, RuleExecutor executor, InternalAgenda agenda, RuleAgendaItem ruleAgendaItem, int salienceInt, Salience salience, LeftTuple leftTuple) {
PropagationContext pctx = leftTuple.getPropagationContext();
pctx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, pctx);
if (rtnNode.getRule().isNoLoop() && rtnNode.equals(pctx.getTerminalNodeOrigin())) {
return;
}
InternalWorkingMemory wm = agenda.getWorkingMemory();
if (salience != null) {
salienceInt = salience.getValue(new DefaultKnowledgeHelper((AgendaItem) leftTuple, wm), rtnNode.getRule(), wm);
}
RuleTerminalNodeLeftTuple rtnLeftTuple = (RuleTerminalNodeLeftTuple) leftTuple;
agenda.createAgendaItem(rtnLeftTuple, salienceInt, pctx, ruleAgendaItem, ruleAgendaItem.getAgendaGroup());
EventSupport es = (EventSupport) wm;
es.getAgendaEventSupport().fireActivationCreated(rtnLeftTuple, wm);
if (rtnNode.getRule().isLockOnActive() && leftTuple.getPropagationContext().getType() != PropagationContext.Type.RULE_ADDITION) {
long handleRecency = pctx.getFactHandle().getRecency();
InternalAgendaGroup agendaGroup = executor.getRuleAgendaItem().getAgendaGroup();
if (blockedByLockOnActive(rtnNode.getRule(), pctx, handleRecency, agendaGroup)) {
es.getAgendaEventSupport().fireActivationCancelled(rtnLeftTuple, wm, MatchCancelledCause.FILTER);
return;
}
}
if (agenda.getActivationsFilter() != null && !agenda.getActivationsFilter().accept(rtnLeftTuple, wm, rtnNode)) {
// only relevant for seralization, to not refire Matches already fired
return;
}
agenda.addItemToActivationGroup(rtnLeftTuple);
executor.addLeftTuple(leftTuple);
// increased here, decreased in Agenda's cancelActivation and fireActivation
leftTuple.increaseActivationCountForEvents();
if (!rtnNode.isFireDirect() && executor.isDeclarativeAgendaEnabled()) {
agenda.insertAndStageActivation(rtnLeftTuple);
}
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class ReactiveObjectUtil method notifyModification.
public static void notifyModification(Object object, Collection<Tuple> leftTuples, ModificationType type) {
for (Tuple leftTuple : leftTuples) {
if (!((ReactiveFromNodeLeftTuple) leftTuple).updateModificationState(object, type)) {
continue;
}
PropagationContext propagationContext = leftTuple.getPropagationContext();
ReactiveFromNode node = (ReactiveFromNode) leftTuple.getTupleSink();
LeftTupleSinkNode sink = node.getSinkPropagator().getFirstLeftTupleSink();
InternalWorkingMemory wm = getInternalWorkingMemory(propagationContext);
wm.addPropagation(new ReactivePropagation(object, (ReactiveFromNodeLeftTuple) leftTuple, propagationContext, node, sink, type));
}
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class TraitHelper method updateManyTraits.
private void updateManyTraits(Object object, BitMask mask, Collection<Thing> originators, Class<?> modifiedClass, Collection<Thing> traits, Activation activation) {
for (Thing t : traits) {
if (!originators.contains(t)) {
InternalFactHandle h = (InternalFactHandle) lookupFactHandle(t);
if (h != null) {
NamedEntryPoint nep = (NamedEntryPoint) h.getEntryPoint();
PropagationContext propagationContext = nep.getPctxFactory().createPropagationContext(nep.getInternalWorkingMemory().getNextPropagationIdCounter(), PropagationContext.Type.MODIFICATION, activation != null ? activation.getRule() : null, activation != null ? activation.getTuple().getTupleSink() : null, h, nep.getEntryPoint(), mask, modifiedClass, null);
nep.update(h, t, t, nep.getObjectTypeConfigurationRegistry().getObjectTypeConf(nep.getEntryPoint(), t), propagationContext);
}
}
}
}
Aggregations