use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class MarshallingTest method testMarshallEntryPointsWithSlidingLengthWindow.
@Test
public void testMarshallEntryPointsWithSlidingLengthWindow() throws Exception {
String str = "package org.domain.test \n" + "import " + getClass().getCanonicalName() + ".*\n" + "import java.util.List\n" + "global java.util.List list\n" + "declare A\n" + " @role( event )\n" + " @expires( 10m )\n" + "end\n" + "declare B\n" + "" + " @role( event )\n" + " @expires( 10m )\n" + "end\n" + "" + "rule a1\n" + "when\n" + " $l : List() from collect( A() over window:length(3) from entry-point 'a-ep') \n" + "then\n" + " list.add( $l );" + "end\n";
KieBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
conf.setOption(EventProcessingOption.STREAM);
final KieBase kbase = loadKnowledgeBaseFromString(conf, str);
KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.get("pseudo"));
ksconf.setOption(TimerJobFactoryOption.get("trackable"));
KieSession ksession = createKnowledgeSession(kbase, ksconf);
List list = new ArrayList();
ksession.setGlobal("list", list);
EntryPoint aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
list.clear();
ksession.fireAllRules();
ksession = marsallStatefulKnowledgeSession(ksession);
assertEquals(2, ((List) list.get(0)).size());
aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
list.clear();
ksession.fireAllRules();
ksession = marsallStatefulKnowledgeSession(ksession);
assertEquals(3, ((List) list.get(0)).size());
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class GetEntryPointCommand method execute.
public EntryPoint execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint ep = ksession.getEntryPoint(name);
if (ep == null) {
return null;
}
EntryPointCreator epCreator = (EntryPointCreator) context.get(EntryPointCreator.class.getName());
return epCreator != null ? epCreator.getEntryPoint(name) : ep;
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class DeleteObjectCommand method execute.
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint ep = ksession.getEntryPoint(entryPoint);
if (ep != null) {
FactHandle handle = ksession.getEntryPoint(entryPoint).getFactHandle(object);
ksession.delete(handle);
}
return null;
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class InsertElementsCommand method execute.
public Collection<FactHandle> execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
List<FactHandle> handles = new ArrayList<FactHandle>();
EntryPoint wmep;
if (StringUtils.isEmpty(this.entryPoint)) {
wmep = ksession;
} else {
wmep = ksession.getEntryPoint(this.entryPoint);
}
for (Object object : objects) {
handles.add(wmep.insert(object));
}
if (outIdentifier != null) {
if (this.returnObject) {
((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, objects);
}
((RegistryContext) context).lookup(ExecutionResultImpl.class).getFactHandles().put(this.outIdentifier, handles);
}
return handles;
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class NegativePatternsTest method testMultipleEntryPoints.
@Test
public void testMultipleEntryPoints() throws InterruptedException {
EntryPoint entryPoint = ksession.getEntryPoint("EventStream");
EntryPoint otherStream = ksession.getEntryPoint("OtherStream");
int count = 0;
count++;
ksession.fireAllRules();
advanceTime(LONG_SLEEP_TIME);
ksession.fireAllRules();
assertEquals(count, firedRulesListener.ruleFiredCount("MultipleEntryPoints"));
FactHandle handle;
for (int i = 0; i < LOOPS; i++) {
handle = entryPoint.insert(new TestEvent(count, "EventA"));
ksession.fireAllRules();
advanceTime(LONG_SLEEP_TIME);
entryPoint.delete(handle);
ksession.fireAllRules();
count++;
advanceTime(LONG_SLEEP_TIME);
ksession.fireAllRules();
}
for (int i = 0; i < LOOPS; i++) {
handle = otherStream.insert(new TestEvent(count, "EventB"));
advanceTime(LONG_SLEEP_TIME);
ksession.fireAllRules();
otherStream.delete(handle);
count++;
advanceTime(SHORT_SLEEP_TIME);
ksession.fireAllRules();
}
ksession.fireAllRules();
assertEquals(count, firedRulesListener.ruleFiredCount("MultipleEntryPoints"));
}
Aggregations