-
1. Re: How to stop a process instance and all its task instance
icyjamie Sep 21, 2005 7:29 AM (in response to sscortan)Their is also a "cancel" on the taskInstance. All queries fetching taskInstances take into account "isCancelled=false". I don't know if this could be of any use also.
You're kind of breaking the business rule if you do a setEnd, because the task is not ended, it is halted or cancelled.
As for web application stuff: this is the same problem as any (web) application stuff: what you see can already be dirty, backend-wise. Best is to check the state in one transaction, locking it and committing it. You should decide whether race conditions are acceptable or not.
Have a look at tests Wfp20CancelActivityTest and Wfp21CancelCaseTest to see how cancellation is handled. I think process.end() recursively calls the ending of the child.
Maybe there will be native support for "cancel" or "suspend" in next release(s). -
2. Re: How to stop a process instance and all its task instance
sscortan Sep 21, 2005 9:05 AM (in response to sscortan)Hello,
Thanks for you reply.
I didn't use taskInstance.cancel() method for the unfinished tasks because it is calling end() method too, which marks those tasks as done, and that is not true, also. Those tasks should be cancelled and made "invisible" for the other actors.
I avoided to use taskInstance.end(), which continues the token's execution.
Because after this cancellation of the process all the tasks, tokens and the process instance must be ended, I preferred to set an end date for the task instance (token.end() and processInstance.end() made that for the other elements)
Wfp21CancelCaseTest test class gives good ideas, but only at process instance's and token's level, not at task instance's level.
The following code worked well for me:Collection listTasks = processInstance.getTaskMgmtInstance().getTaskInstances(); if (listTasks.size()>0) { for (Iterator iter = listTasks.iterator(); iter.hasNext(); ) { TaskInstance ti = (TaskInstance) iter.next(); if (!ti.hasEnded()) { ti.setEnd(new java.util.Date()); log.debug("task instance " + ti.getName() + " has ended"); Token tk = ti.getToken(); tk.end(); log.debug("token " + tk.getName() + " has ended"); } } } if (!processInstance.hasEnded()) { processInstance.end(); log.debug("process instance " + processInstance.getId() + " has ended"); }
But any better idea is welcome, too.
Sorin -
3. Re: How to stop a process instance and all its task instance
brittm Sep 22, 2005 2:53 PM (in response to sscortan)Yes, calling process.end() does also end it's Tokens, BUT...this doesn't automatically cancel open tasks (maybe it shouldn't anyway--once a task has started, you may want it completed--just depends) so that Tasks continue to show up in Actor's queues; you will have to cancel the Tasks explicitly.
This could possibly be managed by an attribute added to the task in the process definition: cancel=implicit | explicit. This would tell JBPM that a particular task should be implicitly cancelled when it's parent is ended, or require explicit cancellation by the user or system (for tasks that should typically be expected to finish once they've been started).
-Britt -
4. Re: How to stop a process instance and all its task instance
mondenkind Nov 15, 2006 10:34 AM (in response to sscortan)sscortan's answer helped me a lot and verified what i already guessed. ending a processinstance and its taskinstances like that works fine. although i have a problem:
if i manually set an end date with setEnd(Date), the state of the taskinstance is left untouched, which means it is still declared as open/signalling. so it never vanishes from my "open tasks" list, which is bad!
what can i do to set it to ended without using the end() function or having proper functions to set the boolian of isOpen/isSignalling to false?!
i can only think of manipulating the database directly with sql/hql, but that would be really dirty!
thanks for your help!!