如何在完成后返回单个工作项处理程序的结果

时间:2013-09-23 04:31:22

标签: jbpm

请帮助我,我是jbpm的新手,一切都工作正常,但我希望在完成我的个人工作项处理程序后返回我的“结果”输出参数,这是我的代码。

public void CreateCompute(String body) throws Exception
    {
        KnowledgeBase kbase = readKnowledgeBaseForCompute();
        AssignTEPIPOnHypervisor tepIP = new AssignTEPIPOnHypervisor();
        CreateIntegratedBridgeOnHost IB = new CreateIntegratedBridgeOnHost();
        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
        ksession.getWorkItemManager().registerWorkItemHandler("AssignTEPIPToHypervisors", tepIP);
        ksession.getWorkItemManager().registerWorkItemHandler("CreateIBOnHosts", IB);
        System.out.println(" >>> Let's create a Persistent Knowledge Session");
        Map<String,Object> params = new HashMap<String, Object>();
        params.put("payload", body);
        params.put("session_id",Integer.toString(ksession.getId()));
        System.out.println(">>> Let's Start the Process");
        ksession.startProcess("com.cl.cloud.createcompute", params);
        System.out.println(">>> Disposing Session");
    }

2 个答案:

答案 0 :(得分:0)

在实现WorkItemHandler的类中,您有以下方法: void executeWorkItem(WorkItem workItem,                          WorkItemManager manager);

workItemManager有一个方法:

void completeWorkItem(long id,                           地图结果);

这些结果是从workItem执行返回的结果。 根据您的BPMN2流程中的数据输入/输出映射,这些结果将映射到流程变量。在这种情况下,您需要确保dataOutput映射是正确的,并且您将看到过程变量的更新方式。

希望这有帮助

答案 1 :(得分:0)

public class HelloProcessExtension implements WorkItemHandler {


public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
    System.out.println("--> HelloProcessExtension.abortWorkItem()...");
    manager.abortWorkItem(workItem.getId());
}

public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    System.out.println("--> HelloProcessExtension.executeWorkItem()...");
    System.out.println(workItem.getParameter("param1") + "\n"
    + workItem.getParameter("param2") + "\n"
    + workItem.getParameter("param3"));
    Map<String, Object> results = new HashMap<String, Object>();
    results.put("price", new Integer(10));
    System.out.println("--> HelloProcessExtension.executeWorkItem()... sent reults");
    manager.completeWorkItem(workItem.getId(), results);
}
}

地图包含密钥price,此密钥名称应该是任务中的输入或输出变量名称。任务中的变量price应该映射到Process变量。