use of org.kie.api.event.rule.AgendaEventListener in project drools by kiegroup.
the class StrictAnnotationTest method testEagerEvaluation.
@Test
public void testEagerEvaluation() {
String str = "package org.simple \n" + "@Propagation(EAGER) rule xxx \n" + "when \n" + " $s : String()\n" + "then \n" + "end \n" + "@Propagation(EAGER) rule yyy \n" + "when \n" + " $s : String()\n" + "then \n" + "end \n";
KieSessionConfiguration conf = RuleBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ForceEagerActivationOption.YES);
Map<String, String> kieModuleConfigurationProperties = new HashMap<>();
kieModuleConfigurationProperties.put(LanguageLevelOption.PROPERTY_NAME, LanguageLevelOption.DRL6_STRICT.toString());
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, kieModuleConfigurationProperties, str);
KieSession ksession = kbase.newKieSession(conf, null);
try {
final List list = new ArrayList();
AgendaEventListener agendaEventListener = new DefaultAgendaEventListener() {
public void matchCreated(org.kie.api.event.rule.MatchCreatedEvent event) {
list.add("activated");
}
};
ksession.addEventListener(agendaEventListener);
ksession.insert("test");
assertEquals(2, list.size());
} finally {
ksession.dispose();
}
}
use of org.kie.api.event.rule.AgendaEventListener in project jbpm by kiegroup.
the class ActivityTest method testRuleTaskWithFacts.
@Test
@RequirePersistence(false)
public void testRuleTaskWithFacts() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-RuleTaskWithFact.bpmn2", "BPMN2-RuleTask3.drl");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(new AgendaEventListener() {
public void matchCreated(MatchCreatedEvent event) {
}
public void matchCancelled(MatchCancelledEvent event) {
}
public void beforeRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent event) {
}
public void beforeRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent event) {
}
public void beforeMatchFired(BeforeMatchFiredEvent event) {
}
public void agendaGroupPushed(org.kie.api.event.rule.AgendaGroupPushedEvent event) {
}
public void agendaGroupPopped(org.kie.api.event.rule.AgendaGroupPoppedEvent event) {
}
public void afterRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent event) {
}
public void afterRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent event) {
ksession.fireAllRules();
}
public void afterMatchFired(AfterMatchFiredEvent event) {
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "SomeString");
ProcessInstance processInstance = ksession.startProcess("RuleTask", params);
assertProcessInstanceFinished(processInstance, ksession);
params = new HashMap<String, Object>();
try {
processInstance = ksession.startProcess("RuleTask", params);
fail("Should fail");
} catch (Exception e) {
e.printStackTrace();
}
params = new HashMap<String, Object>();
params.put("x", "SomeString");
processInstance = ksession.startProcess("RuleTask", params);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.kie.api.event.rule.AgendaEventListener in project jbpm by kiegroup.
the class AbstractRuntimeManager method registerItems.
protected void registerItems(RuntimeEngine runtime) {
RegisterableItemsFactory factory = environment.getRegisterableItemsFactory();
// process handlers
Map<String, WorkItemHandler> handlers = factory.getWorkItemHandlers(runtime);
for (Entry<String, WorkItemHandler> entry : handlers.entrySet()) {
runtime.getKieSession().getWorkItemManager().registerWorkItemHandler(entry.getKey(), entry.getValue());
}
// register globals
Map<String, Object> globals = factory.getGlobals(runtime);
for (Entry<String, Object> entry : globals.entrySet()) {
runtime.getKieSession().setGlobal(entry.getKey(), entry.getValue());
}
// process listeners
List<ProcessEventListener> processListeners = factory.getProcessEventListeners(runtime);
for (ProcessEventListener listener : processListeners) {
runtime.getKieSession().addEventListener(listener);
}
// agenda listeners
List<AgendaEventListener> agendaListeners = factory.getAgendaEventListeners(runtime);
for (AgendaEventListener listener : agendaListeners) {
runtime.getKieSession().addEventListener(listener);
}
// working memory listeners
List<RuleRuntimeEventListener> wmListeners = factory.getRuleRuntimeEventListeners(runtime);
for (RuleRuntimeEventListener listener : wmListeners) {
runtime.getKieSession().addEventListener(listener);
}
}
Aggregations