cancel
Showing results for 
Search instead for 
Did you mean: 

Sending BPMN signal upon variable update

franck102
Champ in-the-making
Champ in-the-making
Hi all,

We are trying to have implement a backend extension that will send out a BPMN signal (i.e. notify subscribers) whenever a given process variable is modified.

The issue we are running into is that, the way we understand it, using an Activiti listener to fire the signal asynchronously means that subscribers may start executing before the new variable value has been committed to the database.

The signal processing could take a while and we don't want failures to interfere with the triggering setVariable, so we send the signal asynchronously. This means that in theory a subscriber could pick up the signal in a different thread, before the triggering setVariable transaction has committed, and read a stale value from the DB.

We have tried using a post commit transaction listener, but we then run into ConcurrentModificationExceptions since runtimeService.signalEventReceivedAsync ends up trying to add a new transaction listener.

In short, is there a reliable pattern to asynchronously signal subscribers about a variable change, while making sure that said subscriber will get the committed updated value when it tries to read it?

Thanks!
Franck
6 REPLIES 6

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Franck.

I have 2 ideas:
    [#] reimplement variable store in DbSqlSession.
    [#] implement your own variable handling outside of activiti variables.
Regards
Martin

franck102
Champ in-the-making
Champ in-the-making
Ouch, both options sound pretty scary.

Isn't there a way to programmatically create the equivalent of a BPMN continuation, something that isn't a TransactionListener but that would execute after the variable is committed, and would throw the signal? Maybe scheduling a job with the job manager?

Franck

trademak
Star Contributor
Star Contributor
Hi Franck,

Event listeners could be used for this. If you register an event listener on a variable create/update you get a trigger every time a variable is updated or created. There's an option to store al events in the Activiti database table ACT_EVT_LOG and you could create a thread that reads new rows from this event log table. When its written to this table you are sure that the transaction has been committed successfully.

Best regards,

Hi,
I think it does not solve
The issue we are running into is that, the way we understand it, using an Activiti listener to fire the signal asynchronously means that subscribers may start executing before the new variable value has been committed to the database.

Regards
Martin

Indeed… the issue is still pending for us pm 5.15.1, if there is anything in the latest releases that would help with this I would love any pointers you can give.

Thanks!
Franck

jwestra
Champ in-the-making
Champ in-the-making
Franck,

If you are using Spring, you can implement a org.springframework.transaction.support.TransactionSynchronization listener that will be notified when a transaction is committed (e.g. it's afterCommit() method).

1. Store your modified variables in a resource holder attached to the Spring Transaction.  If using Spring, Activiti DB commands will be using a Spring Transaction, so you are good to go.

2. In your implementation's 'afterCommit()' method, take the variable(s) and/or signal and fire them off IN A SEPARATE THREAD.  The current thread just had a txn on it and it won't like you doing more work on it.  So, spin off a separate thread for this signal.

Jason