Search in sources :

Example 6 with NodeFactory

use of org.drools.core.reteoo.builder.NodeFactory in project drools by kiegroup.

the class FactHandleMarshallingTest method createEventFactHandle.

private InternalFactHandle createEventFactHandle(StatefulKnowledgeSessionImpl wm, InternalKnowledgeBase kBase) {
    // EntryPointNode
    Rete rete = kBase.getRete();
    NodeFactory nFacotry = CoreComponentFactory.get().getNodeFactoryService();
    RuleBasePartitionId partionId = RuleBasePartitionId.MAIN_PARTITION;
    EntryPointNode entryPointNode = nFacotry.buildEntryPointNode(1, partionId, false, rete, EntryPointId.DEFAULT);
    WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(EntryPointId.DEFAULT, entryPointNode, wm);
    EventFactHandle factHandle = new EventFactHandle(1, 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.kiesession.entrypoints.NamedEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) Person(org.drools.mvel.compiler.Person) Date(java.util.Date)

Example 7 with NodeFactory

use of org.drools.core.reteoo.builder.NodeFactory 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 8 with NodeFactory

use of org.drools.core.reteoo.builder.NodeFactory in project drools by kiegroup.

the class AddRemoveTest method testAdd.

@Test
public void testAdd() {
    /*
         * create a RuleBase with a single ObjectTypeNode we attach a
         * MockObjectSink so we can detect assertions and retractions
         */
    InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    BuildContext context = new BuildContext(kBase);
    NodeFactory nFacotry = kBase.getConfiguration().getComponentFactory().getNodeFactoryService();
    EntryPointNode entryPoint = context.getKnowledgeBase().getRete().getEntryPointNodes().values().iterator().next();
    final ObjectTypeNode objectTypeNode = nFacotry.buildObjectTypeNode(0, entryPoint, new ClassObjectType(Object.class), context);
    objectTypeNode.attach(context);
    final MockObjectSink sink = new MockObjectSink();
    objectTypeNode.addObjectSink(sink);
    kBase.newKieSession();
// objectTypeNode.
}
Also used : BuildContext(org.drools.core.reteoo.builder.BuildContext) NodeFactory(org.drools.core.reteoo.builder.NodeFactory) ClassObjectType(org.drools.core.base.ClassObjectType) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 9 with NodeFactory

use of org.drools.core.reteoo.builder.NodeFactory in project drools by kiegroup.

the class ReteooWorkingMemoryTest method testDifferentEntryPointsOnSameFact.

@Test
public void testDifferentEntryPointsOnSameFact() {
    // JBRULES-2971
    InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    Rete rete = kBase.getRete();
    NodeFactory nFacotry = kBase.getConfiguration().getComponentFactory().getNodeFactoryService();
    EntryPointNode epn = nFacotry.buildEntryPointNode(kBase.getReteooBuilder().getIdGenerator().getNextId(), RuleBasePartitionId.MAIN_PARTITION, kBase.getConfiguration().isMultithreadEvaluation(), rete, new EntryPointId("xxx"));
    kBase.getRete().addObjectSink(epn);
    KieSession ksession = kBase.newKieSession();
    FactHandle f1 = ksession.insert("f1");
    EntryPoint ep = ksession.getEntryPoint("xxx");
    try {
        ep.update(f1, "s1");
        fail("Should throw an exception");
    } catch (IllegalArgumentException e) {
    }
    try {
        ep.retract(f1);
        fail("Should throw an exception");
    } catch (IllegalArgumentException e) {
    }
    ksession.update(f1, "s1");
    assertNotNull(ksession.getObject(f1));
    ksession.retract(f1);
    ksession.retract(f1);
    assertNull(ksession.getObject(f1));
}
Also used : NodeFactory(org.drools.core.reteoo.builder.NodeFactory) EntryPointId(org.drools.core.rule.EntryPointId) FactHandle(org.kie.api.runtime.rule.FactHandle) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Aggregations

NodeFactory (org.drools.core.reteoo.builder.NodeFactory)9 EntryPointNode (org.drools.core.reteoo.EntryPointNode)7 ClassObjectType (org.drools.core.base.ClassObjectType)4 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)4 Rete (org.drools.core.reteoo.Rete)4 Test (org.junit.Test)4 BuildContext (org.drools.core.reteoo.builder.BuildContext)3 Date (java.util.Date)2 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)2 BetaConstraints (org.drools.core.common.BetaConstraints)2 EmptyBetaConstraints (org.drools.core.common.EmptyBetaConstraints)2 EventFactHandle (org.drools.core.common.EventFactHandle)2 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)2 RuleBasePartitionId (org.drools.core.common.RuleBasePartitionId)2 SingleBetaConstraints (org.drools.core.common.SingleBetaConstraints)2 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)2 ExistsNode (org.drools.core.reteoo.ExistsNode)2 JoinNode (org.drools.core.reteoo.JoinNode)2 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)2 NotNode (org.drools.core.reteoo.NotNode)2