> I have a rule which runs every 2 seconds using
> *timer( int: 0ms 2s )*
> When I either disable
> *rule.setEnabled( new EnabledBoolean( false ) );*
> or remove the rule
> *pkg.removeRule( rule );*
> the timer continues to fire every 2 seconds.
> This is with version 5.4.
> I haven't been able to find the API for cancelling or stopping a timer.
> anyone point me in the right direction?
The usual technique is to have a Fact as part of the rule's LHS and
retract this, so the LHS doesn't match any more.
I see that working as an alternative to enable/disable.
But what's the recommended approach for totally removing a rule that runs on a timer? After running pkg.removeRule( rule ) the rule seems to be deleted because pkg.getRules() comes back empty. Yet the rule with the timer continues to fire every 2 seconds.
An existing/active rule with a timer produces an activation if the
conditions are met. This activation is now part of the Rete and
continues to be so until the LHS turns to false; the repeating timer
merely retriggers the execution of the consequence. Killing the rule
itself merely prohibits new activations.
Its debatable whether removing the rule should also retract pending
activations. This is not defined/documented for rules without timer
(at least I'm not aware of any such documentation), but surely all
kinds of rules should be treated alike.