[rules-users] DRL Functions

Swindells, Thomas TSwindells at nds.com
Thu Oct 14 07:06:26 EDT 2010


It shouldn't be hard to provide rewrite support for references to globals and the working memory methods - the logic to modify the methods would be the same as for a rules defaultConsequence handler.

The main challenge then is to get the drools reference into the static functions.

The simplest solution could be to add the KnowledgeHelper in to a static ThreadLocal populated (and cleared) by either the rule or fireAllRules, the drl function (or any other function) could then retrieve and use this.

Thomas

From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Wolfgang Laun
Sent: 13 October 2010 18:45
To: Rules Users List
Subject: Re: [rules-users] DRL Functions

Implementing this would require a detailed parsing of function bodies and more,
to get the runtime object into the scope of the static methods compiled from
DRL functions.

As it is, a minor improvement is possible with:

import org.drools.spi.KnowledgeHelper;

function void ins( KnowledgeHelper kh, Object... obj ){
    kh.insert( obj );
}

//...
then
    ins( drools, new Fact( ... ) );
end

2010/10/13 Swindells, Thomas <TSwindells at nds.com<mailto:TSwindells at nds.com>>
I've just been writing what should be a really simple function in my DRL.
What I wanted to do is to take an object in, construct another object from it and then insert both into working memory.
Eg.
function void insertBoth(Object1 object1) {
      insert(new Object2(object1));
      insert(object 1);
}

Rule XYZ
When
Then
                insertBoth(new Object1());
End


This didn't work as expected however as it couldn't find the method insert.
I then thought, ah maybe I need to use the kcontext global to access them

function void insertBoth(Object1 object1) {
      kcontext.insert(new Object2(object1));
      kcontext.insert(object 1);
}

Rule XYZ
When
Then
                insertBoth(new Object1());
End

This doesn't work either so what I've had to do is:

function void insertBoth(KnowledgeContext kcontext, Object1 object1) {
      kcontext.getKnowledgeRuntime().insert(new Object2(object1));
      kcontext.getKnowledgeRuntime().insert(object 1);
}

Rule XYZ
When
Then
                insertBoth(kcontext, new Object1());
End

This is suddenly a lot more complicated than it needs to be.  Why can't functions have the same access to the standard operations (insert, update, retract etc) and globals as rule actions currently do?
Should I raise an issue for this or am I missing something?

Thomas

________________________________

**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com<mailto:postmaster at nds.com> and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************

_______________________________________________
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


________________________________

**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101014/0bb49bbf/attachment.html 


More information about the rules-users mailing list