Search in sources :

Example 86 with ProcessEventListener

use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.

the class TimerMigrationManagerTest method createRuntimeManagers.

protected void createRuntimeManagers(String processV1, String processV2, ProcessEventListener... eventListeners) {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource(processV1), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            for (ProcessEventListener lister : eventListeners) {
                listeners.add(lister);
            }
            return listeners;
        }

        @Override
        public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
            Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
            handlers.put("MyTask", new DoNothingWorkItemHandler());
            return handlers;
        }
    }).get();
    RuntimeEnvironment environment2 = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource(processV2), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            for (ProcessEventListener lister : eventListeners) {
                listeners.add(lister);
            }
            return listeners;
        }

        @Override
        public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
            Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
            handlers.put("MyTask", new DoNothingWorkItemHandler());
            return handlers;
        }
    }).get();
    createRuntimeManager(environment, environment2);
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) DefaultRegisterableItemsFactory(org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)

Example 87 with ProcessEventListener

use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.

the class SingletonRuntimeManagerTest method testTimerStartWithDeactivate.

@Test(timeout = 10000)
public void testTimerStartWithDeactivate() {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Hello", 1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-TimerStart.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(countDownListener);
            return listeners;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    countDownListener.waitTillCompleted();
    RuntimeEngine runtime1 = manager.getRuntimeEngine(EmptyContext.get());
    List<? extends ProcessInstanceLog> logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(1, logs.size());
    manager.disposeRuntimeEngine(runtime1);
    ((InternalRuntimeManager) manager).deactivate();
    countDownListener.reset(1);
    countDownListener.waitTillCompleted(2000);
    runtime1 = manager.getRuntimeEngine(EmptyContext.get());
    logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(1, logs.size());
    manager.disposeRuntimeEngine(runtime1);
    ((InternalRuntimeManager) manager).activate();
    countDownListener.reset(1);
    countDownListener.waitTillCompleted();
    runtime1 = manager.getRuntimeEngine(EmptyContext.get());
    logs = runtime1.getAuditService().findProcessInstances();
    assertEquals(2, logs.size());
    manager.disposeRuntimeEngine(runtime1);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 88 with ProcessEventListener

use of org.kie.api.event.process.ProcessEventListener in project jbpm by kiegroup.

the class DefaultRegisterableItemsFactoryTest method testJmsAuditCacheInstance.

@Test
public void testJmsAuditCacheInstance() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.jms", "kjar-jms-audit", "1.0.0");
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
    customDescriptor.getBuilder().auditMode(AuditMode.JMS);
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
    installKjar(releaseId, kJar1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).classLoader(this.getClass().getClassLoader()).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    assertNotNull(engine);
    AsyncAuditLogProducer asyncAuditLogProducer = null;
    KieSession kieSession = engine.getKieSession();
    for (ProcessEventListener listener : kieSession.getProcessEventListeners()) {
        if (listener instanceof AsyncAuditLogProducer) {
            asyncAuditLogProducer = (AsyncAuditLogProducer) listener;
            break;
        }
    }
    assertNotNull(asyncAuditLogProducer);
    manager.close();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession kieSession2 = engine2.getKieSession();
    AsyncAuditLogProducer asyncAuditLogProducer2 = null;
    for (ProcessEventListener listener : kieSession2.getProcessEventListeners()) {
        if (listener instanceof AsyncAuditLogProducer) {
            asyncAuditLogProducer2 = (AsyncAuditLogProducer) listener;
            break;
        }
    }
    assertNotNull(asyncAuditLogProducer2);
    // check if the instance is the same (cached)
    assertEquals(asyncAuditLogProducer, asyncAuditLogProducer2);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) AsyncAuditLogProducer(org.jbpm.process.audit.jms.AsyncAuditLogProducer) KieSession(org.kie.api.runtime.KieSession) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) AbstractDeploymentDescriptorTest(org.jbpm.runtime.manager.impl.deploy.AbstractDeploymentDescriptorTest) Test(org.junit.Test)

Aggregations

ProcessEventListener (org.kie.api.event.process.ProcessEventListener)88 Test (org.junit.Test)77 KieSession (org.kie.api.runtime.KieSession)64 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)64 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)61 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)58 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)49 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)44 ArrayList (java.util.ArrayList)41 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)33 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)30 HashMap (java.util.HashMap)29 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)29 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)27 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)20 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)18 KieBase (org.kie.api.KieBase)18 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)17 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)17 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)14