Java Code Examples for org.kie.api.runtime.KieContainer#dispose()
The following examples show how to use
org.kie.api.runtime.KieContainer#dispose() .
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: KieSessionUtils.java From hacep with Apache License 2.0 | 5 votes |
public static void dispose(KieContainer kieContainer) { if (kieContainer != null) { try { kieContainer.dispose(); } catch (Exception e) { LOGGER.error("Unexpected exception", e); } } }
Example 2
Source File: MBeansMonitoringTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@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 3
Source File: MBeansMonitoringTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testContainerMBeans() throws Exception { String drl = "package org.drools.compiler.test\n" + "import org.drools.compiler.StockTick\n" + "declare StockTick\n" + " @role(event)\n" + " @expires(10s)\n" + "end\n" + "rule X\n" + "when\n" + " StockTick()\n" + "then\n" + "end"; 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() ) ); ReleaseId releaseId1 = ks.newReleaseId( "org.kie.test", "mbeans", "1.0.0" ); createKJar( ks, kproj, releaseId1, null, drl ); KieContainer kc = ks.newKieContainer( releaseId1 ); KieBase kiebase = kc.getKieBase( KBASE1 ); kc.newKieSession(KSESSION1); kiebase.newKieSession(); String kc1ID = ((InternalKieContainer) kc).getContainerId(); MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer(); LOG.debug("{}", mbserver.queryNames(new ObjectName("org.kie:kcontainerId="+ObjectName.quote(kc1ID)+",*"), null) ); ReleaseId verRelease = ks.newReleaseId("org.kie.test", "mbeans", "RELEASE" ); KieContainer kc2 = ks.newKieContainer( "Matteo", verRelease ); kc2.newKieSession(KSESSION1); KieContainerMonitorMXBean c1Monitor = JMX.newMXBeanProxy( mbserver, DroolsManagementAgent.createObjectNameBy(kc1ID), KieContainerMonitorMXBean.class); assertEquals(releaseId1.toExternalForm(), c1Monitor.getConfiguredReleaseIdStr()); assertEquals(releaseId1.toExternalForm(), c1Monitor.getResolvedReleaseIdStr()); assertTrue(c1Monitor.getConfiguredReleaseId().sameGAVof(releaseId1)); assertTrue(c1Monitor.getResolvedReleaseId().sameGAVof(releaseId1)); assertEquals(releaseId1.getVersion(), c1Monitor.getConfiguredReleaseId().getVersion()); assertEquals(releaseId1.getVersion(), c1Monitor.getResolvedReleaseId().getVersion()); KieContainerMonitorMXBean c2Monitor = JMX.newMXBeanProxy( mbserver, DroolsManagementAgent.createObjectNameBy("Matteo"), KieContainerMonitorMXBean.class); assertEquals(verRelease.toExternalForm(), c2Monitor.getConfiguredReleaseIdStr()); assertEquals(releaseId1.toExternalForm(), c2Monitor.getResolvedReleaseIdStr()); assertTrue(c2Monitor.getConfiguredReleaseId().sameGAVof(verRelease)); assertTrue(c2Monitor.getResolvedReleaseId().sameGAVof(releaseId1)); assertEquals(verRelease.getVersion(), c2Monitor.getConfiguredReleaseId().getVersion()); assertEquals(releaseId1.getVersion(), c2Monitor.getResolvedReleaseId().getVersion()); // MBean are supported only via KieContainer public API. assertEquals(3, mbserver.queryNames(new ObjectName("org.kie:kcontainerId="+ObjectName.quote(kc1ID)+",*"), null).size()); kc.dispose(); assertEquals(0, mbserver.queryNames(new ObjectName("org.kie:kcontainerId="+ObjectName.quote(kc1ID)+",*"), null).size()); assertEquals(3, mbserver.queryNames(new ObjectName("org.kie:kcontainerId="+ObjectName.quote("Matteo")+",*"), null).size()); }