[rules-users] Drool 5 API and Agenda Listeners
SPAAARKY21
more.spam.pleeease at gmail.com
Mon Oct 12 09:06:33 EDT 2009
I'm basically writing a debugging tool that allows developers to step through
the rule engine itself. In a sense, I'm mimicking the way Jess' developers
rely on the (all-agenda) and (run 1) functions, but in a graphic way as
opposed to command line functions.
Inside of afterActivationFired(), I am displaying information like a current
view of the agenda, and then waiting for user input before returning control
to the rule engine. Tracking the activations myself is a good idea. I'm
just disappointed that the Drools' API no longer provides the methods needed
to inspect the focus stack and its activations. It used to. I suppose I
could always cast the Agenda I get to its concrete implementation but I
would rather not.
Anyway, thanks again for the help.
Pegram, Macon wrote:
>
> Using the listener, you could construct your own agenda stack to track
> what's going on. The AgendaEventListener interface has the methods:
> agendaGroupPopped(AgendaGroupPoppedEvent event)
> agendaGroupPushed(AgendaGroupPushedEvent event)
>
> In your listener, construct a java.util.Stack, and just Push/Pop
> agenda-group information that you retrieve from the AgendaGroupXXXEvent
> onto/off of your internal Stack. You can do similar tracking of event
> firing with the "before" or "after" ActivationFired event. Construct a
> list to capture the sequence of events.
>
> I'm not entirely clear on what you're trying to accomplish, but the
> event listener interface provides hook points for all the related events
> on the agenda, so you should be able to craft a listener to do whatever
> you need. I've used a similar mechanism in unit testing to validate
> correct processing of a set of agenda groups.
>
> Macon
>
> -----Original Message-----
> From: rules-users-bounces at lists.jboss.org
> [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of SPAAARKY21
> Sent: Sunday, October 11, 2009 7:34 PM
> To: rules-users at lists.jboss.org
> Subject: Re: [rules-users] Drool 5 API and Agenda Listeners
>
>
> Thanks for clearing that up for me.
>
> As for the agenda, I am writing an agenda listener already but the
> problem
> is getting the information I want. In Drools 5, an
> org.drools.event.rule.AgendaEventListener's afterActivationFired()
> method
> takes an org.drools.event.rule.AfterActivationFiredEvent object but
> where do
> I go from there? The getKnowledgeRuntime() method returns a
> KnowledgeRuntime, which has a getAgenda() method that returns an
> org.drools.runtime.rule.Agenda. But that Agenda doesn't have methods
> for
> getting all of the agenda groups on the focus stack. It only has
> methods to
> clear the agenda or get an activation/agenda/rule flow group by name.
> What
> I am looking for is a way to get all of the agenda groups on the focus
> stack
> (as a List or through an Iterator,) and then get each activation from
> each
> one of those groups.
>
> In Drools 4, I would have been using an org.drools.Agenda instead, which
> has
> a getAgendaGroups() method and AgendaGroup has a getActivations()
> method.
> In a Drools 5 org.drools.runtime.rule.AgendaGroup, there are only three
> methods - clear(), getName() and setFocus() - so even if I could get all
> of
> the AgendaGroups, it wouldn't do me any good. Do you see why I'm having
> trouble doing anything useful with the new API? In Drool 5, are you
> supposed to approach this in a different way (not in an agenda
> listener?)
>
>
> Pegram, Macon wrote:
>>
>> The primary reason to move to the "Knowledge APIs" apart from what
>> you've already mentioned is that they help to bring together the
> newest
>> features of Drools. In a single KnowledgeBase you can now have not
> only
>> rules, but Flows, and Complex Event Processing.
>>
>> As to tracking activity on the agenda... there's two ways...
>> 1. If you're using Eclipse, one great feature of the Drools plugin is
>> the Audit Log. You can start logging with the following code:
>> KnowledgeRuntimeLogger logger =
>> KnowledgeRuntimeLoggerFactory.newFileLogger(knowledgeSession,
> FILENAME);
>> Then open the resulting log in the Eclipse Drools Audit Log tab and
> get
>> a pretty good graphical representation of what happened during your
> run.
>> See the following URL for a screenshot:
>>
> http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-expert/h
>> tml_single/index.html#d0e6801
>>
>> 2. Create your own AgendaEventListener. Simply implement the
> interface
>> and place whatever actions you want on each event. Then attach it to
>> your session before you start processing like this:
>> knowledgeSession.addEventListener(new YourAgendaListener());
>>
>> Macon
>>
>> -----Original Message-----
>> From: rules-users-bounces at lists.jboss.org
>> [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of SPAAARKY21
>> Sent: Sunday, October 11, 2009 12:26 PM
>> To: rules-users at lists.jboss.org
>> Subject: [rules-users] Drool 5 API and Agenda Listeners
>>
>>
>> I recently moved from Drool 4 to 5 in a little example application I
> had
>> written. At first I hesitated because I thought the API had changed
>> drastically. When I did upgrade, I found that there were few changes.
>> However, I was still using all of the "Rule" classes instead of the
>> "Knowledge" classes - like RuleBase and StatefulRuleSession instead of
>> KnowledgeBase and StatefulKnowledgeBase. It sounds like the
> "Knowledge"
>> API
>> is the way of the future so to speak but I haven't been able to find
>> much
>> information on it. What is the advantage in using the new "Knowledge"
>> API?
>> Will the "Rule" API become deprecated at some point?
>>
>> Anyway, after switching to the Knowledge API, I have been working on
> an
>> agenda listener I had written. What I want to do is iterate through
>> agenda
>> groups on the focus stack and, for each group, iterate through the
>> activations in the order in which they are queued up. However, I
> don't
>> see
>> any way to do that. In fact, since switching to Drools 5 and the
>> "Knowledge" API, it looks like the API for dealing with the agenda and
>> activations and whatnot has become quite small. Or at least it is
> when
>> you
>> stick to the interfaces. Am I missing a better way of doing this?
>>
>> Brandon
>> --
>> View this message in context:
>>
> http://www.nabble.com/Drool-5-API-and-Agenda-Listeners-tp25844904p258449
>> 04.html
>> Sent from the drools - user 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
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Drool-5-API-and-Agenda-Listeners-tp25844904p258488
> 53.html
> Sent from the drools - user 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
>
>
--
View this message in context: http://www.nabble.com/Drool-5-API-and-Agenda-Listeners-tp25844904p25855520.html
Sent from the drools - user mailing list archive at Nabble.com.
More information about the rules-users
mailing list