Search in sources :

Example 6 with CommandContext

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());
    }
}
Also used : CommandContext(org.jbpm.executor.api.CommandContext) Map(java.util.Map)

Example 7 with CommandContext

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());
}
Also used : CommandContext(org.jbpm.executor.api.CommandContext) RequestInfo(org.jbpm.executor.entities.RequestInfo) Test(org.junit.Test)

Aggregations

CommandContext (org.jbpm.executor.api.CommandContext)7 RequestInfo (org.jbpm.executor.entities.RequestInfo)6 Test (org.junit.Test)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ErrorInfo (org.jbpm.executor.entities.ErrorInfo)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 List (java.util.List)1 Map (java.util.Map)1 Transactional (org.jboss.seam.transaction.Transactional)1 Command (org.jbpm.executor.api.Command)1 CommandCallback (org.jbpm.executor.api.CommandCallback)1 ExecutionResults (org.jbpm.executor.api.ExecutionResults)1