use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class ModifyCommand method execute.
public Object execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint wmep = ksession.getEntryPoint(factHandle.getEntryPointId());
Object object = wmep.getObject(this.factHandle);
MVELSafeHelper.getEvaluator().eval(getMvelExpr(), object);
wmep.update(factHandle, object);
return object;
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class InsertObjectInEntryPointCommand method execute.
public FactHandle execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint ep = ksession.getEntryPoint(entryPoint);
FactHandle factHandle = ep.insert(object);
DefaultFactHandle disconnectedHandle = ((DefaultFactHandle) factHandle).clone();
disconnectedHandle.disconnect();
if (outIdentifier != null) {
if (this.returnObject) {
((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, object);
}
((RegistryContext) context).lookup(ExecutionResultImpl.class).getFactHandles().put(this.outIdentifier, disconnectedHandle);
}
return disconnectedHandle;
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class WindowTest method testTimeWindow.
@Test
public void testTimeWindow() throws InterruptedException {
EntryPoint entryPoint = ksession.getEntryPoint("EventStream");
final long[] results = new long[] { 1, 2, 3, 3, 3 };
TestEvent event;
for (int i = 0; i < 5; i++) {
event = new TestEvent(null, "time", null);
entryPoint.insert(event);
assertEquals(results[i], ksession.getQueryResults("TestTimeWindow").iterator().next().get("$eventCount"));
clock.advanceTime(100, TimeUnit.MILLISECONDS);
}
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class StreamsTest method testModifyOnEntryPointFacts.
// (timeout=10000)
@Test
public void testModifyOnEntryPointFacts() throws Exception {
String str = "package org.drools.compiler\n" + "declare StockTick\n" + " @role ( event )\n" + "end\n" + "rule R1 salience 100\n" + " when\n" + " $s1 : StockTick( company == 'RHT', price == 10 ) from entry-point ep1\n" + " then\n" + " StockTick s = $s1;\n" + " modify( s ) { setPrice( 50 ) };\n" + "end\n" + "rule R2 salience 90\n" + " when\n" + " $s1 : StockTick( company == 'RHT', price == 10 ) from entry-point ep2\n" + " then\n" + " StockTick s = $s1;\n" + " modify( s ) { setPrice( 50 ) };\n" + "end\n" + "rule R3 salience 80\n" + " when\n" + " $s1 : StockTick( company == 'RHT', price == 10 ) from entry-point ep3\n" + " then\n" + " StockTick s = $s1;\n" + " modify( s ) { setPrice( 50 ) };\n" + "end\n";
// read in the source
KieBase kbase = loadKnowledgeBaseFromString((KieBaseConfiguration) null, str);
KieSession ksession = createKnowledgeSession(kbase);
org.kie.api.event.rule.AgendaEventListener ael = mock(org.kie.api.event.rule.AgendaEventListener.class);
ksession.addEventListener(ael);
EntryPoint ep1 = ksession.getEntryPoint("ep1");
EntryPoint ep2 = ksession.getEntryPoint("ep2");
EntryPoint ep3 = ksession.getEntryPoint("ep3");
ep1.insert(new StockTick(1, "RHT", 10, 1000));
ep2.insert(new StockTick(1, "RHT", 10, 1000));
ep3.insert(new StockTick(1, "RHT", 10, 1000));
int rulesFired = ksession.fireAllRules();
assertEquals(3, rulesFired);
ArgumentCaptor<org.kie.api.event.rule.AfterMatchFiredEvent> captor = ArgumentCaptor.forClass(org.kie.api.event.rule.AfterMatchFiredEvent.class);
verify(ael, times(3)).afterMatchFired(captor.capture());
List<org.kie.api.event.rule.AfterMatchFiredEvent> aafe = captor.getAllValues();
assertThat(aafe.get(0).getMatch().getRule().getName(), is("R1"));
assertThat(aafe.get(1).getMatch().getRule().getName(), is("R2"));
assertThat(aafe.get(2).getMatch().getRule().getName(), is("R3"));
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class MarshallingTest method testMarshallEntryPointsWithNot.
@Test
public void testMarshallEntryPointsWithNot() throws Exception {
String str = "package org.domain.test \n" + "import " + getClass().getCanonicalName() + ".*\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" + " $a : A() from entry-point 'a-ep'\n" + " not B( this after[0s, 10s] $a) from entry-point 'a-ep'\n" + "then\n" + "list.add( $a );" + "end\n";
KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
KieBase kBase = loadKnowledgeBaseFromString(config, str);
KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.get("pseudo"));
ksconf.setOption(TimerJobFactoryOption.get("trackable"));
KieSession ksession = kBase.newKieSession(ksconf, null);
List list = new ArrayList();
ksession.setGlobal("list", list);
EntryPoint aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock>getSessionClock();
timeService.advanceTime(3, TimeUnit.SECONDS);
ksession = marsallStatefulKnowledgeSession(ksession);
ksession.fireAllRules();
ksession = marsallStatefulKnowledgeSession(ksession);
assertEquals(0, list.size());
}
Aggregations