[rules-users] Mixing Drools language and Java implementions without performance loss

Oliver Libutzki oliver at libutzki.de
Thu Nov 29 14:17:54 EST 2012


Hello everyone,

as I try to find the best solution for a scheduling problem Drools
Planner seems to be the perfect fit.

Instead of using drl files I want to implement the rules in Java, but I
still would like to use the power of Drools (Planner) to find the best
solution as fast as possible.

My first attempt is to use the Description API (Examples:
https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/java/org/drools/lang/api/DescrBuilderTest.java).
This might work, but I wonder if I really have to write the whole rule
this way. Of course I can use "eval" Expressions to integrate Java code,
but I would like to know how expensive this is in certain situations.
So, which information does Drools use to optimize the algorithm?

An example taken from the Test class I mentioned:
                    .lhs()
                        .pattern("StockTick").constraint("company ==
\"RHT\"").end()
                    .end()

I guess it's important to select the StockTick by using the pattern. But
what about the company criteria? Is using the constraint faster than
invoking a method like "checkType"?

                    .lhs().pattern("StockTick").name("myStockTick").eval().constraint(
"checkCompany(myCheese, \"RHT\"").end()
                    .end()

In general, I would like to know which parts can be implemented in
"secret Java" which the drools compiler doesn't know and which parts
should be implemented by using the explicit descr api elements in order
to use the full power of the Drools engine. Thanks for your answers!
Kind regards Oliver



More information about the rules-users mailing list