<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi All,<br>
<br>
I have a bunch of rules that evaluate using some constant variable
(say "slackTicks"). Currently, in my rules, I write down the value
of this "slack" each and every time I use it, for example:<br>
<br>
<code>TransferSchedule( tick > currentTick - 10d )</code><br>
<br>
where 10 is the slack.<br>
<br>
A solution would be to insert constant facts:<br>
<br>
<code>Constant( key = "slack", $slackTicks : value )</code><code><br>
</code><code>TransferSchedule( tick > currentTick - $slackTicks )</code><br>
<br>
Or inject a global properties object:<br>
<br>
<code>global Properties constants</code><code><br>
</code><code><br>
</code><code>$slackTicks :
Double.valueOf(constants.getPropertyValue("model.slack", "0"))</code><br>
<br>
Or, the last one I can think of: a public final static on the fact
class:<br>
<br>
<code>TransferSchedule( tick > currentTick -
TransferSchedule.SLACK_TICKS )</code><code><br>
</code><br>
These all cross the boundary between Java and Drools. In my Java
code I have to insert the Constant facts or inject the global. When
my drools developers think of some new ways to create the rules, I
run the risk of having to go in and modify the .properties file or,
worse, change the Java code.<br>
<br>
To be able to define a "constant" would be a clean solution:<br>
<br>
<code>declare</code><code> constant double SLACK_TICKS = 10</code><code>;<br>
</code><code>
</code><code><br>
...<br>
</code><code>
TransferSchedule( tick > currentTick - SLACK_TICKS )</code><code><br>
...<br>
</code><br>
This separates the rules from the Java code and give the rules
developer all freedom to do whatever they want to make constant.<br>
<br>
Ah, just thought of another way to do it. You can insert the facts
from within Drools itself:<br>
<br>
<code>declare Constant</code><code><br>
</code><code> key : String</code><code><br>
</code><code> value : Object</code><code><br>
</code><code>end</code><code><br>
</code><code><br>
</code><code>rule initialize</code><code><br>
</code><code> salience 100000</code><code><br>
</code><code> when</code><code><br>
</code><code> // always</code><code><br>
</code><code> then</code><code><br>
</code><code> insert( new Constant( "slack", 10d ) );</code><code><br>
</code><code> //... other constants go here</code><code><br>
</code><code>end</code><code><br>
</code><br>
I will still have to "capture" the constants that I need in every
rule with a Constants( key == "...", $c : value ) premise, though...
And you would need to add some more Constant classes to cater to
contain type safety...<br>
<br>
What's your thought? What strategy do you use?<br>
<br>
Regards,<br>
Willem<br>
</body>
</html>