Search in sources :

Example 71 with RuntimeEngine

use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.

the class PerRequestRuntimeManager method signalEvent.

@Override
public void signalEvent(String type, Object event) {
    RuntimeEngine runtimeEngine = getRuntimeEngine(EmptyContext.get());
    runtimeEngine.getKieSession().signalEvent(type, event);
    if (canDispose(runtimeEngine)) {
        disposeRuntimeEngine(runtimeEngine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine)

Example 72 with RuntimeEngine

use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.

the class JMSSignalReceiver method onMessage.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void onMessage(Message message) {
    if (message instanceof BytesMessage) {
        String deploymentId;
        Long processInstanceId;
        String signal;
        Long workItemId;
        Object data;
        BytesMessage bytesMessage = (BytesMessage) message;
        RuntimeManager runtimeManager = null;
        RuntimeEngine engine = null;
        try {
            deploymentId = (String) bytesMessage.getObjectProperty("KIE_SignalDeploymentId");
            if (deploymentId == null) {
                deploymentId = (String) bytesMessage.getObjectProperty("KIE_DeploymentId");
            }
            signal = (String) bytesMessage.getObjectProperty("KIE_Signal");
            processInstanceId = (Long) bytesMessage.getObjectProperty("KIE_SignalProcessInstanceId");
            workItemId = (Long) bytesMessage.getObjectProperty("KIE_SignalWorkItemId");
            logger.debug("Deployment id '{}', signal '{}', processInstanceId '{}', workItemId '{}'", deploymentId, signal, processInstanceId, workItemId);
            Collection<String> availableRuntimeManagers = matchDeployments(deploymentId, RuntimeManagerRegistry.get().getRegisteredIdentifiers());
            for (String matchedDeploymentId : availableRuntimeManagers) {
                try {
                    runtimeManager = RuntimeManagerRegistry.get().getManager(matchedDeploymentId);
                    if (runtimeManager == null) {
                        throw new IllegalStateException("There is no runtime manager for deployment " + matchedDeploymentId);
                    }
                    logger.debug("RuntimeManager found for deployment id {}, reading message content with custom class loader of the deployment", matchedDeploymentId);
                    data = readData(bytesMessage, ((InternalRuntimeManager) runtimeManager).getEnvironment().getClassLoader());
                    logger.debug("Data read successfully with output {}", data);
                    engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
                    // perform operation either signal or complete work item
                    if (workItemId != null) {
                        Map<String, Object> results = new HashMap<String, Object>();
                        if (data != null) {
                            if (data instanceof Map) {
                                results.putAll((Map) data);
                            } else {
                                results.put("Data", data);
                            }
                        }
                        logger.debug("About to complete work item with id {} and data {}", workItemId, results);
                        engine.getKieSession().getWorkItemManager().completeWorkItem(workItemId, results);
                        logger.debug("Successfully completed work item with id {}", workItemId);
                    } else if (signal != null) {
                        if (processInstanceId != null) {
                            logger.debug("About to signal process instance with id {} and event data {} with signal {}", processInstanceId, data, signal);
                            engine.getKieSession().signalEvent(signal, data, processInstanceId);
                        } else {
                            logger.debug("About to broadcast signal {} and event data {}", signal, data);
                            runtimeManager.signalEvent(signal, data);
                        }
                        logger.debug("Signal completed successfully for signal {} with data {}", signal, data);
                    } else {
                        logger.warn("No signal or workitem id is given, skipping this message");
                    }
                } catch (Exception e) {
                    logger.error("Unexpected exception while signaling: {}", e.getMessage(), e);
                } finally {
                    if (runtimeManager != null && engine != null) {
                        runtimeManager.disposeRuntimeEngine(engine);
                    }
                }
            }
        } catch (Exception e) {
            logger.error("Unexpected exception while processing signal JMS message: {}", e.getMessage(), e);
        }
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) BytesMessage(javax.jms.BytesMessage) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) JMSException(javax.jms.JMSException)

Example 73 with RuntimeEngine

use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.

the class KjarRuntimeEnvironmentTest method testScriptTaskFromKjarUsingNamedKbaseKsession.

@Test
public void testScriptTaskFromKjarUsingNamedKbaseKsession() {
    KieServices ks = KieServices.Factory.get();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION), "defaultKieBase", "defaultKieSession").userGroupCallback(userGroupCallback).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = engine.getKieSession().startProcess("ScriptTask", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) KieServices(org.kie.api.KieServices) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 74 with RuntimeEngine

use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.

the class KjarRuntimeEnvironmentTest method testUserTaskFromKjar.

@Test
public void testUserTaskFromKjar() {
    KieServices ks = KieServices.Factory.get();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION)).userGroupCallback(userGroupCallback).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = engine.getKieSession().startProcess("UserTask", params);
    List<TaskSummary> tasks = engine.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    engine.getTaskService().start(taskId, "john");
    engine.getTaskService().complete(taskId, "john", null);
    processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    manager.disposeRuntimeEngine(engine);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) KieServices(org.kie.api.KieServices) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 75 with RuntimeEngine

use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.

the class KjarRuntimeEnvironmentTest method testScriptTaskFromKjar.

@Test
public void testScriptTaskFromKjar() {
    KieServices ks = KieServices.Factory.get();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION)).userGroupCallback(userGroupCallback).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = engine.getKieSession().startProcess("ScriptTask", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) KieServices(org.kie.api.KieServices) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)388 Test (org.junit.Test)269 KieSession (org.kie.api.runtime.KieSession)265 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)229 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)149 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)116 TaskService (org.kie.api.task.TaskService)111 HashMap (java.util.HashMap)110 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)105 TaskSummary (org.kie.api.task.model.TaskSummary)86 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)82 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)67 ArrayList (java.util.ArrayList)59 InternalTaskService (org.kie.internal.task.api.InternalTaskService)59 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)58 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)49 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)43 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)40 UserTaskService (org.jbpm.services.api.UserTaskService)36 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)34