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;
}
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);
}
}
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);
}
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;
}
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();
}
Aggregations