2

请帮助我,我是 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");
    }
4

2 回答 2

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

map 包含 key price,这个键名应该是你任务中的输入或输出变量名。任务中的变量price应该映射到 Process 变量。

于 2014-08-08T20:56:33.893 回答
0

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

workItemManager 有一个方法:

void completeWorkItem(long id, Map results);

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

希望这可以帮助

于 2013-09-23T20:20:23.727 回答