cancel
Showing results for 
Search instead for 
Did you mean: 

Events occuring before DB updates

bathe
Champ in-the-making
Champ in-the-making
Hi,

I am using a simple workflow with 2 tasks as shown in following image.

  [IMG]http://img182.imagevenue.com/loc438/th_565699128_A001CustomerRegistration_122_438lo.jpg[/IMG]
  
User Task has Start and end End task listener as shown:

   @Override
   public void notify(DelegateTask task) {
      System.out.println("Event Received : " + task.getEventName());
      List<String> approvers = new ArrayList<String>();
      
      Set<IdentityLink> identities =  task.getCandidates(); 
      for (IdentityLink identity :identities){
         approvers.add(identity.getUserId());
      }   
      
      List<Object> loggedinUsers = sessionRegistry.getAllPrincipals();
       for (Object loggedinUser : loggedinUsers) {
           if (loggedinUser instanceof MyUserDetails) {
              MyUserDetails myUser = (MyUserDetails) loggedinUser;
              if (approvers.contains(myUser.getUsername())) {
                 System.out.println("Send refresh to :" + myUser.getUsername());
                                     // Notification Logic…..
                 }
           }
       }
   }



User task is assigned to multiple users say M1, M2.  When workflow starts "start" event which is associated with first task is triggered. this will send "Refresh" notification to all associated actors of this task. after getting notification each actor will update task list by calling 


allTasks = taskService.createTaskQuery().taskCandidateUser(userId).list();


Problem statement:
    Step 1: When new workflow starts, START event is fired, captured by listener and refresh notification is send to all actors of task. Till this point everything is working as expected.  But when actors are updating task list, as Activiti engine has not added DB entries of new user task, taskCandidateUser.list() is not returning any results.

    Step 2: When user completes his task, END event is fired, captured by listener and refresh notification is send to all actors of task. Till this point everything is working as expected.  But when actors are updating task list, as Activiti engine has not removed DB entries for completed task, taskCandidateUser.list() is returning task added in step 1.

Please note if I manually refresh screen after step 1 or 2, task list displays updated contents.

Is there anyway to fire events only after complete DB update.

Regards,
Shirish
2 REPLIES 2

frederikherema1
Star Contributor
Star Contributor
You can hook in a TransactionSynchornisationAdapter (if you're using spring) to make sure your queued events (created in the listener) are flushed at this moment. if the transaction rolls back, you can ignore the events and not throw them. You'll have to dig quite deep to see where we add out synhronisation adapter.

Another option is to store the events you want to fire as a variable (or in your won DB) and have a async-service-task after the usertaks (eg. in the process managers approval, or another one) doing the "sending" of the notifications. Making it async makes sure the previous part of the process (usertask) is comitted successfully before the sending is executed.

Hi,

Thanks for really good solution.  As I am using Spring, I have implemented TransactionSynchornisationAdapter and it worked as expected.

Thanks again,