[rules-users] How to query rules to create reports to analyze usage

Wolfgang Laun wolfgang.laun at gmail.com
Wed Apr 25 12:43:58 EDT 2012


On 25/04/2012, thomashatz at yahoo.com <thomashatz at yahoo.com> wrote:
> Thanks Wolfgang,
>
> But don't the rules tables have basic info like 'last run date and time and
> user' type info...

I'm not aware of any such information being collected and stored
automatically. But if this is a Guvnor function, I may have a very
blind spot there.

>
> Also how to setup an AgendaEventListener

It's done as with any other listener in JDK etc. Here are some code
snippets to get you started. This code is not necessarily "best
practice" or anything; it's meant to illustrate the essentials. The
constructor installs the listener.

public class AgendaWatcher implements AgendaEventListener {

    // useful aux. method
    private String ruleNameOfEvent( ActivationEvent actEvent ){
        Activation activation = actEvent.getActivation();
        Rule rule = activation.getRule();
        return rule.getPackageName() + '.' + rule.getName();
    }

    public AgendaWatcher( KnowledgeRuntime knowledgeRuntime ){
        knowledgeRuntime.addEventListener( (AgendaEventListener)this );
    }

    @Override
    public void activationCancelled(ActivationCancelledEvent actEvent) {
         // happens frequently, for various reasons. may not be of interest.
    }

    @Override
    public void activationCreated(ActivationCreatedEvent actEvent) {
        // same thing.
    }

    @Override
    public void beforeActivationFired(BeforeActivationFiredEvent arg0) {
    }

    @Override
    public void afterActivationFired(AfterActivationFiredEvent actEvent) {
        // count firings
        Counts counts = getCountsForName( ruleNameOfEvent( actEvent ) );
        counts.firings++;
    }

    @Override
    public void agendaGroupPopped(AgendaGroupPoppedEvent arg0) {
    }
    @Override
    public void agendaGroupPushed(AgendaGroupPushedEvent arg0) {
    }
}




>
> Really appreciate your knowledge sharing
>
> --- On Tue, 4/24/12, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:
>
>> From: Wolfgang Laun <wolfgang.laun at gmail.com>
>> Subject: Re: [rules-users] How to query rules to create reports to analyze
>> usage
>> To: "Rules Users List" <rules-users at lists.jboss.org>
>> Date: Tuesday, April 24, 2012, 4:30 AM
>> For analyzing "rules usage" an
>> AgendaEventListener should be used to
>> register the information you are interested in. (You
>> wouldn't need to
>> query the rules DB for this anyway.)
>>
>> -W
>>
>> On 24/04/2012, thatz <thomashatz at yahoo.com>
>> wrote:
>> > Am new user to Drools, have 300+ rules, but need to
>> query them using SQL
>> > syntax to create reports and analyze rules usage (if
>> rules are being called,
>> > etc.).  App developer said cannot query the rules
>> db directly because it is
>> > proprietary.  Is there anyway to query rules or
>> what is best way to analyze
>> > rules usage.  Thanks
>> >
>> > --
>> > View this message in context:
>> > http://drools.46999.n3.nabble.com/How-to-query-rules-to-create-reports-to-analyze-usage-tp3934833p3934833.html
>> > Sent from the Drools: User forum mailing list archive
>> at Nabble.com.
>> > _______________________________________________
>> > rules-users mailing list
>> > rules-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/rules-users
>> >
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list