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

The following examples show how to use org.kie.api.KieServices#getKieClasspathContainer() . 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: BaseTest.java    From iot-ocp with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    KieServices kieServices = KieServices.Factory.get();

    KieContainer kContainer = kieServices.getKieClasspathContainer();
    Results verifyResults = kContainer.verify();
    for (Message m : verifyResults.getMessages()) {
        LOG.debug("Kie container message: {}", m);
    }

    KieBase kieBase = kContainer.getKieBase();
    LOG.debug("Created kieBase");

    for ( KiePackage kp : kieBase.getKiePackages() ) {
        for (Rule rule : kp.getRules()) {
            LOG.debug("kp " + kp + " rule " + rule.getName());
        }
    }

    session = kieBase.newKieSession();
    LOG.info(session.getGlobals().toString());
    Logger kieLogger = LoggerFactory.getLogger(this.getClass());
   // session.setGlobal("logger",kieLogger);
}
 
Example 2
Source File: RulesConfiguration.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Kie container.
 *
 * @return the kie container
 */
@Bean
public KieContainer kieContainer() {
	final KieServices kieServices = KieServices.Factory.get();

	final KieContainer kContainer = kieServices.getKieClasspathContainer();
	LOGGER.info("Using classloader {}, parent {}",kContainer.getClassLoader(),kContainer.getClassLoader().getParent());
	
	final Results verifyResults = kContainer.verify();
	for (final Message m : verifyResults.getMessages()) {
		LOGGER.warn("Kie container message: {}", m);
	}

	final KieBase kieBase = kContainer.getKieBase();
	for (final KiePackage kp : kieBase.getKiePackages()) {
		for (final Rule rule : kp.getRules()) {
			LOGGER.info("Loadded Rule: {} {}", kp, rule.getName());
		}
	}
	

	return kContainer;
}
 
Example 3
Source File: HelloWorldExample.java    From drools-examples with Apache License 2.0 5 votes vote down vote up
public static final void main(final String[] args) {
    // KieServices is the factory for all KIE services 
    KieServices ks = KieServices.Factory.get();
    
    // From the kie services, a container is created from the classpath
    KieContainer kc = ks.getKieClasspathContainer();

    execute( kc );
}
 
Example 4
Source File: HelloWorldExample.java    From tools-journey with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) {
    // KieServices is the factory for all KIE services 
    KieServices ks = KieServices.Factory.get();

    // From the kie services, a container is created from the classpath
    KieContainer kc = ks.getKieClasspathContainer();

    execute(kc);
}
 
Example 5
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();
}
 
Example 6
Source File: KnowledgeSessionHelper.java    From droolscourse with Apache License 2.0 4 votes vote down vote up
public static KieContainer createRuleBase() {

        KieServices ks = KieServices.Factory.get();
        KieContainer kieContainer = ks.getKieClasspathContainer();
        return kieContainer;
    }
 
Example 7
Source File: KnowledgeSessionHelper.java    From droolscourse with Apache License 2.0 4 votes vote down vote up
public static KieContainer createRuleBase() {

        KieServices ks = KieServices.Factory.get();
        KieContainer kieContainer = ks.getKieClasspathContainer();
        return kieContainer;
    }
 
Example 8
Source File: KnowledgeSessionHelper.java    From droolscourse with Apache License 2.0 4 votes vote down vote up
public static KieContainer createRuleBase() {

        KieServices ks = KieServices.Factory.get();
        KieContainer kieContainer = ks.getKieClasspathContainer();
        return kieContainer;
    }
 
Example 9
Source File: GameplayRuleTest.java    From hacep with Apache License 2.0 4 votes vote down vote up
private static KieContainer setupKieContainer() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieContainer kieContainer = ks.getKieClasspathContainer();
    return kieContainer;
}
 
Example 10
Source File: WorkflowEngineImpl.java    From tutorials with MIT License 4 votes vote down vote up
private KieBase getKieBase(String kbaseId) {
    KieServices ks = KieServices.Factory.get();
    KieContainer kContainer = ks.getKieClasspathContainer();
    KieBase kbase = kContainer.getKieBase(kbaseId);
    return kbase;
}
 
Example 11
Source File: DroolsScoreExample.java    From drools-examples with Apache License 2.0 3 votes vote down vote up
/**
 * 计算额外积分金额 规则如下: 订单原价金额
 * 100以下, 不加分
 * 100-500 加100分
 * 500-1000 加500分
 * 1000 以上 加1000分
 *
 * @param args
 * @throws Exception
 */
public static final void main(final String[] args) throws Exception{
    // KieServices is the factory for all KIE services
    KieServices ks = KieServices.Factory.get();

    // From the kie services, a container is created from the classpath
    KieContainer kc = ks.getKieClasspathContainer();

    execute( kc );
}
 
Example 12
Source File: DroolsScoreExample.java    From tools-journey with Apache License 2.0 3 votes vote down vote up
/**
 * 计算额外积分金额 规则如下: 订单原价金额
 * 100以下, 不加分
 * 100-500 加100分
 * 500-1000 加500分
 * 1000 以上 加1000分
 *
 * @param args args
 * @throws Exception exception
 */
public static void main(final String[] args) throws Exception {
    // KieServices is the factory for all KIE services
    KieServices ks = KieServices.Factory.get();

    // From the kie services, a container is created from the classpath
    KieContainer kc = ks.getKieClasspathContainer();

    execute(kc);
}
 
Example 13
Source File: PhreakInspector.java    From drools-workshop with Apache License 2.0 3 votes vote down vote up
private KieContainer createContainer() {

        KieServices ks = KieServices.Factory.get();
        KieContainer kContainer = ks.getKieClasspathContainer();

        this.assertBuildResults(kContainer.verify());

        return kContainer;
    }