Search in sources :

Example 1 with KieBaseEventListener

use of org.kie.api.event.kiebase.KieBaseEventListener in project drools by kiegroup.

the class StatefulKnowledgeSessionImpl method dispose.

public void dispose() {
    if (!agenda.dispose(this)) {
        return;
    }
    if (logger != null) {
        try {
            logger.close();
        } catch (Exception e) {
        /* the logger was already closed, swallow */
        }
    }
    for (WorkingMemoryEntryPoint ep : this.entryPoints.values()) {
        ep.dispose();
    }
    this.ruleRuntimeEventSupport.clear();
    this.ruleEventListenerSupport.clear();
    this.agendaEventSupport.clear();
    for (KieBaseEventListener listener : kieBaseEventListeners) {
        this.kBase.removeEventListener(listener);
    }
    if (processRuntime != null) {
        this.processRuntime.dispose();
    }
    if (timerService != null) {
        this.timerService.shutdown();
    }
    if (this.workItemManager != null) {
        ((org.drools.core.process.instance.WorkItemManager) this.workItemManager).dispose();
    }
    this.kBase.disposeStatefulSession(this);
    if (this.mbeanRegistered.get()) {
        DroolsManagementAgent.getInstance().unregisterKnowledgeSessionUnderName(mbeanRegisteredCBSKey, this);
    }
}
Also used : KieBaseEventListener(org.kie.api.event.kiebase.KieBaseEventListener) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) IOException(java.io.IOException)

Example 2 with KieBaseEventListener

use of org.kie.api.event.kiebase.KieBaseEventListener in project drools by kiegroup.

the class StatefulKnowledgeSessionImpl method init.

private void init(SessionConfiguration config, Environment environment, long propagationContext) {
    this.config = config;
    this.environment = environment;
    this.propagationIdCounter = new AtomicLong(propagationContext);
    Globals globals = (Globals) this.environment.get(EnvironmentName.GLOBALS);
    if (globals != null) {
        if (!(globals instanceof GlobalResolver)) {
            this.globalResolver = new GlobalsAdapter(globals);
        } else {
            this.globalResolver = (GlobalResolver) globals;
        }
    } else {
        this.globalResolver = new MapGlobalResolver();
    }
    this.kieBaseEventListeners = new LinkedList<KieBaseEventListener>();
    this.lock = new ReentrantLock();
    this.timerService = TimerServiceFactory.getTimerService(this.config);
    this.opCounter = new AtomicLong(0);
    this.lastIdleTimestamp = new AtomicLong(-1);
}
Also used : Globals(org.kie.api.runtime.Globals) ReentrantLock(java.util.concurrent.locks.ReentrantLock) AtomicLong(java.util.concurrent.atomic.AtomicLong) KieBaseEventListener(org.kie.api.event.kiebase.KieBaseEventListener) MapGlobalResolver(org.drools.core.base.MapGlobalResolver) GlobalResolver(org.drools.core.spi.GlobalResolver) MapGlobalResolver(org.drools.core.base.MapGlobalResolver)

Example 3 with KieBaseEventListener

use of org.kie.api.event.kiebase.KieBaseEventListener in project drools by kiegroup.

the class MultipleKieBaseListenersTest method testKnowledgeBaseEventSupportLeak.

@Test
public void testKnowledgeBaseEventSupportLeak() throws Exception {
    final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, "");
    KieBaseEventListener listener = new DefaultKieBaseEventListener();
    kieBase.addEventListener(listener);
    kieBase.addEventListener(listener);
    kieBase.addEventListener(listener);
    Assertions.assertThat(kieBase.getKieBaseEventListeners().size()).isEqualTo(1);
    kieBase.removeEventListener(listener);
    Assertions.assertThat(kieBase.getKieBaseEventListeners()).isEmpty();
}
Also used : DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) KieBase(org.kie.api.KieBase) DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) KieBaseEventListener(org.kie.api.event.kiebase.KieBaseEventListener) Test(org.junit.Test)

Example 4 with KieBaseEventListener

use of org.kie.api.event.kiebase.KieBaseEventListener in project drools by kiegroup.

the class Misc2Test method testKnowledgeBaseEventSupportLeak.

@Test
public void testKnowledgeBaseEventSupportLeak() throws Exception {
    // JBRULES-3666
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration);
    KieBaseEventListener listener = new DefaultKieBaseEventListener();
    kbase.addEventListener(listener);
    kbase.addEventListener(listener);
    assertEquals(1, kbase.getKieBaseEventListeners().size());
    kbase.removeEventListener(listener);
    assertEquals(0, kbase.getKieBaseEventListeners().size());
}
Also used : DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) KieBase(org.kie.api.KieBase) KieBaseEventListener(org.kie.api.event.kiebase.KieBaseEventListener) DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) Test(org.junit.Test)

Example 5 with KieBaseEventListener

use of org.kie.api.event.kiebase.KieBaseEventListener in project drools by kiegroup.

the class Misc2Test method testKnowledgeBaseEventSupportLeak.

@Test
public void testKnowledgeBaseEventSupportLeak() throws Exception {
    // JBRULES-3666
    KieBase kbase = getKnowledgeBase();
    KieBaseEventListener listener = new DefaultKieBaseEventListener();
    kbase.addEventListener(listener);
    kbase.addEventListener(listener);
    assertEquals(1, ((KnowledgeBaseImpl) kbase).getKieBaseEventListeners().size());
    kbase.removeEventListener(listener);
    assertEquals(0, ((KnowledgeBaseImpl) kbase).getKieBaseEventListeners().size());
}
Also used : DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) KieBase(org.kie.api.KieBase) KieBaseEventListener(org.kie.api.event.kiebase.KieBaseEventListener) DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) Test(org.junit.Test)

Aggregations

KieBaseEventListener (org.kie.api.event.kiebase.KieBaseEventListener)6 Test (org.junit.Test)3 KieBase (org.kie.api.KieBase)3 DefaultKieBaseEventListener (org.kie.api.event.kiebase.DefaultKieBaseEventListener)3 IOException (java.io.IOException)2 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)2 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 MapGlobalResolver (org.drools.core.base.MapGlobalResolver)1 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 AsyncReceiveNode (org.drools.core.reteoo.AsyncReceiveNode)1 GlobalResolver (org.drools.core.spi.GlobalResolver)1 Globals (org.kie.api.runtime.Globals)1