use of org.drools.core.reteoo.ObjectSource in project drools by kiegroup.
the class SegmentUtilities method getQueryOtn.
private static ObjectTypeNode getQueryOtn(LeftTupleSource lts) {
while (!(lts instanceof LeftInputAdapterNode)) {
lts = lts.getLeftTupleSource();
}
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) lts;
ObjectSource os = liaNode.getObjectSource();
while (!(os instanceof EntryPointNode)) {
os = os.getParentObjectSource();
}
return ((EntryPointNode) os).getQueryNode();
}
use of org.drools.core.reteoo.ObjectSource in project drools by kiegroup.
the class PhreakActivationIterator method processLeftTuples.
public static void processLeftTuples(LeftTupleSource node, List<AgendaItem> agendaItems, Set<RuleTerminalNode> nodeSet, InternalWorkingMemory wm) {
LeftTupleSource node1 = node;
while (NodeTypeEnums.LeftInputAdapterNode != node1.getType()) {
node1 = node1.getLeftTupleSource();
}
int maxShareCount = node1.getAssociationsSize();
while (NodeTypeEnums.LeftInputAdapterNode != node.getType()) {
Memory memory = wm.getNodeMemory((MemoryFactory) node);
if (memory.getSegmentMemory() == null) {
// segment has never been initialized, which means the rule has never been linked.
return;
}
if (node.getAssociationsSize() == maxShareCount) {
// the recurse must start from the first split node, otherwise we get partial overlaps in propagations
if (NodeTypeEnums.isBetaNode(node)) {
BetaMemory bm;
if (NodeTypeEnums.AccumulateNode == node.getType()) {
AccumulateMemory am = (AccumulateMemory) memory;
bm = am.getBetaMemory();
FastIterator it = bm.getLeftTupleMemory().fullFastIterator();
Tuple lt = BetaNode.getFirstTuple(bm.getLeftTupleMemory(), it);
for (; lt != null; lt = (LeftTuple) it.next(lt)) {
AccumulateContext accctx = (AccumulateContext) lt.getContextObject();
collectFromPeers(accctx.getResultLeftTuple(), agendaItems, nodeSet, wm);
}
} else if (NodeTypeEnums.ExistsNode == node.getType()) {
bm = (BetaMemory) wm.getNodeMemory((MemoryFactory) node);
// done off the RightTupleMemory, as exists only have unblocked tuples on the left side
FastIterator it = bm.getRightTupleMemory().fullFastIterator();
RightTuple rt = (RightTuple) BetaNode.getFirstTuple(bm.getRightTupleMemory(), it);
for (; rt != null; rt = (RightTuple) it.next(rt)) {
for (LeftTuple lt = rt.getBlocked(); lt != null; lt = lt.getBlockedNext()) {
if (lt.getFirstChild() != null) {
collectFromPeers(lt.getFirstChild(), agendaItems, nodeSet, wm);
}
}
}
} else {
bm = (BetaMemory) wm.getNodeMemory((MemoryFactory) node);
FastIterator it = bm.getLeftTupleMemory().fullFastIterator();
Tuple lt = BetaNode.getFirstTuple(bm.getLeftTupleMemory(), it);
for (; lt != null; lt = (LeftTuple) it.next(lt)) {
if (lt.getFirstChild() != null) {
collectFromLeftInput(lt.getFirstChild(), agendaItems, nodeSet, wm);
}
}
}
return;
} else if (NodeTypeEnums.FromNode == node.getType()) {
FromMemory fm = (FromMemory) wm.getNodeMemory((MemoryFactory) node);
TupleMemory ltm = fm.getBetaMemory().getLeftTupleMemory();
FastIterator it = ltm.fullFastIterator();
for (LeftTuple lt = (LeftTuple) ltm.getFirst(null); lt != null; lt = (LeftTuple) it.next(lt)) {
if (lt.getFirstChild() != null) {
collectFromLeftInput(lt.getFirstChild(), agendaItems, nodeSet, wm);
}
}
return;
}
}
node = node.getLeftTupleSource();
}
// No beta or from nodes, so must retrieve LeftTuples from the LiaNode.
// This is done by scanning all the LeftTuples referenced from the FactHandles in the ObjectTypeNode
LeftInputAdapterNode lian = (LeftInputAdapterNode) node;
Memory memory = wm.getNodeMemory((MemoryFactory) node);
if (memory.getSegmentMemory() == null) {
// segment has never been initialized, which means the rule has never been linked.
return;
}
ObjectSource os = lian.getObjectSource();
while (os.getType() != NodeTypeEnums.ObjectTypeNode) {
os = os.getParentObjectSource();
}
ObjectTypeNode otn = (ObjectTypeNode) os;
final ObjectTypeNodeMemory omem = wm.getNodeMemory(otn);
LeftTupleSink firstLiaSink = lian.getSinkPropagator().getFirstLeftTupleSink();
java.util.Iterator<InternalFactHandle> it = omem.iterator();
while (it.hasNext()) {
InternalFactHandle fh = it.next();
fh.forEachLeftTuple(lt -> {
if (lt.getTupleSink() == firstLiaSink) {
collectFromLeftInput(lt, agendaItems, nodeSet, wm);
}
});
}
}
use of org.drools.core.reteoo.ObjectSource in project drools by kiegroup.
the class BetaNodeBuilder method build.
public BetaNode build() {
NodeFactory nFactory = buildContext.getComponentFactory().getNodeFactoryService();
EntryPointNode epn = buildContext.getKnowledgeBase().getRete().getEntryPointNodes().values().iterator().next();
ObjectTypeNode otn = nFactory.buildObjectTypeNode(buildContext.getNextId(), epn, new ClassObjectType(leftType), buildContext);
LeftInputAdapterNode leftInput = nFactory.buildLeftInputAdapterNode(buildContext.getNextId(), otn, buildContext);
ObjectSource rightInput = nFactory.buildObjectTypeNode(buildContext.getNextId(), epn, new ClassObjectType(rightType), buildContext);
ReteTesterHelper reteTesterHelper = new ReteTesterHelper();
Pattern pattern = new Pattern(0, new ClassObjectType(leftType));
// BetaNodeFieldConstraint betaConstraint = null;
BetaConstraints betaConstraints = null;
if (constraintFieldName != null) {
ClassFieldAccessorStore store = (ClassFieldAccessorStore) reteTesterHelper.getStore();
InternalReadAccessor extractor = store.getReader(leftType, leftFieldName);
Declaration declr = new Declaration(leftVariableName, extractor, pattern);
betaConstraints = new SingleBetaConstraints(reteTesterHelper.getBoundVariableConstraint(rightType, constraintFieldName, declr, constraintOperator), buildContext.getKnowledgeBase().getConfiguration());
} else {
betaConstraints = new EmptyBetaConstraints();
}
switch(nodeType) {
case NodeTypeEnums.JoinNode:
return new JoinNode(0, leftInput, rightInput, betaConstraints, buildContext);
case NodeTypeEnums.NotNode:
return new NotNode(0, leftInput, rightInput, betaConstraints, buildContext);
case NodeTypeEnums.ExistsNode:
return new ExistsNode(0, leftInput, rightInput, betaConstraints, buildContext);
}
throw new IllegalStateException("Unable to build Node");
}
use of org.drools.core.reteoo.ObjectSource in project drools by kiegroup.
the class NodesPartitioningTest method checkNode.
private void checkNode(NetworkNode node) {
if (node instanceof EntryPointNode) {
assertSame(RuleBasePartitionId.MAIN_PARTITION, node.getPartitionId());
} else if (node instanceof ObjectTypeNode) {
assertSame(RuleBasePartitionId.MAIN_PARTITION, node.getPartitionId());
checkPartitionedSinks((ObjectTypeNode) node);
} else if (node instanceof ObjectSource) {
ObjectSource source = ((ObjectSource) node).getParentObjectSource();
if (!(source instanceof ObjectTypeNode)) {
assertSame(source.getPartitionId(), node.getPartitionId());
}
} else if (node instanceof BetaNode) {
ObjectSource rightInput = ((BetaNode) node).getRightInput();
if (!(rightInput instanceof ObjectTypeNode)) {
assertSame(rightInput.getPartitionId(), node.getPartitionId());
}
LeftTupleSource leftInput = ((BetaNode) node).getLeftTupleSource();
assertSame(leftInput.getPartitionId(), node.getPartitionId());
} else if (node instanceof TerminalNode) {
LeftTupleSource leftInput = ((TerminalNode) node).getLeftTupleSource();
assertSame(leftInput.getPartitionId(), node.getPartitionId());
}
}
use of org.drools.core.reteoo.ObjectSource in project drools by kiegroup.
the class ReteDumper method getSinks.
public static Sink[] getSinks(BaseNode node) {
Sink[] sinks = null;
if (node instanceof EntryPointNode) {
EntryPointNode source = (EntryPointNode) node;
Collection<ObjectTypeNode> otns = source.getObjectTypeNodes().values();
sinks = otns.toArray(new Sink[otns.size()]);
} else if (node instanceof ObjectSource) {
ObjectSource source = (ObjectSource) node;
sinks = source.getObjectSinkPropagator().getSinks();
} else if (node instanceof LeftTupleSource) {
LeftTupleSource source = (LeftTupleSource) node;
sinks = source.getSinkPropagator().getSinks();
}
return sinks;
}
Aggregations