cancel
Showing results for 
Search instead for 
Did you mean: 

How to consume a token programmatically

gualberto
Champ in-the-making
Champ in-the-making
Hi,

We have some processes with user activities that can run back to past activities, thus creating something like a loop (A->B->A).
The B->A flow originates on an B´s non-terminating boundary event, so when 'A' flows to 'B' (again) we end with 2 tokens on B.

I'd like to know if there is some way of consume programmatically these tokens, because the end user do not need to deal with this "clone".

Regards
3 REPLIES 3

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,
You can implement your own behavior and consume token there.
e.g.

  /**
   * Default way of leaving a BPMN 2.0 activity: evaluate the conditions on the
   * outgoing sequence flow and take those that evaluate to true.
   */
  protected void leave(ActivityExecution execution) {
    bpmnActivityBehavior.performDefaultOutgoingBehavior(execution);
  }

You should change this default behavior.

I would prefer to describe this functionality  in the process diagram. - More readable and not so complicated.

Regards
Martin

hendrix
Champ in-the-making
Champ in-the-making
Hi Martin,

I was trying to obtain that behavior using your suggestion (changing the element's behavior), then I got through
org/activiti/engine/impl/bpmn/behavior/BoundaryEventActivityBehavior.java
Hoping that I would be able to kill the token "left behind" the boundary event upon the event's execution.
Surprisingly I found that exists a boolean variable (named interrupting) that does exactly what I wanted inside the BoundaryEventActivityBehavior's execute method.
However, debugging the engine I found out that no matter what value i set on the boundary event's "cancelActivity" property , that variable is never set to true. (I forced that value hard-coding it and the behavior was what I expected).

Then I started searching where is the source of that value (false) on that variable (interrupting) and found out that it comes from org\activiti\editor\language\json\converter\BoundaryEventJsonConverter.java (line 91), where the BPMN model is being parsed.

The code is copied below ( I was testing with a timer boundary event at first ) :

<java>

boundaryEvent.setCancelActivity(getPropertyValueAsBoolean(PROPERTY_CANCEL_ACTIVITY, elementNode));

</java>

Clearly the value is being set based on the property PROPERTY_CANCEL_ACTIVITY="cancelActivity" of that elementNode variable.
The thing I found very strange is that no matter which value I set on the timer boundary event at the bpmn20.xml file, it never is present on that elementNode, which seems to be a json representation of the boundary element, right from the jackson's output (all other attributes from the XML file seems to be present). That way, the getPropertyValueAsBoolean call always resolves to false (its default for not found properties), letting the boundary event interrupted variable never be "true", thus, never working as I expect.

Is that some kind of flaw on the parsing process? why there is that "cancelActivity" option on the timer boundary event since it (seems that) is never used?

thanks in advance,

Fellipe.

jbarrez
Star Contributor
Star Contributor
It does sound like something is rather wrong in the modeling here.
If the loop A->B->A causes two B's then it is modeled wrong. So instead of trying to hack around it, a better question would be what the use case is and how to model it.