Search in sources :

Example 31 with PropagationContext

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;
    }
}
Also used : PropagationContext(org.drools.core.spi.PropagationContext) LeftTuple(org.drools.core.reteoo.LeftTuple) DroolsQuery(org.drools.core.base.DroolsQuery)

Example 32 with PropagationContext

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;
    }
}
Also used : PropagationContext(org.drools.core.spi.PropagationContext) LeftTuple(org.drools.core.reteoo.LeftTuple) DroolsQuery(org.drools.core.base.DroolsQuery)

Example 33 with PropagationContext

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);
    }
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) InternalAgendaGroup(org.drools.core.common.InternalAgendaGroup) PropagationContext(org.drools.core.spi.PropagationContext) EventSupport(org.drools.core.common.EventSupport) DefaultKnowledgeHelper(org.drools.core.base.DefaultKnowledgeHelper) RuleTerminalNodeLeftTuple(org.drools.core.reteoo.RuleTerminalNodeLeftTuple)

Example 34 with PropagationContext

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));
    }
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) PropagationContext(org.drools.core.spi.PropagationContext) ReactiveFromNode(org.drools.core.reteoo.ReactiveFromNode) LeftTupleSinkNode(org.drools.core.reteoo.LeftTupleSinkNode) ReactiveFromNodeLeftTuple(org.drools.core.reteoo.ReactiveFromNodeLeftTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) PhreakFromNode.deleteChildLeftTuple(org.drools.core.phreak.PhreakFromNode.deleteChildLeftTuple) Tuple(org.drools.core.spi.Tuple) ReactiveFromNodeLeftTuple(org.drools.core.reteoo.ReactiveFromNodeLeftTuple)

Example 35 with PropagationContext

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);
            }
        }
    }
}
Also used : PropagationContext(org.drools.core.spi.PropagationContext) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) InternalFactHandle(org.drools.core.common.InternalFactHandle) Thing(org.drools.core.factmodel.traits.Thing)

Aggregations

PropagationContext (org.drools.core.spi.PropagationContext)35 PropagationContextFactory (org.drools.core.common.PropagationContextFactory)8 LeftTuple (org.drools.core.reteoo.LeftTuple)8 DroolsQuery (org.drools.core.base.DroolsQuery)6 InternalFactHandle (org.drools.core.common.InternalFactHandle)6 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)6 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)4 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)4 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)3 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)3 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)3 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)2 DefaultKnowledgeHelper (org.drools.core.base.DefaultKnowledgeHelper)2 BetaConstraints (org.drools.core.common.BetaConstraints)2 EventFactHandle (org.drools.core.common.EventFactHandle)2 EventSupport (org.drools.core.common.EventSupport)2