Java Code Examples for org.kie.api.KieServices#newKieClasspathContainer()

The following examples show how to use org.kie.api.KieServices#newKieClasspathContainer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleRuleActivator.java    From servicemix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(BundleContext context) throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieContainer kcont = ks.newKieClasspathContainer(getClass()
            .getClassLoader());
    KieBase kbase = kcont.getKieBase("SimpleRuleKBase");

    logger.info("KieSession newKieSession.");
    ksession = kbase.newKieSession();

    ksession.addEventListener(new DebugAgendaEventListener());
    ksession.addEventListener(new DebugRuleRuntimeEventListener());

    Customer customer = customerPoor();

    logger.info("KieSession fireAllRules. {}", customer);
    FactHandle fh = ksession.insert(customer);
    ksession.fireAllRules();
    ksession.delete(fh);
    logger.info("After rule {}", customer);

    customer = customerNormal();
    logger.info("KieSession fireAllRules. {}", customer);
    fh = ksession.insert(customer);
    ksession.fireAllRules();
    ksession.delete(fh);
    logger.info("After rule {}", customer);

    customer = customerVip();
    logger.info("KieSession fireAllRules. {}", customer);
    fh = ksession.insert(customer);
    ksession.fireAllRules();
    ksession.delete(fh);

    logger.info("After rule {}", customer);
}
 
Example 2
Source File: SimpleTest.java    From servicemix with Apache License 2.0 5 votes vote down vote up
/**
 * beforeClass.
 */
@BeforeClass
public static void beforeClass() {
    KieServices ks = KieServices.Factory.get();
    KieContainer kcont = ks.newKieClasspathContainer();
    KieBase kbase = kcont.getKieBase("SimpleRuleKBase");
    ksession = kbase.newKieSession();
    ksession.addEventListener(new DebugAgendaEventListener());
    ksession.addEventListener(new DebugRuleRuntimeEventListener());
}
 
Example 3
Source File: MBeansMonitoringTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testKieClasspathMBeans() throws Exception {
    MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
    KieServices ks = KieServices.Factory.get();

    KieContainer kc = ks.getKieClasspathContainer("myID");
    
    KieContainerMonitorMXBean c1Monitor = JMX.newMXBeanProxy(
            mbserver,
            DroolsManagementAgent.createObjectNameBy("myID"),
            KieContainerMonitorMXBean.class);
    KieBase kb = kc.getKieBase("org.kie.monitoring.kbase1");
    KieSession statefulKieSession = kc.newKieSession("org.kie.monitoring.kbase1.ksession1");
    StatelessKieSession statelessKieSession = kc.newStatelessKieSession("org.kie.monitoring.kbase1.ksession2");
    
    KieSessionMonitoringMXBean statefulKieSessionMonitor = JMX.newMXBeanProxy(
            mbserver,
            DroolsManagementAgent.createObjectNameBy("myID", "org.kie.monitoring.kbase1", KieSessionType.STATEFUL, "org.kie.monitoring.kbase1.ksession1"),
            KieSessionMonitoringMXBean.class);
    StatelessKieSessionMonitoringMXBean statelessKieSessionMonitor = JMX.newMXBeanProxy(
            mbserver,
            DroolsManagementAgent.createObjectNameBy("myID", "org.kie.monitoring.kbase1", KieSessionType.STATEFUL, "org.kie.monitoring.kbase1.ksession1"),
            StatelessKieSessionMonitoringMXBean.class);
    
    assertEquals("myID", c1Monitor.getContainerId() );
    assertTrue(c1Monitor.getConfiguredReleaseId().sameGAVof(KieContainerMonitorMXBean.CLASSPATH_KIECONTAINER_RELEASEID));
    assertTrue(c1Monitor.getResolvedReleaseId().sameGAVof(KieContainerMonitorMXBean.CLASSPATH_KIECONTAINER_RELEASEID));
    assertEquals("org.kie.monitoring.kbase1.ksession1", statefulKieSessionMonitor.getKieSessionName());
    assertEquals("org.kie.monitoring.kbase1",           statefulKieSessionMonitor.getKieBaseId());
    assertEquals("org.kie.monitoring.kbase1.ksession1", statelessKieSessionMonitor.getKieSessionName());
    assertEquals("org.kie.monitoring.kbase1",           statelessKieSessionMonitor.getKieBaseId());
    
    
    KieContainer kc2 = ks.newKieClasspathContainer("myID2");
    KieContainerMonitorMXBean c2Monitor = JMX.newMXBeanProxy(
            mbserver,
            DroolsManagementAgent.createObjectNameBy("myID2"),
            KieContainerMonitorMXBean.class);
    KieBase kb2 = kc2.getKieBase("org.kie.monitoring.kbase1");
    KieSession statefulKieSession2 = kc2.newKieSession("org.kie.monitoring.kbase1.ksession1");
    StatelessKieSession statelessKieSession2 = kc2.newStatelessKieSession("org.kie.monitoring.kbase1.ksession2");
    KieSessionMonitoringMXBean statefulKieSessionMonitor2 = JMX.newMXBeanProxy(
            mbserver,
            DroolsManagementAgent.createObjectNameBy("myID2", "org.kie.monitoring.kbase1", KieSessionType.STATEFUL, "org.kie.monitoring.kbase1.ksession1"),
            KieSessionMonitoringMXBean.class);
    StatelessKieSessionMonitoringMXBean statelessKieSessionMonitor2 = JMX.newMXBeanProxy(
            mbserver,
            DroolsManagementAgent.createObjectNameBy("myID2", "org.kie.monitoring.kbase1", KieSessionType.STATEFUL, "org.kie.monitoring.kbase1.ksession1"),
            StatelessKieSessionMonitoringMXBean.class);
    
    assertEquals("myID2", c2Monitor.getContainerId() );
    assertTrue(c2Monitor.getConfiguredReleaseId().sameGAVof(KieContainerMonitorMXBean.CLASSPATH_KIECONTAINER_RELEASEID));
    assertTrue(c2Monitor.getResolvedReleaseId().sameGAVof(KieContainerMonitorMXBean.CLASSPATH_KIECONTAINER_RELEASEID));
    assertEquals("org.kie.monitoring.kbase1.ksession1", statefulKieSessionMonitor2.getKieSessionName());
    assertEquals("org.kie.monitoring.kbase1",           statefulKieSessionMonitor2.getKieBaseId());
    assertEquals("org.kie.monitoring.kbase1.ksession1", statelessKieSessionMonitor2.getKieSessionName());
    assertEquals("org.kie.monitoring.kbase1",           statelessKieSessionMonitor2.getKieBaseId());
    
    kc.dispose();
    kc2.dispose();
}