use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class TimerAndCalendarTest method testExpiredPropagations.
@Test
public void testExpiredPropagations() throws InterruptedException {
// DROOLS-244
String drl = "package org.drools.test;\n" + "\n" + "import org.drools.compiler.StockTick;\n" + "global java.util.List list;\n" + "\n" + "declare StockTick\n" + "\t@role( event )\n" + "\t@timestamp( time )\n" + "end\n" + "\n" + "declare window ATicks\n" + " StockTick( company == \"AAA\" ) over window:time( 1s ) " + " from entry-point \"AAA\"\n" + "end\n" + "\n" + "declare window BTicks\n" + " StockTick( company == \"BBB\" ) over window:time( 1s ) " + " from entry-point \"BBB\"\n" + "end\n" + "\n" + "rule Ticks \n" + " when\n" + " String()\n" + " accumulate( $x : StockTick() from window ATicks, $a : count( $x ) )\n" + " accumulate( $y : StockTick() from window BTicks, $b : count( $y ) )\n" + " accumulate( $z : StockTick() over window:time( 1s ), $c : count( $z ) )\n" + " then\n" + " list.add( $a );\n" + " list.add( $b );\n" + " list.add( $c );\n" + "end";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get("pseudo"));
KieSession ksession = kbase.newKieSession(conf, null);
ArrayList list = new ArrayList();
ksession.setGlobal("list", list);
SessionPseudoClock clock = (SessionPseudoClock) ksession.getSessionClock();
clock.advanceTime(1100, TimeUnit.MILLISECONDS);
StockTick tick = new StockTick(0, "AAA", 1.0, 0);
StockTick tock = new StockTick(1, "BBB", 1.0, 2500);
StockTick tack = new StockTick(1, "CCC", 1.0, 2700);
EntryPoint epa = ksession.getEntryPoint("AAA");
EntryPoint epb = ksession.getEntryPoint("BBB");
epa.insert(tick);
epb.insert(tock);
ksession.insert(tack);
FactHandle handle = ksession.insert("go1");
ksession.fireAllRules();
System.out.println("***** " + list + " *****");
assertEquals(asList(0L, 1L, 1L), list);
list.clear();
ksession.retract(handle);
clock.advanceTime(2550, TimeUnit.MILLISECONDS);
handle = ksession.insert("go2");
ksession.fireAllRules();
System.out.println("***** " + list + " *****");
assertEquals(asList(0L, 0L, 1L), list);
list.clear();
ksession.retract(handle);
clock.advanceTime(500, TimeUnit.MILLISECONDS);
handle = ksession.insert("go3");
ksession.fireAllRules();
System.out.println("***** " + list + " *****");
assertEquals(asList(0L, 0L, 0L), list);
list.clear();
ksession.retract(handle);
ksession.dispose();
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class KieBaseUpdater method clearInstancesOfModifiedClass.
protected void clearInstancesOfModifiedClass(Class<?> cls) {
// remove all ObjectTypeNodes for the modified classes
ClassObjectType objectType = new ClassObjectType(cls);
for (EntryPointNode epn : ctx.kBase.getRete().getEntryPointNodes().values()) {
epn.removeObjectType(objectType);
}
// remove all instance of the old class from the object stores
for (InternalWorkingMemory wm : ctx.kBase.getWorkingMemories()) {
for (EntryPoint ep : wm.getEntryPoints()) {
InternalWorkingMemoryEntryPoint wmEp = (InternalWorkingMemoryEntryPoint) wm.getWorkingMemoryEntryPoint(ep.getEntryPointId());
ClassAwareObjectStore store = ((ClassAwareObjectStore) wmEp.getObjectStore());
if (store.clearClassStore(cls)) {
log.warn("Class " + cls.getName() + " has been modified and therfore its old instances will no longer match");
}
}
}
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class UpdateCommand method execute.
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint ep = ksession.getEntryPoint(handle.getEntryPointId());
if (modifiedProperties != null) {
ep.update(handle, object, modifiedProperties);
} else {
ep.update(handle, object);
}
return null;
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class GetEntryPointsCommand method execute.
public Collection<? extends EntryPoint> execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
Collection<? extends EntryPoint> eps = ksession.getEntryPoints();
EntryPointCreator epCreator = (EntryPointCreator) context.get(EntryPointCreator.class.getName());
if (epCreator == null) {
return eps;
}
Collection<EntryPoint> result = new ArrayList<EntryPoint>();
for (EntryPoint ep : eps) {
result.add(epCreator.getEntryPoint(ep.getEntryPointId()));
}
return result;
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class GetFactHandleInEntryPointCommand method execute.
public FactHandle execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
EntryPoint ep = ksession.getEntryPoint(entryPoint);
InternalFactHandle factHandle = (InternalFactHandle) ep.getFactHandle(object);
if (factHandle != null) {
InternalFactHandle handle = factHandle.clone();
if (disconnected) {
handle.disconnect();
}
return handle;
}
return null;
}
Aggregations