The behavior you described is how it is working in 5.3 (and it seems 5.2
too). The rule is fired once per process instance you have in your working
memory no matter if the others instances are, are not yet or even has
already been in that Rule Task Node. Again, I'm not sure if this is a
deliberated feature or a bug, but according to the documentation, it is a
bug.
One workaround could be that the process inserts a control fact containing
its own id right before the Task Node is ejecuted (this could be done in a
listener or in the on-entry action property of the node).
Your rule then will look like this:
rule "process complete"
ruleflow-group "Complete task group"
when
$ControlFact($id: processIntanceId)
$processInstance: WorkflowProcessInstance(instanceId == $id)
then
System.out.println("processInstance.id " +
$processInstance.getId());
retract ($id)
end
Best Regards,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Esteban Aliverti
- Developer @
2012/2/13 Alberto R. Galdo <argaldo(a)gmail.com>
We're using 5.2.0 final here.
What we are also observing is that whenever a process instance reaches a
businessruletask node the rule gets fired a number of times equal to the
number of instantiated processes even if any of those processes didn't
reach the bussinessruletask node.
Does this means that whenever a businessruletask is reached in any of the
current process instance, the rule gets fired for *all* the instances of
the process and subsequent businessruletask nodes won't fire anything?
2012/2/13 Esteban Aliverti <esteban.aliverti(a)gmail.com>
> I had some tests working fine in jbpm 5.1 but failing in 5.3 because of
> this same reason. I'm not sure if this is this is a regression bug or if
> there is a deliberated change in the behavior.
> Maybe someone in the jbpm dev team can shed some light here.
>
> Best Regards,
>
> XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>
> Esteban Aliverti
> - Developer @
http://www.plugtree.com
> - Blog @
http://ilesteban.wordpress.com
>
>
> 2012/2/13 Alberto R. Galdo <argaldo(a)gmail.com>
>
>>
>> According to the documentation:
>>
>> "Rule constraints do not have direct access to variables defined inside
>>> the process.
>>> It is however possible to refer to the current process instance inside
>>> a rule constraint,
>>> by adding the process instance to the Working Memory and matching for
>>> the process instance in your rule constraint.
>>> We have added special logic to make sure that a variable
>>> processInstance of type WorkflowProcessInstance
>>> will only match to the current process instance and not to other
>>> process instances in the Working Memory.
>>> Note that you are however responsible yourself to insert the process
>>> instance into the session and,
>>> possibly, to update it, for example, using Java code or an on-entry or
>>> on-exit or explicit action in your process.
>>> The following example of a rule constraint will search for a person
>>> with the same name as the value stored in the variable "name" of
the
>>> process:"
>>>
>>
>>
>> This however does not seem to be true.
>>
>> The first rule is to receive a stream of objects of type MyObject.
>> This rule starts an associated process.
>>
>> The second rule will be called by the process (from bpmn).
>>
>> Within the process there a task that invokes an an asynchronous service,
>> ie,
>> an implementation of WorkItemHandler that contains a Thread that will
>> set call
>> manager.completeWorkItem(workItemId,results);
>> when 30s have passed).
>>
>> With this setup we can observe what happens when 2 MyObject instances
>> come into the first rule separated by a short period of time (say 5
>> seconds).
>>
>> When the first object comes in a process is created and started (with
>> process id=1)
>> The process passes from the start node to the callMyTask node, which
>> invokes the slow WorkItemHandler references by MyTask
>> (which we have previously registered into session.getWorkItemManager()
>> ).
>> Because the WorkItemHandler has a thread that waits 30s before
>> completing the work item, it just sits there doing nothing (so far
>> everything is ok)
>> and allows the engine to process other events.
>>
>> 5 seconds later we insert another MyObject into the stream.
>> The first rule gets fired and created another process (with process
>> id=2).
>> The process passes from the start node to the callMyTask node, which
>> invoke our slow service.
>>
>> We have thus two processes running in parallel.
>>
>> When the first callMyTask node completes, the next node completeTask is
>> invoked.
>>
>> The rule "process complete" is matched as it belongs to the rule flow
>> group "Complete task group".
>>
>> At this point we observe that the rule is matched twice spitting out:
>>
>> processInstance.id 2
>> processInstance.id 1
>> .
>> So the rule has matched both process instances that are in working
>> memory and not just the one (with process id 1)
>> that called the "process complete" rule.
>>
>>
>>
>> The rule file
>> -------------
>>
>> rule "New case"
>> when
>> $myobject : MyObject(processed==false) from entry-point
>> "myobject stream"
>> then
>> ProcessInstance
>>
processInstance=kcontext.getKnowledgeRuntime().createProcessInstance("com.mycompany.process.MyProcess",
>> parameters);
>> insert(processInstance);
>>
>> kcontext.getKnowledgeRuntime().startProcessInstance(processInstance.getId());
>> modify ($myobject){
>> setProcessed(true)
>> }
>> end
>>
>> rule "process complete"
>> ruleflow-group "Complete task group"
>> no-loop true
>> when
>> $processInstance: WorkflowProcessInstance()
>> then
>> System.out.println("processInstance.id " +
>> $processInstance.getId());
>> end
>>
>>
>> The BPMN xml
>> ------------
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <definitions id="Definition"
>>
targetNamespace="http://www.jboss.org/drools"
>>
typeLanguage="http://www.java.com/javaTypes"
>>
expressionLanguage="http://www.mvel.org/2.0"
>>
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
>>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="
>>
http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
>>
xmlns:g="http://www.jboss.org/drools/flow/gpd"
>>
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
>>
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
>>
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
>>
xmlns:tns="http://www.jboss.org/drools">
>>
>> <process processType="Private" isExecutable="true"
>> id="com.mycompany.process.MyProcess" name="my process" >
>>
>> <!-- process variables -->
>>
>> <!-- nodes -->
>> <startEvent id="start" name="StartProcess" />
>>
>> <task id="callMyTask" name="call my task"
tns:taskName="MyTask" >
>> <ioSpecification>
>> </ioSpecification>
>> </task>
>>
>>
>> <businessRuleTask id="completeTask" name="Complete slow
task"
>> g:ruleFlowGroup="Complete task group" >
>> </businessRuleTask>
>>
>> <endEvent id="end" name="EndProcess" />
>>
>> <!-- connections -->
>> <sequenceFlow id="start-callMyTask"
sourceRef="start"
>> targetRef="callMyTask" />
>> <sequenceFlow id="callMyTask-completeTask"
>> sourceRef="callMyTask" targetRef="completeTask" />
>> <sequenceFlow id="completeTask-end"
sourceRef="completeTask"
>> targetRef="end" />
>> </process>
>> </definitions>
>>
>>
>> What's wrong with this? Isn't WorkflowProcessInstance() supposed to be
>> attached to the calling ProcessInstance? Is there another way of getting
>> the group of rules fire only for the processinstance that called it?
>>
>>
>> Greets,
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users