1 2 Previous Next 21 Replies Latest reply on Nov 22, 2010 3:52 AM by LX T Go to original post
      • 15. Re: EventListener questions
        Santanu Saraswati Novice

        Hi Sebastian,
        Its a nice tricky point that you pointed out.

        I was trying to follow the behaviour after reading your post. The following things happen in sequence when transition happens from one activity to another

        1. End event fires for the source node
        2. Destination activity is set on the execution
        3. Start event is fired on the destination node
        4. execute method of destination activity behaviour is called

        For task node the TaskImpl is saved in db at the fourth step. But the start event is fired before that. And activity name is set before that. So it creates the trap you figured out.

        • 16. Re: EventListener questions
          Sebastian Schneider Master

          Hi Santanu,

          good to now that someone else took a deeper look at this and thanks for your valueable feedback.

          I don't know if the order of no. 3 and no. 4 has been chosen for some reason or not. To me it makes clearly sense for automated activities but causes the described problem for user activities.

          • 17. Re: EventListener questions
            Ronald van Kuijk Master
            Yep, I just had a look at the issue and I think it is invalid. There has not been a commit to the DB yet, so you cannot access data through the query api.
            • 18. Re: EventListener questions
              Sebastian Schneider Master

              Okay, speaking from a technical point of view Santanu Saraswati has done the investigation which shows the reason for this behaviour. And to me it seems this cannot be changed because of a common order of the described steps for automatic activities and user tasks. So technically it is kind of intented.


              But from my point of view this should work since there are no points speaking against using an EventListener in this way? I stumbled over this because I needed to provide the task's details to an external system. So would you say this is an improper use of EvenetListeners or Task Queries?

              • 19. Re: EventListener questions
                Ronald van Kuijk Master

                It's the combination that is invalid.. An eventlistener on THIS task AND querying for THIS task...


                Any other combination is perfectly valid. And task info can be accessed via the normal API I'd guess

                • 20. Re: EventListener questions
                  Jas Lam Newbie

                  I am experiencing this same exact problem where I can not get a handle on the task when my event listener is triggered.


                  So I dig into jBPM code that handles the <notification/> tag. See section for description of this tag

         e-mail support in tasks



                  <task assignee="ssoa" form="tasks/downloadData.htm" g="155,11,123,60" name="DownloadData">


                  This would trigger the org.jbpm.jpdl.internal.activity.MailListener class to send out an email to the assigned user


                  To find the current task, the MailListener notify method has the following code:


                      EnvironmentImpl environment = EnvironmentImpl.getCurrent();
                      DbSession dbSession = environment.get(DbSession.class);
                      TaskImpl task = dbSession.findTaskByExecution(execution);


                  When i stepped through the code in debug mode. the task variable is populated with the newly created task. I also noticed that no entry in the DB has been created for the task yet. Hence using query API won't return any task. It is looking great till this point.


                  THEN THE PROBLEM IS:


                  When i tried to insert the above Java code in implementing my listener.


                  TaskImpl task = dbSession.findTaskByExecution(execution);    //RETURN NULL!!!


                  It always returns NULL.

                  As I stepped through debug mode. I noticed my listener code is invoked first before the MailListener notify method. I watched the execution variable and they are the same when in MailListener and myListener. The execution variable already has an associating task. Not sure why dbSession.findTaskByExecution() kept returning NULL.


                  Thanks in advance for any help!

                  • 21. Re: EventListener questions
                    LX T Newbie

                    did you find a work around for your problem? I have a similar issue.

                    1 2 Previous Next