Java Code Examples for org.drools.core.impl.InternalKnowledgeBase#hasSegmentPrototypes()
The following examples show how to use
org.drools.core.impl.InternalKnowledgeBase#hasSegmentPrototypes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddRemoveRule.java From kogito-runtimes with Apache License 2.0 | 4 votes |
/** * This method is called after the rule nodes have been added to the network * For add tuples are processed after the segments and pmems have been adjusted */ public static void addRule(TerminalNode tn, Collection<InternalWorkingMemory> wms, InternalKnowledgeBase kBase) { if (log.isTraceEnabled()) { log.trace("Adding Rule {}", tn.getRule().getName()); } boolean hasProtos = kBase.hasSegmentPrototypes(); boolean hasWms = !wms.isEmpty(); if (!hasProtos && !hasWms) { return; } RuleImpl rule = tn.getRule(); LeftTupleNode firstSplit = getNetworkSplitPoint(tn); PathEndNodes pathEndNodes = getPathEndNodes(kBase, firstSplit, tn, rule, hasProtos, hasWms); // Insert the facts for the new paths. This will iterate each new path from EndNode to the splitStart - but will not process the splitStart itself (as tha already exist). // It does not matter that the prior segments have not yet been processed for splitting, as this will only apply for branches of paths that did not exist before for (InternalWorkingMemory wm : wms) { wm.flushPropagations(); if (NodeTypeEnums.LeftInputAdapterNode == firstSplit.getType() && firstSplit.getAssociationsSize() == 1) { // rule added with no sharing insertLiaFacts(firstSplit, wm); } else { PathEndNodeMemories tnms = getPathEndMemories(wm, pathEndNodes); if (tnms.subjectPmem == null) { // If the existing PathMemories are not yet initialized there are no Segments or tuples to process continue; } Map<PathMemory, SegmentMemory[]> prevSmemsLookup = reInitPathMemories(tnms.otherPmems, null); // must collect all visited SegmentMemories, for link notification Set<SegmentMemory> smemsToNotify = handleExistingPaths(tn, prevSmemsLookup, tnms.otherPmems, wm, ExistingPathStrategy.ADD_STRATEGY); addNewPaths(wm, smemsToNotify, tnms.subjectPmems); processLeftTuples(firstSplit, wm, true, rule); notifySegments(smemsToNotify, wm); } } if (hasWms) { insertFacts( pathEndNodes, wms ); } else { for (PathEndNode node : pathEndNodes.otherEndNodes) { node.resetPathMemSpec(null); } } }
Example 2
Source File: AddRemoveRule.java From kogito-runtimes with Apache License 2.0 | 4 votes |
/** * This method is called before the rule nodes are removed from the network. * For remove tuples are processed before the segments and pmems have been adjusted */ public static void removeRule( TerminalNode tn, Collection<InternalWorkingMemory> wms, InternalKnowledgeBase kBase) { if (log.isTraceEnabled()) { log.trace("Removing Rule {}", tn.getRule().getName()); } boolean hasProtos = kBase.hasSegmentPrototypes(); boolean hasWms = !wms.isEmpty(); if (!hasProtos && !hasWms) { return; } RuleImpl rule = tn.getRule(); LeftTupleNode firstSplit = getNetworkSplitPoint(tn); PathEndNodes pathEndNodes = getPathEndNodes(kBase, firstSplit, tn, rule, hasProtos, hasWms); for (InternalWorkingMemory wm : wms) { wm.flushPropagations(); PathEndNodeMemories tnms = getPathEndMemories(wm, pathEndNodes); if ( !tnms.subjectPmems.isEmpty() ) { if (NodeTypeEnums.LeftInputAdapterNode == firstSplit.getType() && firstSplit.getAssociationsSize() == 1) { if (tnms.subjectPmem != null) { flushStagedTuples(firstSplit, tnms.subjectPmem, wm); } processLeftTuples(firstSplit, wm, false, tn.getRule()); removeNewPaths(wm, tnms.subjectPmems); } else { flushStagedTuples(tn, tnms.subjectPmem, pathEndNodes, wm); processLeftTuples(firstSplit, wm, false, tn.getRule()); removeNewPaths(wm, tnms.subjectPmems); Map<PathMemory, SegmentMemory[]> prevSmemsLookup = reInitPathMemories(tnms.otherPmems, tn); // must collect all visited SegmentMemories, for link notification Set<SegmentMemory> smemsToNotify = handleExistingPaths(tn, prevSmemsLookup, tnms.otherPmems, wm, ExistingPathStrategy.REMOVE_STRATEGY); notifySegments(smemsToNotify, wm); } } if (tnms.subjectPmem != null && tnms.subjectPmem.isInitialized() && tnms.subjectPmem.getRuleAgendaItem().isQueued()) { // SubjectPmem can be null, if it was never initialized tnms.subjectPmem.getRuleAgendaItem().dequeue(); } } if (!hasWms) { for (PathEndNode node : pathEndNodes.otherEndNodes) { node.resetPathMemSpec(null); } } }