[rules-users] drools quirks

Matt Young solid at youngdev.net
Sat Sep 18 11:19:55 EDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

maybe now would be a good time for some code.  Here is how I am
executing the rules against the object:
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();


        KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
       
kbuilder.add(ResourceFactory.newByteArrayResource(ruledata),ResourceType.DRL
);
        if ( kbuilder.hasErrors() ) {
            System.err.println( kbuilder.getErrors().toString() );
        }
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
        StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession();
        ksession.execute(document);

Here is the rule:

package sample1

import sample1.bean.EventRulesDocument;
import sample1.bean.Transaction;
import java.util.Date;

rule "Standard processing rule"

    when
          $doc : EventRulesDocument(
            ruleRun == false &&  # <<< Wolfgang
            event != null && event.eventType.eventCode == "testevent" )
    then
   
       Transaction t = new Transaction();
        t.setEvent($doc.getEvent());
        t.setCategory($doc.getEvent().getEventType().getEventCode());
        t.setTransactionAmount($doc.getEvent().getEventAmount());
         t.setCreateTs(new Date());
         t.setUsername($doc.getEvent().getCreateUsername());

        modify( $doc ) {setRuleRun(true)};   # Wolfgang <<<<<<
        modify( $doc ) {addSaveTransaction(t)} ;

       
end

If I take out the 2 lines marked "Wolfgang", the ksession never
returns from the execute() method.

Additionally If any code in the world can be executed in the RHS, then
why shouldn't I just use groovy as my rule language?  At least then, I
can write math like such:
def num1=95;
def num2=90;
def num3=num2/num1;

and all of the math is done with big decimal objects.  IF there is no
restriction on what can be done in the RHS what is the advantage to
using a rules engine over a general purpose scripting language?  The
whole purpose for me choosing drools over Groovy eval() was that I
didn't want to give my users the ability to spawn threads, allocate
massive amounts of memory etc.  

On 09/18/2010 10:59 AM, Wolfgang Laun wrote:
> On 18 September 2010 16:15, Matt Young <solid at youngdev.net
> <mailto:solid at youngdev.net>> wrote:
>
> I just started using drools and this is my first time implementing
> a rules engine.  Everything has been pretty smooth but I have
> some quirks that I am not sure I can live with. 1) for some reason,
> if I execute the Knowlege session against an object, the knowlege
> session never returns.
>
>
>> I don't understand the term "execute...against an object". Do you
>> mean that you have just one fact inserted befor you call
>> fireAllRules()?
>
>> But anyway, this call not returning is almost certainly due to a
>> loop in your rules, or have you made sure that they don't?
>
>
> The only way I can get the ksession to return is to make IF (obj ==
> null) part of the LHS and make modify($input){setObj("complete")}
> part of the RHS This seems like a deficiency since I have users
> writing their own rules, I can see them forgetting this
> requirement.
>
>
>> Writing rules is programming, no holds barred :-)
>
>> Look into Domain Specific Languages (DSL) as a cushion for the
>> unwary.
>
>
>
> IS their a way to get the ksession to firerules only once?  If so
> what does that look like?
>
>
>> kSession.fireUntilHalt( 1 );
>
>
> 2) It seems that any code I want can be executed in the RHS.  I
> could literally execute something like the following in the RHS.
>
> byte[] b= new byte[10000000000000]; // Really big memory waste
>
> I also could just start a bunch of threads.
>
> The point is that I am intending to let the users write their own
> rules but I can't do that if there are no restrictions on how/what
> can be done inside the rules.  Any suggestions?  Are there
> sandboxes or filters I can activate to restrict the RHS?
>
>
>> Again: DSL.
>
>> Also, Rule Templates might be the starting point; it'd depend on
>> what the may be allowed to do.
>
>> And what about good old-fashioned training?!
>
>> -W
>
>

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/rules-users




> _______________________________________________ rules-users mailing
> list rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users

- -- 
Cheers,
Matt Young
solid at youngdev.net
http://youngdev.net

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJMlNibAAoJEO5jycTTPEzc5uUQAJ1ku8gHoMLKVf8Y64llpAIK
n0jKIkUbvs44AKEIq3bv6hM9x1sqskJ8zXqV1FmrJ6FLeILPpqc2El/QVQkY5YVh
xKbFU6FOEhjhR8lcOCLu9Pt7Bxh0eWcdpJsGN/4PAaUDmS4f4UEj1OH5TRdxKWvn
sw4nR3N+KxJKIOSsvW2IXcULdiy3rQm3YYs7GvQmiPbrgLzSYxGhPBsy/W18P75f
xefctOjsuFt89BP3BUjzut3Hu7Q/1bhCETwV0sGg2c7oynbgiRY96/tGCvdVYroM
1h0vcv2zwnxmJcWx0ipzf8Tmwkliy2MY2ITcgIrcZP21FY3AxcvU2SvKgrFj9C+N
68c8PM0m0ZMHB5AKNB+2AeI5/52AP9K9LwLxAZu0EaXpS62E/ZIQ0F7TSGNmZi2o
7bYLl1C7BH2JV9+Zfxy4B0kfOzMeoT+cBscA8YUQ8twmy2QHGQ5CqUdRvlaL1Ktc
WfWFLjsuJm09D+iCS8wg+V4DcqeTH7NMPicodUFeXtxzvsZzmXoXRv+OIYGp2zla
uBuMgQGYMI651RTWWvLN4IyUlbwJPWMg974LcBir1SOogyfdU/2A4s4kPMh2CK4v
X/UCK4J/dX1DYGmrpEUqOkyHiajPqfbA7yed+K+SbfUbNwGvzl6q4gaE2eM+w1pz
bT9rOgr9PFpyiL2EPdut
=UoOJ
-----END PGP SIGNATURE-----




More information about the rules-users mailing list