[jBPM Users] - Re: workflow design about wait states
by mmusaji
Perhaps I'm missing something... This is an example of how my application will start of the workflow. My comments in the code explain what I need to happen. I'm using the same process definition previously posted.
I need the workflow to start and then this method to wait until a signal is recieved from the workflow before reading the variable back out the executionService.
| @WebMethod
| public String request() {
| try {
| InitialContext ctx = new InitialContext();
| this.processEngine = (ProcessEngine)ctx.lookup("java:/ProcessEngine");
|
| ExecutionService execService = (ExecutionService)
| this.processEngine.get(ExecutionService.class);
|
| //kicks off workflow (1)
| ProcessInstance processInstance = execService.startProcessInstanceByKey("process", variables);
|
| //between above the line and this line, we need a wait of some sort but depending on how long
| //the workflow takes to complete...
|
| //should not be read until the workflow is complete
| myObject = (MyObject)execService.getVariable(processInstance.getId(), "myObjectDetails");
|
|
| result = "My Object Details: " + myObject.getDetails();
|
| } catch (Exception e) {
| e.printStackTrace();
| }
|
| return result;
| }
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4255466#4255466
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4255466
16 years, 6 months
[jBPM Users] - Re: workflow design about wait states
by kukeltje
1: Correct
2: No, not necessarily. Yes, with manually firing the jobs and doing nothing in addtion you are right. But... You could always do one of two things if you really think it is important (keep in mind that a fork is 'parallel on the BUSINESS level', not by definition multi-threaded (although sometimes they are processed that way)
- Start a new threads where you manually fire the jobs
- Switch back to the jobExecutor in these case (preferred) with multiple threads (5 is the default afaik)
But as you can read from Jorams post (and what I forgot to explain to you) is that in addition to this you have to make sure the unittest thread is not ended before both jobs are finished and the join is reached. This can be done by one long Thread.sleep(..), or by having a loop which tests if the execution is in a specific state or if it is ended and if not, sleep a short time and test again.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4255462#4255462
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4255462
16 years, 6 months
[jBPM Users] - Exeception Handeling problem in JBPM
by prajatna
Hi All,
In my JBPM approval process, I have a requirement that, if at any point of time JBPM exception happens during the process work flow., the control should delegate to a separate TaskNode called Admin node, and the normal process flow should stop. Inside Admin node the admin user decides , from which task node now the process should continue, and accordingly the flow continues
Taking into consideration this requirement I designed a admin node and a exception handler as follows..
| <task-node name="Moduladministrator">
| <task name="AdministratorInteraction" description="Moduladministrator-Interaction">
| <assignment class="com.sample.action.AssignAdminAction"></assignment>
| </task>
| </task-node>
| <exception-handler>
| <action name="TravelExceptionHandler" class="com.sample.action.TravelExecptionHandler" ></action>
| </exception-handler>
|
|
The Exception action handler is ass follows , which transfer the flow to Admin node and creates the Taskinstance at Admin node
| public class TravelExecptionHandler implements ActionHandler {
|
| private static Log log = LogFactory.getLog(TravelExecptionHandler.class);
| private static final long serialVersionUID = 1L;
|
| public void execute(ExecutionContext executionContext) throws Exception {
|
| log.debug("#################### ERROR HANDELING ##################");
| log.debug("========================================================");
| log.debug("#################### ERROR HANDELING ##################");
| try {
|
|
| log.debug("Error comes from --" + executionContext.getNode().getName());
| log.debug("Error is -- -- --" + executionContext.getException().getMessage());
|
| Node targetNode = executionContext.getProcessDefinition().findNode("Moduladministrator");
| log.debug("Admin node is--" + targetNode.getName());
|
| TaskInstance faultyTaskInstance = executionContext.getTaskInstance();
|
| if (faultyTaskInstance != null) {
| faultyTaskInstance.setEnd(new Date());
| }
| TaskNode targetTaskNode = (TaskNode) targetNode;
| targetTaskNode.enter(executionContext);
| TaskMgmtInstance taskManagementInstance = executionContext.getTaskMgmtInstance();
|
| taskManagementInstance.getTaskMgmtDefinition().setStartTask((Task) targetTaskNode.getTasks().iterator().next());
|
| log.info("Now Controll is with " + targetTaskNode.getName() + " node");
|
|
| } catch (Exception e) {
| log.debug("Error---" + e.getCause());
| e.printStackTrace();
| }
|
| }
| }
|
This above code part is working find with creating the taskinstance at admin task node.
Now after the task is assigned to a admin user, the admin take decision from which task node the process should start, again.
The code i am using to delegate the flow from admin node to any desired task node is--
| String faultNode = (String) contextInstance.getVariable("ErrorOriginatingNode");
| Node faultyNode = processInstance.getProcessDefinition().findNode(faultNode);
| Collection col = processInstance.getTaskMgmtInstance().getTaskInstances();
| int cnt = 0;
| ArrayList arrayLst = new ArrayList(col);
| log.debug("Total task is- " + arrayLst.size());
|
| for (int i = 0; i < arrayLst.size(); i++) {
| TaskInstance taskInstance = (TaskInstance) arrayLst.get(i);
| log.debug("-----TaskName = " + taskInstance.getName() + "----TaskId = " + taskInstance.getId()
| + "----Is task active-- " + !taskInstance.hasEnded());
| if (!taskInstance.getName().equalsIgnoreCase("AdministratorInteraction") && !taskInstance.hasEnded()) {
|
| log.debug("-----Task = " + taskInstance.getName() + " is ending ");
| taskInstance.setEnd(new Date());
| cnt++;
| }
| }
| log.debug("Total "+cnt+"tasks got ended");
| List nodes = processInstance.getProcessDefinition().getNodes();
| for (int i = 0; i < nodes.size(); i++) {
| Node tempNode = (Node) nodes.get(i);
| if(tempNode instanceof TaskNode)
| log.debug("TaskNode " + i + "---" + tempNode.getName());
| }
| log.info("Error Occurred in work flow.Entering Admin Node -- -- --");
| log.info("*********Please provide any of the above Node you want to proceed with**************");
|
| String node = conInput.getConsoleInput();
| log.debug("Selected for TaskNode--" + node);
| TaskNode targetNode = (TaskNode)processInstance.getProcessDefinition().findNode(node);
| Transition errorTransition = new Transition("to" + targetNode.getName());
|
| targetNode.addArrivingTransition(errorTransition);
| faultyNode.addLeavingTransition(errorTransition);
|
| errorTransition.setTo(targetNode);
| TaskMgmtInstance taskManagementInstance = processInstance.getTaskMgmtInstance();
| taskManagementInstance.getTaskMgmtDefinition().setStartTask((Task) targetNode.getTasks().iterator().next());
|
| adminTaskInstance.end(errorTransition);
|
|
Unfortunately, I am not able to achieve my requirement. The problem I am facing is even the control is delegating to admin node, still the process continues to move forward with the selected transition from the node where exception occurs..
So basically , I am not able to stop and resume the work flow from a desired Tasknode, as a admin.
Please suggest how to achieve this ..
As per the JBPM document 10.7. Exception handling
anonymous wrote :
| Note that the exception handling mechanism of jBPM is not completely similar to the java exception handling. In
| java, a caught exception can have an influence on the control flow. In the case of jBPM, control flow cannot be
| changed by the jBPM exception handling mechanism.
So then , how to achieve my requirement ..Any work around is there?
Please suggest..
Thanks in advance for your valuable reply..
Prajatna Mahunta
prajatna.mahunta(a)daimler.com
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4255458#4255458
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4255458
16 years, 6 months