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);
}
}
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);
}
}
}
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());
}
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);
}
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());
}
Aggregations