[jboss-user] [jBPM] New message: "[jBPM 4.3] Cancel Job/Timer"

Nils Preusker do-not-reply at jboss.com
Tue Jan 26 07:41:07 EST 2010


User development,

A new message was posted in the thread "[jBPM 4.3] Cancel Job/Timer":

http://community.jboss.org/message/522289#522289

Author  : Nils Preusker
Profile : http://community.jboss.org/people/nilspreusker

Message:
--------------------------------------------------------------
Hi,

I'm trying to find a way to cancel or delete jobs or timers to move a process instance into the state "active-root". 

Here is a more detailed description what I'm trying to do: I have a state - "wait state" - that contains a transition with a timer, which will execute a java activity - "do something". Now I want to provide an alternative path of execution, in case something goes wrong with the java activity. Since the process instance is in state "inactive scope" (because the job has to be finished before the execution can move on), I'll get an exception when I signal the process instance to move to "another wait state". I suppose, that by deleting or canceling the timer and the associated job, the state of the process instance would be set to "active-root".

I'm aware that the "TimerEventTest" does almost the same thing, using an event listener, but the problem is that I need to invoke an alternative path of execution if something goes wrong during the execution of the java activity.

Consider the following process definition:
http://community.jboss.org/servlet/JiveServlet/showImage/1876/cancel-job.png
=================================
<?xml version="1.0" encoding="UTF-8"?>

<process name="cancel-job" xmlns="http://jbpm.org/4.3/jpdl">
    <start g="88,11,48,48" name="start1">
       <transition g="-69,-18" name="to wait state" to="wait state"/>
    </start>
    <state g="65,92,92,52" name="wait state">
       <transition g="-93,-18" name="to do something" to="do something">
           <timer duedate="20 minutes"/>
       </transition>
       <transition g="272,118:-114,-18" name="to another wait state" to="another wait state"/>
    </state>
    <java class="de.nilspreusker.DoSomething" g="58,218,105,52" method="doSomething" name="do something">
       <transition name="to end1" to="end1" g="-51,-14"/>
    </java>
    <state g="206,218,133,52" name="another wait state">
       <transition name="to end1" to="end1" g="14,-14"/>
    </state>
    <end name="end1" g="167,336,48,48"/>
</process>
=================================
... and test case:
=================================
package yourpackage;

import org.jbpm.api.ProcessInstance;
import org.jbpm.test.JbpmTestCase;

public class CancelTest extends JbpmTestCase {

    String deploymentId;

    protected void setUp() throws Exception {
         super.setUp();

        deploymentId = repositoryService.createDeployment()
             .addResourceFromClasspath("yourpackage/cancel-job.jpdl.xml")
             .deploy();
     }

    protected void tearDown() throws Exception {
         repositoryService.deleteDeploymentCascade(deploymentId);
         super.tearDown();
     }

    public void testJavaInstantiate() {
         ProcessInstance processInstance = executionService.startProcessInstanceByKey("cancel_job");
         String pid = processInstance.getId();

         assertTrue(processInstance.isActive("wait state"));
         assertTrue(processInstance.getState().equals(ProcessInstance.STATE_INACTIVE_SCOPE));

        // This throws: "org.jbpm.api.JbpmException: execution[cancel_job.7] is not active: inactive-scope"
        // executionService.signalExecutionById(processInstance.getId(), "another wait state");
     }
}
=================================
--------------------------------------------------------------

To reply to this message visit the message page: http://community.jboss.org/message/522289#522289




More information about the jboss-user mailing list