[rules-users] Handle activationCancelled Event

Ingomar Otter iotter at mac.com
Fri Jul 25 09:15:57 EDT 2008


Why don't you use facts for control?
when mylamp=="on"
then
assert/update sth?

That looks easier to me.

--I
Am 25.07.2008 um 13:04 schrieb Claudio Rainoldi:

> Hi everyone,
> i'm developing a java application using drools 4 for domotic control;
> i ve implemented a listener on my working memory with the method
> afterActivationFired(...)
> and activationCancelled(...) .
> At startup of my app i've write the following lines:
>
> listener = *new* FiredRulesListener();
> workingMemory.addEventListener(listener);
>
> Each time a rule is fired the method afterActivationFired(...) is  
> called and
> it is ok; but when the rule stop to be true the method
> activationCancelled  isn't
> never called.
> I try to be more clear:
>
> i 've the following rule:
> when mylamp=="on"
> then
> System.out.println("light 1 on");
>
>
> When i turn on the light 1 the method afterActivationFired(...)  is  
> called,
> but when i turn off the light the method activationCancelled isn't  
> called.
> Can someboy help me??
> Thanks in advance.
>
>
> Cla
>
>
> My listener code:
>
> *
>
> public* *static* *class* FiredRulesListener  
> *extends*DefaultAgendaEventListener
>
> {
>
> List<Rule> firedRules = *new* ArrayList<Rule>();
>
> *
>
> public* List<Rule> getFiredRules()
>
> {
> *
>
> return* *this*.firedRules;
>
> }
>
> @Override
> *
>
> public* *void* afterActivationFired(AfterActivationFiredEvent event,
> WorkingMemory workingMemory)
>
> {
>
> Rule rule = event.getActivation().getRule();
> *
>
> if* (!*this*.firedRules.contains(rule))
>
> *this*.firedRules.add(rule);
>
> }
>
> @Override
> *
>
> public* *void* activationCancelled (ActivationCancelledEvent event,
> WorkingMemory workingMemory)
>
> {
>
> *System.out.println("i never see this message");*
>
> Rule *rule*= event.getActivation().getRule();
>
> *this*.firedRules.remove(rule);
>
> }
> _______________________________________________
> 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