For jBPM 5, How to access a fact in the working memory from WorkItemHandler

Solution Verified - Updated -

Environment

  • Red Hat JBoss BRMS
    • 5.3

Issue

  • How to access a fact in the working memory from WorkItemHandler
  • How to re-matching rules with a specific fact object from WorkItemHandler
  • How to access a ksession from WorkItemHandler

Resolution

  • How to access a fact in the working memory from WorkItemHandler
    To modify the facts which is inserted into the working memory by ksession.insert(), you can use the following API.
    ksession.getObject(FactHandle);
    ksession.getObjects();
    ksession.getObjects(ObjectFilter);

  • How to re-matching rules with a specific fact object from WorkItemHandler
    If you modify the fact object in the working memory and want to re-matching with rules again, please use a following API.
    ksession.update(FactHandle, Object);
    By invoking ksession.update(), agenda will be generated. So please call ksession.fireAllRule() if you need it. By using the following API, you can get an object for the first parameter, FactHandle, to call ksession.upate().
    ksession.getFactHandle(Object);
    ksession.getFactHandles();
    ksession.getFactHandles(ObjectFilter);
    Also ksession.insert() returns FactHandle object, then you can maintain the returned object in your application.

  • How to access a ksession from WorkItemHandler
    You need to provide a way to access ksession from WorkItemHandler. You may create a local variable in WorkItemHandler to keep a ksession object. In general, you can pass and store ksession object during execution for a WorkItemHandler's constructor.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments