5 Replies Latest reply on Apr 28, 2012 2:20 AM by Sukumaran Raghavan

    How to complete custom Work Item Handler

    Miljenko Norsic Newbie

      Hi all,


      I have a question about custom work item handlers. I've seen a way to do it (chapter 13 on domain-specific processes in JBPM User Guide), but the samples are mostly simple, and include a TestWorkItemHandler that simply prints out work item information and then calls completeWorkItem() method on WorkItemManager object.


      On the other hand, if I have an access to a ksession, I can call


      ksession.getWorkItemManager().completeWorkItem(id, params);


      The requirements for my scenario include some custom work item handlers that are going to contain some external business logic, but can stay in an active state (it means that work item handler would not call completeWorkItem() and abortWorkItem()). And everything is persisted in a database and I cannot remember work item in the meantime because there is going to be a batch job that is going to process all pending processes.


      Is there a way to continue with the custom work handler at the place where it stopped? If so, how can I wake up that custom work item handler?

      I did not see a way to send a signal to a custom work item handler, is it possible?




        • 1. Re: How to complete custom Work Item Handler
          Miljenko Norsic Newbie

          Hi all,


          I might be a little unclear.

          I'm trying to create a custom work item handler that can react on external events. Nodes that are going to use that custom work item handler are going to be chained and need to respond to changes on a daily bases (eg. from a batch job).


          I'd like to have a work item handler with method executeWorkItem() that can be triggered multiple times from an external signal, for example.


          Is it possible to do in custom work item handler at all?




          • 2. Re: How to complete custom Work Item Handler
            Tihomir Surdilovic Master

            Hi Miljenko,

            in order to trigger it again, you would put an intermediate event before it. So if you signal that event, the service task will be called again.


            Hope this helps.

            1 of 1 people found this helpful
            • 3. Re: How to complete custom Work Item Handler
              Miljenko Norsic Newbie

              Hi Tihomir,


              thanks for the tip, but that's exactly I'm trying to avoid, because I'm going to have a lot of my custom "waiting work items" (e.g. wait 1 day, then do something, wait next 5 days, do something else, wait next 10 days etc), and for each of them I'll have a separate intermediate event to trigger it.


              Ideally, I'd like my custom work item handler to be able to respond to a signal event, giving me ultimate control over my custom work items and minimizing number of nodes. Does anybody know is there a way to "connect" custom work item with a intermediate signal, so that when I call signalEvent(), my custom work item handler's executeWorkItem() method is called?


              I'm still a newbie in BPMN, so please pardon if the question is stupid.




              • 4. Re: How to complete custom Work Item Handler
                Tihomir Surdilovic Master

                In general you cannot just signal any node directly. In some more advanced cases, like ad-hoc subprocess you can, however normally you have to model this as a signal event.

                • 5. Re: How to complete custom Work Item Handler
                  Sukumaran Raghavan Newbie



                  I had a similar scenario. I took the following approach.


                  - I created my own DB table for my CustomWorkItemHandler. i maintained the Session ID, Process Instance ID, WorkItem ID, and state (as needed by you). Everytime the workitemhandler is executed, it will update the DB table . Note that it DOES not complete or abort the work item.

                  - In my case i had an external event to complete the work item. Upon receipt of the event, i loaded the persisted ksession, then performed a completeWorkitem for the specific work item ID. I got the work item ID as part of the external event.


                  This is basically how the Human task works. I had picked the idea from there. HumanTask however is much more complex; while this is a much more simple case.