use of org.jbpm.executor.api.CommandContext in project jBPM5-Developer-Guide by Salaboy.
the class AsyncGenericWorkItemHandler method executeWorkItem.
/**
* This handler expects 3 input parameters:
* command: the command to be scheduled using Executor Service component.
* callbacks: the callbacks that should be executed by Executor Service
* after the command is performed.
* waitTillComplete: Should the work item be completed or not right
* after the command is scheduled? In the case it should wait, the
* completion of the work item should be delegated to the executor service
* by using a command or callback that completes it.
* @param workItem
* @param manager
*/
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
long workItemId = workItem.getId();
String command = (String) workItem.getParameter("command");
String callbacks = (String) workItem.getParameter("callbacks");
this.execKey = workItem.getName() + "_" + workItem.getProcessInstanceId() + "_" + workItemId + "@sessionId=" + this.sessionId;
CommandContext ctx = new CommandContext();
for (Map.Entry<String, Object> entry : workItem.getParameters().entrySet()) {
if (entry.getValue() instanceof Object) {
ctx.setData(entry.getKey(), entry.getValue());
}
}
ctx.setData("_workItemId", String.valueOf(workItemId));
ctx.setData("callbacks", callbacks);
ctx.setData("businessKey", this.execKey);
Long requestId = this.executor.scheduleRequest(command, ctx);
workItem.getParameters().put("requestId", requestId);
String sWaitTillComplete = (String) workItem.getParameter("waitTillComplete");
Boolean waitTillComplete = sWaitTillComplete == null ? null : Boolean.valueOf(sWaitTillComplete);
if (waitTillComplete == null || !waitTillComplete.booleanValue()) {
manager.completeWorkItem(workItemId, workItem.getResults());
}
}
use of org.jbpm.executor.api.CommandContext in project jBPM5-Developer-Guide by Salaboy.
the class BasicExecutorBaseTest method simpleExcecutionTest.
/**
* Tests a simple command request.
* @throws InterruptedException
*/
@Test
public void simpleExcecutionTest() throws InterruptedException {
CommandContext ctxCMD = new CommandContext();
ctxCMD.setData("businessKey", UUID.randomUUID().toString());
//A job is scheduled by using its CDI @Name
executor.scheduleRequest("PrintOutCmd", ctxCMD);
Thread.sleep(10000);
//after 10 seconds we should have no errors, no queued requests and
//one executed request.
List<RequestInfo> inErrorRequests = executor.getInErrorRequests();
assertEquals(0, inErrorRequests.size());
List<RequestInfo> queuedRequests = executor.getQueuedRequests();
assertEquals(0, queuedRequests.size());
List<RequestInfo> executedRequests = executor.getExecutedRequests();
assertEquals(1, executedRequests.size());
}
Aggregations