0

我在一篇 jbpm 论坛文章https://community.jboss.org/thread/165545中读到,将 HumanTaskHandler 描述为异步工作项处理程序,当我们使用异步人工任务处理程序时,我们必须完成任何任务,taskclient.complete()然后向流程引擎发出信号 ksession.getWorkItemManager().completeWorkItem().

这是在使用异步工作项处理程序时完成任务的理想方法吗?
这就像完成一个任务两次。实际上,当我们调用complete()and时发生了什么completeWorkItem()
请澄清。

4

2 回答 2

2

如果您在调用 taskClient.complete() 方法时已正确设置所有内容,则会话将通知并且 ksession.getWorkItemManager().completeWorkItem() 将自动为您调用。没有必要自己调用它。您只需要记住将 WorkItemHandler 注册到会话并保持会话处于活动状态,以便通知它。干杯

于 2012-05-24T12:12:45.613 回答
1

对于 JBPM 6,我已经实现了一个像这样的异步工作项处理程序,因为管理器和 ksession 无法完成任务。RuntimeManagerRegistry 的 Maven 依赖项是 kie 内部版本 6.0.1.Final,jsoup 1.7.2。

    import java.io.IOException;
    import org.drools.core.process.instance.impl.WorkItemImpl;
    import org.jsoup.Jsoup;
    import org.kie.api.runtime.manager.RuntimeEngine;
    import org.kie.api.runtime.manager.RuntimeManager;
    import org.kie.api.runtime.process.WorkItem;
    import org.kie.api.runtime.process.WorkItemHandler;
    import org.kie.api.runtime.process.WorkItemManager;
    import org.kie.internal.runtime.manager.RuntimeManagerRegistry;
    import org.kie.internal.runtime.manager.context.EmptyContext;


    public class AsyncWorkItemHandler implements WorkItemHandler {
        boolean abort = false;

        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
            manager.abortWorkItem(workItem.getId());
            abort = true;
        }

        @Override
        public void executeWorkItem(final WorkItem workItem, final WorkItemManager manager) {
            final String depId = ((WorkItemImpl) workItem).getDeploymentId();
            new Thread(new Runnable() {
                String url = (String) workItem.getParameter("url");
                org.jsoup.nodes.Document document = null;

                public void run() {
                    while (true) {
                        if (abort == true) {
                            break;
                        }
                        // example of polling a web site for specific text
                        // before task can complete say "release"
                        try {
                            document = Jsoup.connect(url).timeout(3000).get();
                        }
                        catch (IOException e) {
                            e.printStackTrace();
                        }
                        String info = document.text();
                        if (info.contains("release")) {
                            if (depId != null) {
                                RuntimeManager manager = RuntimeManagerRegistry.get().getManager(depId);
                                RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
                                engine.getKieSession().getWorkItemManager().completeWorkItem(workItem.getId(), null);
                                manager.disposeRuntimeEngine(engine);
                            }
                            else {
                                // this is for eclipse testing because depId is not
                                // available
                                manager.completeWorkItem(workItem.getId(), null);
                            }
                            break;
                        }
                        try {
                            Thread.sleep(2000);
                        }
                        catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }).start();
        }
    }
于 2014-02-28T22:38:59.610 回答