I am a new Drools user working my way through the examples. To test my
understanding of how the rules work, I modified the
StateExampleUsingSalience.drl file used in the
StateExampleWithDynamicRules example. The result of my change
conflicted with my understanding of how the rules should work.
I made two modifications in the StateExampleUsingSalience.drl file. The
two modifications (shown below) are the commenting out of the two lines
in the RHS portion of the "B to D" rule. My understanding of how this
would affect the result was: because the "D" State object never changes
state to "State.FINISHED" the RHS portion of the "D to E" rule (shown
below) would not execute because the first pattern in the LHS would fail
to find a State object in working memory that met the criteria of the
constraint groups defined within it.
My question is: Why does the "D to E" rule in the
StateExampleDynamicRules.drl execute the statements in the RHS portion
of the rule?
From StateExampleUsingSalience.drl: My changes in this file are the
lines commented out in the RHS portion.
rule "B to D"
State(name == "B", state == State.FINISHED )
d : State(name == "D", state == State.NOTRUN )
//System.out.println(d.getName() + " finished" );
//d.setState( State.FINISHED );
From StateExampleDynamicRules.drl: This is the rule where I expected
the RHS portion to NOT get executed because there aren't any State
objects in working memory that have their name == "D" and its state ==
State.FINISHED because the setState( State.FINISHED ) was never executed
on the "D" state object.
rule "D to E"
State(name == "D", state == State.FINISHED )
e : State(name == "E", state == State.NOTRUN )
System.out.println(e.getName() + " finished" );
e.setState( State.FINISHED );
After my modifications, the output was:
I did not expect the "E finished" message to be printed.