Thursday, October 28, 2010

Basic Drools example!

what is wrong with this ??

rule "Apply 10% discount if total purcahses is over 100"           
    no-loop true   
    dialect "java"
        $c : Customer()
        $i : Double(doubleValue  > 100) from accumulate ( Purchase( customer == $c, $price : product.price ),
                                                                    sum( $price ) )
          $c.setDiscount( 10 );
        insertLogical( new Discount($c, 10) );   
        System.out.println( "Customer " + $c.getName() + " now has a shopping total of " + $i );

Hi All,

We see a part of .drl file above :) I have found it in the Drools 5.1 examples.I tried to understand it's world. I can not define exactly but i think there is something dirty around here.

I write java. I want to write java. I know java (I guess:))...

But what is the no-loop & accumulate & sum & insertLogical & assigments in text & calling java methods from a text file ?

Why i have have learn some other literals ? If I am expected & free to write Java in there (meaning lovely .drl file) why & what the other things are ?

Come on guys. I am someone who really curious for new technologies. I am not resisting to learn those.

Only those make me scared . Calling my methods  from a text file ??? i was expecting to see only execution paths (in some other clean waylike when->what). Maybe I could implement some interfaces i could return some preDefined RETURN_TYPEs also. Even I could write simple Java Statements in an XML file. Those are all accepted by me.

But,,, Calling java methods from text context, doing assignments in there .Learning its nature .....I felt myself like developing PLSQL . I don't want implement a business logic inside a text file. I don't know why ...Just my comments.

PS: I could validate a xml file or Java file in my IDE (which is not eclipse). I don't want to be mad bec.of a typo or some extra comma while dealing with a weird text file in the future.


I will be searching for another fwk ....


A few days later....

A small update :

1) Download JSR94 jar :Java Rule Engine Specification
2) Download JRuleEngine from :
3) Create a project with these 2 jars. Compile and run ..

See sample rule.xml :

I liked it very much...Sweet huh ?

Nevertheless I have a question mark for JRuleEngine too. As a commentator :D

In its web page there is a link: To do:

It says :
- Rules graphical editor: a JSP web application to define rules that will be saved on XML file.


JSP's and web applications is a good but i think it is not the right choice.
Application Management and Monitoring must be done via MBeans. JConsole a is good tool.

InputStream inStream = new FileInputStream( "/home/sunels/JRuleEngine1.3/examples/example1.xml" );
RuleExecutionSet res1 = ruleAdministrator.getLocalRuleExecutionSetProvider(null).createRuleExecutionSet( inStream, null );

Maybe rules can be served as a mbean while creating the RuleExecutionSet...

No comments:

Post a Comment