Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-2570

KnowledgeAgent lacks a safe disposal method

    Details

      Description

      In the old RuleAgent api, there were a couple methods exposed that provided a safe disposal/cleanup mechanism:
      > ragent.stopPolling();
      > for (StatefulSession s : ragent.getRuleBase().getStatefulSessions())

      { s.dispose(); }

      In the new KnowledgeAgent api, there is only:
      > kagent.monitorResourceChangeEvents(false);

      This is problematic for a few reasons:
      1. Calling kagent.monitorResourceChangeEvents(false) will stop the thread that reads changesets from the queue and processes them, but the kagent will remain as a notifier listener. So the kagent will continue putting a changeset on its queue whenever the scanner detects a change, the result of this being a memory leak.
      2. Without a way to get at the KnowledgeBase and it's StatefulKnowledgeSessions, there is no way to cleanly dispose them.
      3. There is currently no way for the ResourceChangeScannerService to know that it should stop "watching" a resource, because it doesn't know when there are no more listeners registered with the ResourceChangeNotifierService. The result of this is unnecessary overhead.

      To solve #1 and #2 above, a dispose() method should be added to KnowledgeAgent that will:
      a. Remove itself as a notifier listener.
      b. THEN call monitorResourceChangeEvents(false) to stop it's internal thread.
      c. Clear it's internal queue.
      d. Iterate over any StatefulKnowledgeSessions associated with it's KnowledgeBase, and dispose() them.

      It could be argued that #3 above should be a separate Jira issue, but it is related to this topic, so it deserves mentioning.

      Notes:
      1. This issue is a dependency for JBoss.org ESB 4.9, which is a dependency for JBoss.com SOA-P 5.1. The dependent Jira issue is: JBESB-3360.
      2. This issue has been marked as Critical, although I would consider it a Blocker. However, I will leave that decision up to the Drools team.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  dward David Ward
                  Reporter:
                  dward David Ward
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: