[jboss-user] [jBPM] - Re: How to create a simple waiting workflow
Jan Uhlir
do-not-reply at jboss.com
Thu Feb 16 15:07:15 EST 2012
Jan Uhlir [https://community.jboss.org/people/espinosa_cz] created the discussion
"Re: How to create a simple waiting workflow"
To view the discussion, visit: https://community.jboss.org/message/717300#717300
--------------------------------------------------------------
This works (6a):
https://community.jboss.org/servlet/JiveServlet/showImage/17999/jbpm+screenshot+wait+state+working+6a.png https://community.jboss.org/servlet/JiveServlet/downloadImage/17999/jbpm+screenshot+wait+state+working+6a.png
This works too (6b):
https://community.jboss.org/servlet/JiveServlet/showImage/18000/jbpm+screenshot+wait+state+working+6b.png https://community.jboss.org/servlet/JiveServlet/downloadImage/18000/jbpm+screenshot+wait+state+working+6b.png
*BPMN2 Code 6a:*
*BPMN2 Code 6b:*
*Code for class behind JavaTask task node:*
public class JavaTask6WorkItemHandler implements WorkItemHandler {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
System.out.println("Inside JavaTask : " + workItem.getName());
// notify manager that work item has been completed
// Essential! Custom tasks are by default set "wait for completion = true", this makes them "false"
manager.completeWorkItem(workItem.getId(), null);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
// do nothing
}
}
*Test run code, start and signalize the process:*
public class SimpleProcess6aRun {
public static void main(String[] args) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("simple_process_6a.bpmn"), ResourceType.BPMN2);
KnowledgeBase kbase = kbuilder.newKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.getWorkItemManager().registerWorkItemHandler("JavaTask6", new JavaTask6WorkItemHandler());
ProcessInstance processInstance = ksession.startProcess("SimpleProcess6a");
Assert.assertNotNull(processInstance);
// print all running processes
Collection allProcesses = ksession.getProcessInstances();
for (ProcessInstance p : allProcesses) {
System.out.println("Running - " + p);
}
// test wait state
Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
// send signal
// ksession.signalEvent("fooSignal", "fooSignal"); // global signal
processInstance.signalEvent("fooSignal", null); // process specific signal
// test successful finish (test state)
Assert.assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
}
// the code for SimpleProcess6bRun (6b process) is analogous
This https://community.jboss.org/thread/165545 forum thread is related too. I found Esteban Aliverti comment very helpful and so his examples on github.
Is there any real difference between 6a and 6b? Otherwise I am going to use the simpler variant, without Gateway.
If I have, let's say, process with 20 wait nodes, I have to add 20 more Event nodes after every task?
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/717300#717300]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120216/8333799a/attachment.html
More information about the jboss-user
mailing list