Uploaded image for project: 'jBPM'
  1. jBPM
  2. JBPM-3578

LocalTaskService don't remove listeners

    XMLWordPrintable

Details

    Description

      Recently I've found that when using LocalTaskService, it doesn't remove the listeners that are created in:

        public void registerForEvent(EventKey key, boolean remove, EventResponseHandler responseHandler) {
          SimpleEventTransport transport =
              new SimpleEventTransport(taskServiceSession, responseHandler, remove);
          taskServiceSession.getService().getEventKeys().register(key, transport);
        }
      

      Notice that a client of this method can't remove it later, becouse the method return void.

      This method is called by SyncWSHumanTaskHandler.connect()

       private void registerTaskEvents() {
       TaskCompletedHandler eventResponseHandler = new TaskCompletedHandler();
              TaskEventKey key = new TaskEventKey(TaskCompletedEvent.class, -1);
              client.registerForEvent(key, false, eventResponseHandler);
              key = new TaskEventKey(TaskFailedEvent.class, -1);
              client.registerForEvent(key, false, eventResponseHandler);
              key = new TaskEventKey(TaskSkippedEvent.class, -1);
              client.registerForEvent(key, false, eventResponseHandler);
          }
      

      See that the listeners aren't save to remove later. If don't remove the listeners, they are invoked later.

      I fixed this with an update of LocalTaskService. When register the events, I save each listener to then dispose it.

        public void registerForEvent(EventKey key, boolean remove, EventResponseHandler responseHandler) {
          SimpleEventTransport transport =
              new SimpleEventTransport(taskServiceSession, responseHandler, remove);
          taskServiceSession.getService().getEventKeys().register(key, transport);
          //ADDED
          eventsRegistered.add(new KeyAndTransport(key, transport));
         //END ADDED
        }
      

      The class KeyAndTransport have two instances variables, the key and the transport. The instance variable eventsRegistered is a collection. Then, when is disconnected, I remove the listeners.

      public void disconnect() throws Exception {
          // do nothing
          // ADDED
          removeListeners();
         // END ADDED
        }
      
        private synchronized void removeListeners() {
          for (KeyAndTransport k : eventsRegistered) {
            taskServiceSession.getService().getEventKeys().unregister(k.getKey(), k.getTransport());
          }
          eventsRegistered.clear();
        }
      

      I've attached the complete file. I want to know if this is a bug or a misuse of this clasess. I have problems when use more than one session, with this change, work well with multiple sessions. Note that in my project I open and close session in each request, so when I close the session (and other resources) I can't remove the listener with the actual API.

      Attachments

        Activity

          People

            salaboy@gmail.com Mauricio Salatino (Inactive)
            gardellajuanpablo@gmail.com Juan Pablo Gardella (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: