Search in sources :

Example 11 with EntryPointNode

use of org.drools.core.reteoo.EntryPointNode 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());
    }
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) LeftTupleSource(org.drools.core.reteoo.LeftTupleSource) BetaNode(org.drools.core.reteoo.BetaNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) ObjectSource(org.drools.core.reteoo.ObjectSource) TerminalNode(org.drools.core.reteoo.TerminalNode)

Example 12 with EntryPointNode

use of org.drools.core.reteoo.EntryPointNode 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;
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) LeftTupleSource(org.drools.core.reteoo.LeftTupleSource) Sink(org.drools.core.reteoo.Sink) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) ObjectSource(org.drools.core.reteoo.ObjectSource)

Example 13 with EntryPointNode

use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.

the class RemoveRuleTest method testRemoveBigRule.

@Test
public void testRemoveBigRule() throws Exception {
    // JBRULES-3496
    final String str = "package org.drools.compiler.test\n" + "\n" + "declare SimpleFact\n" + "   patientSpaceId : String\n" + "   block : int\n" + "end\n" + "\n" + "declare SimpleMembership\n" + "   patientSpaceId : String\n" + "   listId : String\n" + "end\n" + "\n" + "declare SimplePatient\n" + "   spaceId : String\n" + "end\n" + "\n" + "rule \"RTR - 47146 retract\"\n" + "agenda-group \"list membership\"\n" + "when\n" + "   $listMembership0 : SimpleMembership( $listMembershipPatientSpaceIdRoot : patientSpaceId, ( listId != null && listId == \"47146\" ) )\n" + "   not ( $patient0 : SimplePatient( $patientSpaceIdRoot : spaceId, spaceId != null && spaceId == $listMembershipPatientSpaceIdRoot ) \n" + "       and ( ( " + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 1 )\n" + "         ) or ( " + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 2 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId  == $patientSpaceIdRoot, block == 3 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 4 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 5 )\n" + "       ) ) and ( ( " + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 6 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 7 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 8 )\n" + "       ) ) and ( ( " + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 9 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 10 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 11 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 12 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 13 )\n" + "         ) or ( (" + "            SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 14 )\n" + "           ) and (" + "              SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 15 )\n" + "         ) ) or ( ( " + "            SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 16 )\n" + "           ) and ( " + "             SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 17 )\n" + "         ) ) or ( ( " + "             SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 18 )\n" + "           ) and (" + "             SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 19 )\n" + "         ) ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 20 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 21 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 22 )\n" + "         ) or ( ( " + "             SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 23 )\n" + "         ) and (" + "             SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 24 )\n" + "     ) ) ) and ( ( " + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 25 )\n" + "         ) or (" + "           SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 26 )\n" + "     ) ) )\n" + "then\n" + "end\n";
    final Collection<KiePackage> kpgs = loadKnowledgePackagesFromString(str);
    assertEquals(1, kpgs.size());
    final InternalKnowledgeBase kbase = (InternalKnowledgeBase) getKnowledgeBase();
    kbase.addPackages(kpgs);
    kbase.removeKiePackage(kpgs.iterator().next().getName());
    final EntryPointNode epn = ((InternalKnowledgeBase) kbase).getRete().getEntryPointNodes().values().iterator().next();
    for (final ObjectTypeNode otn : epn.getObjectTypeNodes().values()) {
        final ObjectSink[] sinks = otn.getObjectSinkPropagator().getSinks();
        if (sinks.length > 0) {
            fail(otn + " has sinks " + Arrays.toString(sinks));
        }
    }
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) KiePackage(org.kie.api.definition.KiePackage) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) ObjectSink(org.drools.core.reteoo.ObjectSink) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 14 with EntryPointNode

use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.

the class FactHandleMarshallingTest method createEventFactHandle.

private InternalFactHandle createEventFactHandle(StatefulKnowledgeSessionImpl wm, InternalKnowledgeBase kBase) {
    // EntryPointNode
    Rete rete = kBase.getRete();
    NodeFactory nFacotry = kBase.getConfiguration().getComponentFactory().getNodeFactoryService();
    RuleBasePartitionId partionId = RuleBasePartitionId.MAIN_PARTITION;
    EntryPointNode entryPointNode = nFacotry.buildEntryPointNode(1, partionId, false, (ObjectSource) rete, EntryPointId.DEFAULT);
    WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(EntryPointId.DEFAULT, entryPointNode, wm);
    EventFactHandle factHandle = new EventFactHandle(1, (Object) new Person(), 0, (new Date()).getTime(), 0, wmEntryPoint);
    return factHandle;
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) Rete(org.drools.core.reteoo.Rete) NodeFactory(org.drools.core.reteoo.builder.NodeFactory) RuleBasePartitionId(org.drools.core.common.RuleBasePartitionId) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) Person(org.drools.compiler.Person) Date(java.util.Date)

Example 15 with EntryPointNode

use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.

the class ParallelEvaluationTest method test.

@Test(timeout = 10000L)
public void test() {
    StringBuilder sb = new StringBuilder(400);
    sb.append("global java.util.List list;\n");
    for (int i = 0; i < 10; i++) {
        sb.append(getRule(i, ""));
    }
    KieBase kbase = new KieHelper().addContent(sb.toString(), ResourceType.DRL).build(MultithreadEvaluationOption.YES);
    EntryPointNode epn = ((InternalKnowledgeBase) kbase).getRete().getEntryPointNode(EntryPointId.DEFAULT);
    ObjectTypeNode otn = epn.getObjectTypeNodes().get(new ClassObjectType(Integer.class));
    assertTrue(((CompositePartitionAwareObjectSinkAdapter) otn.getObjectSinkPropagator()).isHashed());
    KieSession ksession = kbase.newKieSession();
    assertTrue(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda());
    List<Integer> list = new DebugList<Integer>();
    ksession.setGlobal("list", list);
    for (int i = 0; i < 10; i++) {
        ksession.insert(i);
        ksession.insert("" + i);
    }
    ksession.fireAllRules();
    assertEquals(10, list.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) EntryPointNode(org.drools.core.reteoo.EntryPointNode) ClassObjectType(org.drools.core.base.ClassObjectType) KieBase(org.kie.api.KieBase) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) DebugList(org.drools.compiler.util.debug.DebugList) Test(org.junit.Test)

Aggregations

EntryPointNode (org.drools.core.reteoo.EntryPointNode)23 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)16 ClassObjectType (org.drools.core.base.ClassObjectType)8 Test (org.junit.Test)8 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)7 KieSession (org.kie.api.runtime.KieSession)6 KieHelper (org.kie.internal.utils.KieHelper)6 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)5 ObjectSource (org.drools.core.reteoo.ObjectSource)5 KieBase (org.kie.api.KieBase)5 Rete (org.drools.core.reteoo.Rete)4 ArrayList (java.util.ArrayList)3 LeftTupleSink (org.drools.core.reteoo.LeftTupleSink)3 LeftTupleSource (org.drools.core.reteoo.LeftTupleSource)3 NodeFactory (org.drools.core.reteoo.builder.NodeFactory)3 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)2 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)2 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)2 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)2 RuleBasePartitionId (org.drools.core.common.RuleBasePartitionId)2