activiti - How to modify variables in an atomic way using REST API -


consider process instance variable has value. update value, instance increment one, using rest api of activiti / camunda. how this?

the problem rest api has services setting variable values , them. incorporating such api lead race condition.

also consider example regarding integers while variable complex json object or array!

this answer camunda 7.3.0:

there no out-of-the-box solution. can following:

  1. extend rest api custom resource implements endpoint variable modification. since camunda rest api uses jax-rs, possible add camunda rest resources custom jax-rs application. see [1] details.
  2. in custom resource endpoint, implement read-modify-write cycle in 1 transaction using custom command:

    protected void readmodifywritevariable(commandexecutor commandexecutor, final string processinstanceid,       final string variablename, final int valuetoadd) {    try {     commandexecutor.execute(new command<void>() {       public void execute(commandcontext commandcontext) {         integer mycounter = (integer) runtimeservice().getvariable(processinstanceid, variablename);          // variable         mycounter += valuetoadd;          // update provokes optimisticlockingexception when command ends, if variable updated meanwhile         runtimeservice().setvariable(processinstanceid, variablename, mycounter);          return null;       }     });   } catch (optimisticlockingexception e) {     // try again     readmodifywritevariable(commandexecutor, processinstanceid, variablename, valuetoadd);   } } 

see [2] detailed discussion.

[1] http://docs.camunda.org/manual/7.3/api-references/rest/#overview-embedding-the-api
[2] https://groups.google.com/d/msg/camunda-bpm-users/3stl8s9o2ai/dcx6ktknbgaj


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -