use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class PhreakQueryNode method doLeftInserts.
public void doLeftInserts(QueryElementNode queryNode, QueryElementNodeMemory qmem, StackEntry stackEntry, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples) {
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
PropagationContext pCtx = leftTuple.getPropagationContext();
InternalFactHandle handle = queryNode.createFactHandle(pCtx, wm, leftTuple);
DroolsQuery dquery = queryNode.createDroolsQuery(leftTuple, handle, stackEntry, qmem.getSegmentMemory().getPathMemories(), qmem, stackEntry.getSink(), wm);
LeftInputAdapterNode lian = (LeftInputAdapterNode) qmem.getQuerySegmentMemory().getRootNode();
LiaNodeMemory lm = (LiaNodeMemory) qmem.getQuerySegmentMemory().getNodeMemories().get(0);
LeftInputAdapterNode.doInsertObject(handle, pCtx, lian, wm, lm, false, dquery.isOpen());
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class PhreakQueryTerminalNode method doLeftInserts.
public void doLeftInserts(QueryTerminalNode qtnNode, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, LinkedList<StackEntry> stack) {
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
// qtnNode.assertLeftTuple( leftTuple, leftTuple.getPropagationContext(), wm );
PropagationContext pCtx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, leftTuple.getPropagationContext());
// find the DroolsQuery object
Tuple rootEntry = leftTuple.getRootTuple();
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().rowAdded(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 doLeftDelete.
public static void doLeftDelete(InternalAgenda agenda, RuleExecutor executor, Tuple leftTuple) {
PropagationContext pctx = leftTuple.getPropagationContext();
pctx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, pctx);
RuleTerminalNodeLeftTuple rtnLt = (RuleTerminalNodeLeftTuple) leftTuple;
rtnLt.setMatched(false);
agenda.cancelActivation(leftTuple, pctx, rtnLt, rtnLt.getTerminalNode());
if (leftTuple.getMemory() != null) {
// Expiration propagations should not be removed from the list, as they still need to fire
executor.removeLeftTuple(leftTuple);
}
leftTuple.setContextObject(null);
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class PhreakRuleTerminalNode method doLeftTupleUpdate.
public static void doLeftTupleUpdate(TerminalNode rtnNode, RuleExecutor executor, InternalAgenda agenda, int salienceInt, Salience salience, LeftTuple leftTuple) {
PropagationContext pctx = leftTuple.getPropagationContext();
pctx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, pctx);
boolean blocked = false;
RuleTerminalNodeLeftTuple rtnLeftTuple = (RuleTerminalNodeLeftTuple) leftTuple;
if (executor.isDeclarativeAgendaEnabled()) {
if (rtnLeftTuple.getBlockers() != null && !rtnLeftTuple.getBlockers().isEmpty()) {
// declarativeAgenda still blocking LeftTuple, so don't add back ot list
blocked = true;
}
} else {
blocked = rtnNode.getRule().isNoLoop() && rtnNode.equals(pctx.getTerminalNodeOrigin());
}
InternalWorkingMemory wm = agenda.getWorkingMemory();
if (salience != null) {
salienceInt = salience.getValue(new DefaultKnowledgeHelper(rtnLeftTuple, wm), rtnNode.getRule(), wm);
}
if (agenda.getActivationsFilter() != null && !agenda.getActivationsFilter().accept(rtnLeftTuple, wm, rtnNode)) {
// only relevant for serialization, to not re-fire Matches already fired
return;
}
if (!blocked) {
boolean addToExector = true;
if (rtnNode.getRule().isLockOnActive() && pctx.getType() != PropagationContext.Type.RULE_ADDITION) {
long handleRecency = pctx.getFactHandle().getRecency();
InternalAgendaGroup agendaGroup = executor.getRuleAgendaItem().getAgendaGroup();
if (blockedByLockOnActive(rtnNode.getRule(), pctx, handleRecency, agendaGroup)) {
addToExector = false;
}
}
if (addToExector) {
if (!rtnLeftTuple.isQueued()) {
// not queued, so already fired, so it's effectively recreated
EventSupport es = (EventSupport) wm;
es.getAgendaEventSupport().fireActivationCreated(rtnLeftTuple, wm);
rtnLeftTuple.update(salienceInt, pctx);
executor.addLeftTuple(leftTuple);
wm.getRuleEventSupport().onUpdateMatch(rtnLeftTuple);
}
}
} else {
// LeftTuple is blocked, and thus not queued, so just update it's values
rtnLeftTuple.update(salienceInt, pctx);
}
if (!rtnNode.isFireDirect() && executor.isDeclarativeAgendaEnabled()) {
agenda.modifyActivation(rtnLeftTuple, rtnLeftTuple.isQueued());
}
}
use of org.drools.core.spi.PropagationContext in project drools by kiegroup.
the class PhreakTimerNode method doLeftDeletes.
public void doLeftDeletes(TimerNode timerNode, TimerNodeMemory tm, PathMemory pmem, LeftTupleSink sink, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
TimerService timerService = agenda.getWorkingMemory().getTimerService();
TupleList leftTuples = tm.getInsertOrUpdateLeftTuples();
TupleList deletes = tm.getDeleteLeftTuples();
if (!deletes.isEmpty()) {
for (LeftTuple leftTuple = (LeftTuple) deletes.getFirst(); leftTuple != null; ) {
LeftTuple next = (LeftTuple) leftTuple.getNext();
srcLeftTuples.addDelete(leftTuple);
if (log.isTraceEnabled()) {
log.trace("Timer Add Postponed Delete {}", leftTuple);
}
leftTuple.clear();
leftTuple = next;
}
deletes.clear();
}
for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
PropagationContext pctx = leftTuple.getPropagationContext();
Object obj = leftTuple.getContextObject();
if (obj instanceof DefaultJobHandle) {
timerService.removeJob((DefaultJobHandle) obj);
} else if (obj instanceof TupleKey && pctx.getReaderContext() != null) {
pctx.getReaderContext().removeTimerNodeScheduler(timerNode.getId(), (TupleKey) obj);
}
pctx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, pctx);
if (leftTuple.getMemory() != null) {
// it gets removed either way.
leftTuples.remove(leftTuple);
if (pctx.getFactHandle().isExpired()) {
// a expire clashes with insert or update, allow it to propagate once, will handle the expire the second time around
doPropagateChildLeftTuple(sink, trgLeftTuples, stagedLeftTuples, leftTuple);
tm.getDeleteLeftTuples().add(leftTuple);
// make sure it's dirty, so it'll evaluate again
pmem.doLinkRule(agenda);
if (log.isTraceEnabled()) {
log.trace("Timer Postponed Delete {}", leftTuple);
}
}
}
if (leftTuple.getMemory() == null) {
// if it's != null, then it's already been postponed, and the existing child propagated
// only has one child
LeftTuple childLeftTuple = leftTuple.getFirstChild();
if (childLeftTuple != null) {
childLeftTuple.setPropagationContext(leftTuple.getPropagationContext());
RuleNetworkEvaluator.deleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
if (log.isTraceEnabled()) {
log.trace("Timer Delete {}", leftTuple);
}
}
}
leftTuple.clearStaged();
leftTuple = next;
}
}
Aggregations