Of course, you can also create your own event listener.
Something like this:

public class YourClass extends DefaultWorkingMemoryEventListener
{
  public void yourMethodForFiringRules()
  {
    // Load the rules file and set the event listener
    FileReader rulesFile = new FileReader("yourRulesFile.drl");
    RuleBase ruleBase = RuleBaseLoader.loadFromReader(rulesFile);
    WorkingMemory workingMemory = ruleBase.newWorkingMemory();
    workingMemory.addEventListener(this);

    // Assert objects
    workingMemory.assertObject(new YourObject());
    ...

    // Fire rules
    workingMemory.fireAllRules();
  }

  public void activationFired(ActivationFiredEvent firedEvent)
  {
    // Get the name of the fired rule
    String firedRuleName = firedEvent.getRule().getName();
    // See API for more methods on ActivationFiredEvent
  }
}

God bless,
Jaime

-----Mensaje original-----
De: Matthew Pawluk [mailto:[EMAIL PROTECTED] 
Enviado el: miércoles, 08 de febrero de 2006 23:16
Para: [email protected]
Asunto: Re: [drools-user] how to know which rule was fired?

Use the WorkingMemory addEventListener method....

snippet:

Rulebase rb = RuleBaseLoader.loadFromInputStream(rulesetStream);
WorkingMemory wm = rb.newWorkingMemory( ); wm.addEventListener(new 
DebugWorkingMemoryEventListener());


Geoffrey Wiseman wrote:
> I don't know of a detailed example on the site for this; there may be one.
> I've used it before, but I don't have a working example at hand that I 
> can easily supply, and a quick scan of Google doesn't show anything obvious.
>
> I do agree that this is probably what you want to look into though.
> Activation fired events will tell you when a rule has been executed, 
> and applying an listener to working memory is fairly painless.
>
> On 2/8/06, Peter Van Weert <[EMAIL PROTECTED]> wrote:
>   
>> I'm sorry, but I can't help you there. I have hardly any practical 
>> experience with Drools myself. Maybe someone else can help?
>>
>> Felipe Piccolini wrote:
>>
>> Peter,
>>
>>   Where can I get more info, doc or some examples for listeners and
>>   event handlers. I would like to see some code example for a simple
>>   rule execution, with fact assertions, application data and invoking
>>   the fireAllRules method.
>>
>>   Thanks.
>>
>> Wednesday, February 8, 2006, 5:39:25 PM, you wrote:
>>
>>    Maybe http://www.drools.org/Event+Model?nocache could be of use to 
>> you (in particular the ActivationFiredEvent-event)?
>>
>>     Joel G. Rivera-González wrote:
>>
>>  i have a over a meg of rules and we need to know whitch rule was fired...
>>
>> i know i can send a string with the rule name on the consequence, but 
>> i would like to know if drools provide something for this...
>> if not...i think it would be a great addition to drools to know the rule 
>> that was fired...
>>
>> thanks...
>>
>> -Joel
>>
>> Joel G. Rivera-González Wovenware, Inc [EMAIL PROTECTED] "The 
>> first 90% of a project takes 90% of the time, the last 10% takes the 
>> other 90% of the time" - Murphy's Law
>>
>>
>>
>>
>>
>>
>> --------------------------
>> Felipe Piccolini
>> [EMAIL PROTECTED]
>>
>>
>>
>>
>>     
>
>
> --
> Geoffrey Wiseman
>
>   

--
Matthew Pawluk
NeuLion Inc.
1600 Old Country Road
Suite 102
Plainview, NY 11803
516.249.6565
[EMAIL PROTECTED]


______________________
Este mensaje, y en su caso, cualquier fichero anexo al mismo,
 puede contener informacion clasificada por su emisor como confidencial
 en el marco de su Sistema de Gestion de Seguridad de la 
Informacion siendo para uso exclusivo del destinatario, quedando 
prohibida su divulgacion copia o distribucion a terceros sin la 
autorizacion expresa del remitente. Si Vd. ha recibido este mensaje 
 erroneamente, se ruega lo notifique al remitente y proceda a su borrado. 
Gracias por su colaboracion.
______________________
This message including any attachments may contain confidential 
information, according to our Information Security Management System,
 and intended solely for a specific individual to whom they are addressed.
 Any unauthorised copy, disclosure or distribution of this message
 is strictly forbidden. If you have received this transmission in error,
 please notify the sender immediately and delete it.
______________________

Reply via email to