use of org.kie.api.runtime.KieSessionConfiguration in project jbpm-work-items by kiegroup.
the class JavaHandlerWorkitemHandlerTest method createSession.
private static KieSession createSession(KieBase kbase) {
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.process.instance.event.DefaultSignalManagerFactory");
KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
return kbase.newKieSession(config, KieServices.get().newEnvironment());
}
use of org.kie.api.runtime.KieSessionConfiguration in project jbpm by kiegroup.
the class PersistenceUtil method createKieSessionFromKBase.
public static KieSession createKieSessionFromKBase(KieBase kbase, Map<String, Object> context) {
Properties defaultProps = new Properties();
defaultProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName());
defaultProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName());
KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(defaultProps);
ksconf.setOption(ForceEagerActivationOption.YES);
return kbase.newKieSession(ksconf, createEnvironment(context));
}
use of org.kie.api.runtime.KieSessionConfiguration in project jbpm by kiegroup.
the class AbstractWorkItemHandlerTest method createSession.
private static KieSession createSession(KieBase kbase) {
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.process.instance.event.DefaultSignalManagerFactory");
KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
return kbase.newKieSession(config, EnvironmentFactory.newEnvironment());
}
use of org.kie.api.runtime.KieSessionConfiguration in project jbpm by kiegroup.
the class JbpmBpmn2TestCase method restoreSession.
protected KieSession restoreSession(KieSession ksession, boolean noCache) {
if (sessionPersistence) {
long id = ksession.getIdentifier();
KieBase kbase = ksession.getKieBase();
Environment env = null;
if (noCache) {
env = createEnvironment(emf);
} else {
env = ksession.getEnvironment();
}
if (pessimisticLocking) {
env.set(USE_PESSIMISTIC_LOCKING, true);
}
KieSessionConfiguration config = ksession.getSessionConfiguration();
config.setOption(ForceEagerActivationOption.YES);
ksession.dispose();
StatefulKnowledgeSession result = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, config, env);
AuditLoggerFactory.newInstance(Type.JPA, result, null);
return result;
} else {
return ksession;
}
}
use of org.kie.api.runtime.KieSessionConfiguration in project jbpm by kiegroup.
the class MBeansMonitoringWithJBpmTest method testRulesAndProcesses.
@Test
public void testRulesAndProcesses() throws Exception {
String drl = "package org.drools.droolsjbpm_integration_testmgt\n" + "rule S\n" + "when\n" + " $s: String() \n" + "then\n" + " try { Thread.sleep(10); } catch (Exception e) { }\n" + " System.out.println($s); \n" + "end\n";
String process = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" + "<definitions id=\"Definition\"\n" + " targetNamespace=\"http://www.example.org/MinimalExample\"\n" + " typeLanguage=\"http://www.java.com/javaTypes\"\n" + " expressionLanguage=\"http://www.mvel.org/2.0\"\n" + " xmlns=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd\"\n" + " xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\"\n" + " xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\"\n" + " xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\"\n" + " xmlns:tns=\"http://www.jboss.org/drools\">\n" + "\n" + " <process processType=\"Private\" isExecutable=\"true\" id=\"com.sample.HelloWorld\" name=\"Hello World\" >\n" + "\n" + " <!-- nodes -->\n" + " <startEvent id=\"_a1\" name=\"StartProcess\" />\n" + " <scriptTask id=\"_a2\" name=\"Hello\" >\n" + " <script>System.out.println(\"Hello World\");</script>\n" + " </scriptTask>\n" + " <endEvent id=\"_a3\" name=\"EndProcess\" >\n" + " <terminateEventDefinition/>\n" + " </endEvent>\n" + "\n" + " <!-- connections -->\n" + " <sequenceFlow id=\"_a1-_a2\" sourceRef=\"_a1\" targetRef=\"_a2\" />\n" + " <sequenceFlow id=\"_a2-_a3\" sourceRef=\"_a2\" targetRef=\"_a3\" />\n" + "\n" + " </process>" + " <process processType=\"Private\" isExecutable=\"true\" id=\"com.sample.CiaoWorld\" name=\"Ciao World\" >\n" + "\n" + " <!-- nodes -->\n" + " <startEvent id=\"_b1\" name=\"StartProcess\" />\n" + " <scriptTask id=\"_b2\" name=\"Ciao\" >\n" + " <script>System.out.println(\"Ciao World\");</script>\n" + " </scriptTask>\n" + " <endEvent id=\"_b3\" name=\"EndProcess\" >\n" + " <terminateEventDefinition/>\n" + " </endEvent>\n" + "\n" + " <!-- connections -->\n" + " <sequenceFlow id=\"_b1-_b2\" sourceRef=\"_b1\" targetRef=\"_b2\" />\n" + " <sequenceFlow id=\"_b2-_b3\" sourceRef=\"_b2\" targetRef=\"_b3\" />\n" + "\n" + " </process>" + "</definitions>";
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel(KBASE1).setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
KieSessionModel ksessionModel1 = kieBaseModel1.newKieSessionModel(KSESSION1).setDefault(true).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
KieSessionModel ksessionModel2 = kieBaseModel1.newKieSessionModel(KSESSION2).setDefault(false).setType(KieSessionModel.KieSessionType.STATELESS);
ReleaseId releaseId1 = ks.newReleaseId("org.kie.test", "mbeans", "1.0.0");
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML());
kfs.generateAndWritePomXML(releaseId1);
kfs.write("src/main/resources/r" + 1 + ".drl", drl);
kfs.write("src/main/resources/p" + 1 + ".bpmn2", process);
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
if (kb.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
for (org.kie.api.builder.Message result : kb.getResults().getMessages()) {
LOG.error(result.getText());
}
}
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId1);
KieContainer kc = ks.newKieContainer(KCONTAINER1, releaseId1);
KieBase kiebase = kc.getKieBase(KBASE1);
Properties ksessionConfigProps = new Properties();
ksessionConfigProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName());
ksessionConfigProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName());
KieSessionConfiguration sessionConf = ks.newKieSessionConfiguration(ksessionConfigProps);
sessionConf.setOption(ForceEagerActivationOption.YES);
KieSession ksession = kc.newKieSession(KSESSION1, sessionConf);
MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
KieSessionMonitoringMXBean aggrMonitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy(KCONTAINER1, KBASE1, KieSessionType.STATEFUL, KSESSION1), KieSessionMonitoringMXBean.class);
long tft = 0;
print(aggrMonitor);
checkAgendaTotals(aggrMonitor, 0, 0, 0);
checkTotalFactCount(aggrMonitor, 0);
tft = checkTotalFiringTimeGEQ(aggrMonitor, tft);
checkTotalSessions(aggrMonitor, 1);
assertNull(aggrMonitor.getStatsForProcess("com.sample.HelloWorld"));
assertNull(aggrMonitor.getStatsForProcess("com.sample.CiaoWorld"));
assertFalse(aggrMonitor.getStatsByProcess().containsKey("com.sample.HelloWorld"));
assertFalse(aggrMonitor.getStatsByProcess().containsKey("com.sample.CiaoWorld"));
ksession.insert("Ciao");
ksession.startProcess("com.sample.HelloWorld");
ksession.startProcess("com.sample.HelloWorld");
ksession.startProcess("com.sample.CiaoWorld");
ksession.fireAllRules();
print(aggrMonitor);
checkAgendaTotals(aggrMonitor, 1, 0, 1);
checkTotalFactCount(aggrMonitor, 1);
tft = checkTotalFiringTimeGEQ(aggrMonitor, tft + 1);
checkTotalSessions(aggrMonitor, 1);
checkStatsForProcess(aggrMonitor, "com.sample.HelloWorld", 2, 2, 6);
checkStatsForProcess(aggrMonitor, "com.sample.CiaoWorld", 1, 1, 3);
ksession.fireAllRules();
print(aggrMonitor);
checkAgendaTotals(aggrMonitor, 1, 0, 1);
checkTotalFactCount(aggrMonitor, 1);
tft = checkTotalFiringTimeGEQ(aggrMonitor, tft);
checkTotalSessions(aggrMonitor, 1);
checkStatsForProcess(aggrMonitor, "com.sample.HelloWorld", 2, 2, 6);
checkStatsForProcess(aggrMonitor, "com.sample.CiaoWorld", 1, 1, 3);
LOG.debug("---");
KieSession ksession2 = kc.newKieSession(KSESSION1, sessionConf);
ksession2.insert("Ciao");
ksession.startProcess("com.sample.HelloWorld");
ksession.startProcess("com.sample.HelloWorld");
ksession.startProcess("com.sample.CiaoWorld");
ksession2.fireAllRules();
print(aggrMonitor);
checkAgendaTotals(aggrMonitor, 2, 0, 2);
checkTotalFactCount(aggrMonitor, 2);
tft = checkTotalFiringTimeGEQ(aggrMonitor, tft + 1);
checkTotalSessions(aggrMonitor, 2);
checkStatsForProcess(aggrMonitor, "com.sample.HelloWorld", 4, 4, 12);
checkStatsForProcess(aggrMonitor, "com.sample.CiaoWorld", 2, 2, 6);
LOG.debug("--- NOW for the STATELESS ---");
tft = 0;
StatelessKieSession stateless = kc.newStatelessKieSession(KSESSION2, sessionConf);
StatelessKieSessionMonitoringMXBean aggrMonitor2 = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy(KCONTAINER1, KBASE1, KieSessionType.STATELESS, KSESSION2), StatelessKieSessionMonitoringMXBean.class);
print(aggrMonitor2);
checkAgendaTotals(aggrMonitor2, 0, 0, 0);
checkRuleRuntimeTotals(aggrMonitor2, 0, 0);
tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft);
checkTotalSessions(aggrMonitor2, 0);
List<Command> cmds = new ArrayList<Command>();
cmds.add(CommandFactory.newInsert("Ciao"));
cmds.add(CommandFactory.newStartProcess("com.sample.HelloWorld"));
cmds.add(CommandFactory.newStartProcess("com.sample.HelloWorld"));
cmds.add(CommandFactory.newStartProcess("com.sample.CiaoWorld"));
BatchExecutionCommand batch = CommandFactory.newBatchExecution(cmds);
stateless.execute(batch);
print(aggrMonitor2);
checkAgendaTotals(aggrMonitor2, 1, 0, 1);
checkRuleRuntimeTotals(aggrMonitor2, 1, 0);
tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft + 1);
checkTotalSessions(aggrMonitor2, 1);
checkStatsForProcess(aggrMonitor2, "com.sample.HelloWorld", 2, 2, 6);
checkStatsForProcess(aggrMonitor2, "com.sample.CiaoWorld", 1, 1, 3);
stateless.execute(batch);
print(aggrMonitor2);
checkAgendaTotals(aggrMonitor2, 2, 0, 2);
checkRuleRuntimeTotals(aggrMonitor2, 2, 0);
tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft + 1);
checkTotalSessions(aggrMonitor2, 2);
checkStatsForProcess(aggrMonitor2, "com.sample.HelloWorld", 4, 4, 12);
checkStatsForProcess(aggrMonitor2, "com.sample.CiaoWorld", 2, 2, 6);
StatelessKieSession stateless2 = kc.newStatelessKieSession(KSESSION2, sessionConf);
LOG.debug(stateless + " " + stateless2);
checkTotalSessions(aggrMonitor2, 2);
stateless2.execute(batch);
print(aggrMonitor2);
checkAgendaTotals(aggrMonitor2, 3, 0, 3);
checkRuleRuntimeTotals(aggrMonitor2, 3, 0);
tft = checkTotalFiringTimeGEQ(aggrMonitor2, tft + 1);
checkTotalSessions(aggrMonitor2, 3);
checkStatsForProcess(aggrMonitor2, "com.sample.HelloWorld", 6, 6, 18);
checkStatsForProcess(aggrMonitor2, "com.sample.CiaoWorld", 3, 3, 9);
}
Aggregations