[jBPM 4.3] Cancel Job/Timer
nilspreusker Jan 26, 2010 7:50 AMHi,
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 of 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 "TimerEventTest" in the examples does almost the same things, but it uses an event listener with a timeout. In this case, I can't use a timeout, because the alternative path of execution is also supposed to work if the timer already fired and something went wrong.
Consider the following process definition:
=================================
<?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");
}
}
=================================