JBoss Community

Re: How to create a simple waiting workflow

created by Jan Uhlir in jBPM - View the full discussion

This works (6a):

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/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 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

Start a new discussion in jBPM at Community