-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The method onSucces() of the RuleListener is not executed on Rule that are registered in a CompositeRule #273
Comments
Please note that a rule should not be aware that there is a listener around it. It should not call the listener itself, it is the engine driving the process that calls the listener before/after each rule. However, when using a composite rule, the engine sees the composite rule as a regular rule (This is inherent to the composite design pattern according to which composite rules are implemented). The engine works against the Hope this helps. I'm closing this for now, but if you need more support, please do not hesitate to add a comment. |
Thank you for your response, I understand that the engine is the one which drives the process and should be the one to call the listener and I understand that a composite rule is seen as a regular rule. But should not it at least be aware that a regular rule can be decomposed into several rules ? The problem is that if I want to do some things before/after each rule, I will have to create other condition/action which will make the code less maintainable and readable. This why I wanted to use the listener. |
No, as far as the engine is concerned, that's an implementation detail. If the engine starts looking if a
RuleListener is not the right choice if you want to apply logic before/after the internal (composing) rules of a composite rule. You did not share what kind of logic you want to apply, but there should be a clean way of doing that without a rule listener. I'm thinking of extracting that code in a separate class (that you can unit test, etc) and (re)use it in a rule decorator. Using AOP is another option depending on your context (if you use Spring that should be fairly easy). Good luck! |
I have noticed that the method onSuccess() in the
RuleListener
is only executed on theRule
that are registered directly in theRules
object but not when registered in aCompositeRule
such asConditionalRuleGroup
.If I have this method in my RuleListener :
I get the following results in the following examples :
Example :
onSuccess(Rule rule, Facts facts)
is executedThe results :
rule1
rule2
Example:
onSuccess(Rule rule, Facts facts)
is not executedThe results :
conditionalRuleGroup2
I think it is because in the
ConditionalRuleGroup
, the methodexecute()
does not call the RuleListener's method.Is there a reason as to not call it like you do with the
DefaulRuleEngine
in theexecute()
method ?The text was updated successfully, but these errors were encountered: