Yep that's pretty much it. Your listener gets callbacks from the session whenever
facts are inserted/updated/retracted or whenever rules activate. You can keep the audit
logic in the listener, and let the business rules do business rule stuff. And you can
pinpoint the rules or facts that you are really interested in.
When a rule activates, you can get at all sorts of information about it. Just run through
that class in a debugger to see what's available to you. If you grab that project,
there are a number of unit tests you can fire off, and set breakpoints in the listeners.
Unfortunately, when a rule doesn't activate, you don't get so much for free.
You can iterate through your knowledge base to see what rules exist.
You can subtract the rules which fired from those, to get a list of rules which did not
fire.
You can examine the facts which were in working memory at the time.
So if you know what your rule's constraints are, then you can pick the relevant facts
out and examine their values.
What's not so easy is automatically matching up the LHS of a rule with the facts that
might be relevant to it. I had a dig through it in the debugger, and unfortunately, as far
as I could tell, by examining a rule, the properties holding the facts that would be
matched on the LHS were all private. From what I understand, it might be possible to use
Drools Verifier to build up a model matching rules to the constraints they are interested
in, but I haven't had chance to have a good dig into that. If anybody knows the tools
better than me, I'd love to hear of thoughts on how this might be achieved.
Steve
On 31 Jan 2013, at 16:11, "Cotton, Ben" <Ben.Cotton(a)morganstanley.com>
wrote:
Ø Between those, you should be able to knock up something which does an appropriate audit
of what's going on in your rules without refactoring any of your DRL.
Ah. I think I get it.
Based on my understanding of the code you provided, the Listener’s objectInserted()
method gets a callback from the DROOLs runtime whenever a KS fact insert event is
processed. I could then use the ObjectInsertedEvent reference (passed by the callback) to
do my own accounting/auditing of the fact, including the ability to establish “did this
rule fail?” by providing the equivalent of the .DRL L-value logic in the objectInserted()
method’s implementation? If my understanding is correct, I could then get an *exactly*
precise answer to “why did this rule fail?” by iterating on the equivalent of each of the
.DRL L-value predicate participants and evaluating “did this specific predicate
participant fail to match?”. Very interesting. That would, indeed, effectively unburden
the .DRL from any audit/accounting logic – moving the burden to the Listener.
Is my understanding close to how you envisioned doing this?
Very interesting. Thanks again!
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf OfStephen Masters
Sent: Thursday, January 31, 2013 4:49 AM
To: Rules Users List
Subject: Re: [rules-users] Non short circuit ANDing
fyi - if you're just learning your way around working memory event listeners and the
like, here's some example code. It's an extended version of something I found in
the Drools docs.
A tracking working memory event listener:
https://github.com/gratiartis/sctrcd-fx-web/blob/master/src/main/java/uk/...
Attach it to your session to keep track of all facts as they are
inserted/updated/retracted. It also supports filtering for fact classes or handles so that
you can pick out which ones are relevant.
A tracking agenda event listener:
https://github.com/gratiartis/sctrcd-fx-web/blob/master/src/main/java/uk/...
Keeps track of and logs every rule which fires.
I use them in this test helper class, which enables me to create unit tests which assert
that specific rules have fired or that specific facts are in working memory.
https://github.com/gratiartis/sctrcd-fx-web/blob/master/src/main/java/uk/...
Between those, you should be able to knock up something which does an appropriate audit
of what's going on in your rules without refactoring any of your DRL. I prefer using
listeners like this to monitor what's going on, as they don't intrude on your
code. I tend to think that the rules should be simple and specific to the decision being
made, rather than needing them to be written in a specific way in order to achieve some
side effects.
Steve
On 31 Jan 2013, at 00:53, Davide Sottara <dsotty(a)gmail.com> wrote:
Gents,
this is a really interesting discussion and I wish I had more time to participate.. I
agree with Stephen that some constraints are really worthy monitoring,
while others are simply "filters".. Wolfgang's mention of "near
misses" is potentially a hot topic, I have been experimenting with
"imperfect" rules which
are more robust in that sense and provide better traceability, but that is not yet
implemented in the core engine.
I would also point out that one thing is monitor constraints for "logging" or
"auditing" purposes, another is the ability to specify different behaviours
(i.e. consequences) according to the success vs failure of an evaluation.
To this end, and following on the "extending" rule thread, it has actually been
planned and partially implemented.. it's only an experimental feature
(@Mario, any update/clarification?), so it's probably not well documented. But I
would point you to these links:
http://blog.athico.com/2012/09/conditional-branches-with-sub-blocks.html
https://community.jboss.org/wiki/BranchCEs
with the warning that it's still experimental and, while adopting
"familiar" keywords (if, then, else, switch), their semantics is different from
the
usual imperative language one, and in fact could enable some of the "extend"
capabilities that have been invoked in the last couple of posts.
Best
Davide
On 01/30/2013 02:25 PM, Cotton, Ben wrote:
automatically rename each rule "part" (being a single-condition rule derived
from the original) to some derivation of the original rule name, and need the consequence
only in the fully-extended rule, thereby giving the same effect, but with rule
"parts" that would reflect failure at the individual condition level
This is *exactly* the ambition we are hoping that some Drools .DRL enrichment tool (or
other Drools capability) can provide.
Wish I had sufficient competency to comment on the merits of your different suggested
approaches. Hopeful that the Drools gurus will comment explicitly on all these approaches
(and/or the approach suggested by another of using Working Memory listeners).
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views
contained herein are not intended to be, and do not constitute, advice within the meaning
of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you
have received this communication in error, please destroy all electronic and paper copies
and notify the sender immediately. Mistransmission is not intended to waive
confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted
under applicable law, to monitor electronic communications. This message is subject to
terms available at the following link:
http://www.morganstanley.com/disclaimers If you
cannot access these links, please notify us by reply message and we will send the contents
to you. By messaging with Morgan Stanley you consent to the foregoing.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users