Search in sources :

Example 51 with EventFactHandle

use of org.drools.core.common.EventFactHandle 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 52 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class OldOutputMarshallerMethods method writeFactHandle_v1.

// Changed with JBRULES-3257
public static void writeFactHandle_v1(MarshallerWriteContext context, ObjectOutputStream stream, ObjectMarshallingStrategyStore objectMarshallingStrategyStore, int type, InternalFactHandle handle) throws IOException {
    stream.writeInt(type);
    stream.writeInt(handle.getId());
    stream.writeLong(handle.getRecency());
    if (type == 2) {
        // is event
        EventFactHandle efh = (EventFactHandle) handle;
        stream.writeLong(efh.getStartTimestamp());
        stream.writeLong(efh.getDuration());
        stream.writeBoolean(efh.isExpired());
        stream.writeLong(efh.getActivationsCount());
    }
    // context.out.println( "Object : int:" + handle.getId() + " long:" + handle.getRecency() );
    // context.out.println( handle.getObject() );
    Object object = handle.getObject();
    if (object != null) {
        int index = objectMarshallingStrategyStore.getStrategy(object);
        ObjectMarshallingStrategy strategy = objectMarshallingStrategyStore.getStrategy(index);
        stream.writeInt(index);
        strategy.write(stream, object);
    } else {
        stream.writeInt(-1);
    }
    String entryPoint = handle.getEntryPoint().getEntryPoint().getEntryPointId();
    if (entryPoint != null && !entryPoint.equals("")) {
        stream.writeBoolean(true);
        stream.writeUTF(entryPoint);
    } else {
        stream.writeBoolean(false);
    }
}
Also used : ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) EventFactHandle(org.drools.core.common.EventFactHandle)

Example 53 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TypeDeclarationTest method testTypeDeclarationWithInnerClassesImport.

@Test
public void testTypeDeclarationWithInnerClassesImport() {
    // DROOLS-150
    String str = "";
    str += "package org.drools.compiler;\n" + "\n" + "import org.drools.compiler.compiler.TypeDeclarationTest.EventBar.Foo;\n" + "" + "declare Foo\n" + " @role( event )\n" + "end\n" + "" + "rule R when Foo() then end";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
    System.err.println(kbuilder.getErrors());
    assertFalse(kbuilder.hasErrors());
    InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
    kBase.addPackages(kbuilder.getKnowledgePackages());
    KieSession knowledgeSession = kBase.newKieSession();
    FactHandle handle = knowledgeSession.insert(new EventBar.Foo());
    assertTrue(handle instanceof EventFactHandle);
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) FactHandle(org.kie.api.runtime.rule.FactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 54 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class DroolsAbstractPMMLTest method reportWMObjects.

public String reportWMObjects(KieSession session) {
    PriorityQueue<String> queue = new PriorityQueue<String>();
    for (FactHandle fh : session.getFactHandles()) {
        Object o;
        if (fh instanceof EventFactHandle) {
            EventFactHandle efh = (EventFactHandle) fh;
            queue.add("\t " + efh.getStartTimestamp() + "\t" + efh.getObject().toString() + "\n");
        } else {
            o = ((DefaultFactHandle) fh).getObject();
            queue.add("\t " + o.toString() + " >> " + System.identityHashCode(o.getClass()) + "\n");
        }
    }
    String ans = " ---------------- WM " + session.getObjects().size() + " --------------\n";
    while (!queue.isEmpty()) ans += queue.poll();
    ans += " ---------------- END WM -----------\n";
    return ans;
}
Also used : EventFactHandle(org.drools.core.common.EventFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) PriorityQueue(java.util.PriorityQueue)

Example 55 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class ConstrainedDataDictionaryTest method testProperties.

@Test
public void testProperties() throws Exception {
    getKSession().getEntryPoint("in_Vallued").insert(1);
    getKSession().getEntryPoint("in_Intervalled").insert(8.3);
    getKSession().getEntryPoint("in_Cat").insert("aa");
    getKSession().getEntryPoint("in_Sort").insert(1);
    getKSession().fireAllRules();
    Collection<EventFactHandle> fact1 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Vallued").getFactClass()));
    assertEquals(1, fact1.size());
    // assertEquals(true, getKbase().getFactType(packageName, "Vallued").get(fact1.iterator().next().getObject(), "continuous"));
    Collection<EventFactHandle> fact2 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Intervalled").getFactClass()));
    assertEquals(1, fact2.size());
    // assertEquals(true, getKbase().getFactType(packageName,"Intervalled").get(fact2.iterator().next().getObject(),"continuous"));
    Collection<EventFactHandle> fact3 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Cat").getFactClass()));
    assertEquals(1, fact3.size());
    // assertEquals(true, getKbase().getFactType(packageName,"Cat").get(fact3.iterator().next().getObject(),"categorical"));
    Collection<EventFactHandle> fact4 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Sort").getFactClass()));
    assertEquals(1, fact4.size());
    // assertEquals(true, getKbase().getFactType(packageName,"Sort").get(fact4.iterator().next().getObject(),"ordinal"));
    checkGeneratedRules();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) EventFactHandle(org.drools.core.common.EventFactHandle) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Aggregations

EventFactHandle (org.drools.core.common.EventFactHandle)86 Test (org.junit.Test)51 KieSession (org.kie.api.runtime.KieSession)23 KieBase (org.kie.api.KieBase)18 InternalFactHandle (org.drools.core.common.InternalFactHandle)16 DisconnectedWorkingMemoryEntryPoint (org.drools.core.common.DisconnectedWorkingMemoryEntryPoint)13 DisconnectedWorkingMemoryEntryPoint (org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint)13 FactHandle (org.kie.api.runtime.rule.FactHandle)11 DuringEvaluatorDefinition (org.drools.core.base.evaluators.DuringEvaluatorDefinition)10 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)10 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 QueryElementFactHandle (org.drools.core.common.QueryElementFactHandle)6 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)5 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)5 PropagationContext (org.drools.core.spi.PropagationContext)5 StockTick (org.drools.testcoverage.common.model.StockTick)5 EntryPointId (org.drools.core.rule.EntryPointId)4 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)4