are for loops possible in drools
by ceemh3
does anybody know if there is a way to do for loops in drools ?.
I am trying to loop through a list of string to see if one of the strings
matches a pattern e.g.
def listOfStrings = ['a','a.b','a.b.c']
for(String s:listOfStrings){
if(s matches "^a.b.*$"){
return true
}
}
I have written the following rule based on what documentation I could find,
but I dont think the syntax is correct
rule "Matcher"
when
TestClass : TestClass(($s matches "^a.b.*$") from listOfStrings,
count($s))
then
TestClass.setResponse( "Condition is True !!" );
end
I am finding it hard to find good documentation on the drl language
I would appreciate any help that anybody can give me
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/are-for-loops-possibl...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 7 months
Drools Objects not released from heap
by dmiller44
Hello,
I have a weird issue, and I'm trying to figure out if this is a bug I should
report, or an error in my rule. I'm running an application with a heap
space (min: 512mb, max: 1024mb) that gets full and eventually overflows
relatively quickly (12hrs or less). We insert about 112 records into a
Stateful Drools Session (Drools 5.1 CR1 released 7/22/2010) every 30seconds,
using CLOUD session type, single thread, with fireUntilHalt.
Our rules evaluate the object (A) we give it, and in some cases instantiate
a new object (B) and insert it into the session. After processing object
(A), we retract it from the session.
Another rule matches on object (B), and when finished, also retracts the
object.
When I do a heap snapshot, I've noticed quite a few Drools-related classes,
along with unreleased instantiations of object(A) & object(B) (more of the
latter). Obviously I have to take into consideration that objects are being
inserted at the time of the snapshot, but over a couple hours I'll have
1000's of these objects. I've found the only fix to be to release the
session.
I should note - calling session.getObjects() shows an empty list (size 0).
Is this a bug? When retract is called, shouldn't it free up the FactHandle &
Object to be collected? And is instantiating an object in a rule incorrect
for some reason?
Below is a small chart of classes - the number of instances - and space
taken. (TemperatureEvent represents object (A), while AssetShallowRemote
represents object (B)) Any input would be appreciated.
Dan
| Class | Instances |
Size | |
|--------------------------------------------------------------+-----------+----------+---|
| java.lang.String | 1155258 |
41589288 | |
| char[] | 1153540 |
91560120 | |
| java.util.concurrent.LinkedBlockingQueue$Node | 329989 |
10559648 | |
| java.util.LinkedHashMap$Entry | 153489 |
9209340 | |
| java.util.HashMap$Entry | 151929 |
6684876 | |
| java.sql.Timestamp | 117017 |
4212612 | |
| org.drools.reteoo.LeftTuple | 53395 |
8756780 | |
| org.drools.common.AgendaItem | 53390 |
5819510 | |
| org.drools.retoo.RightTuple | 53386 |
5125056 | |
| my.test.package.AssetShallowRemote | 42995 | 11780630 | |
| org.drools.common.DefaultFactHandle | 37273 |
3280024 | |
| org.drools.core.util.ObjectHashSet$ObjectEntry | 37273 |
1341828 | |
| org.drools.common.PropagationContextImpl | 32721 |
2683512 | |
| org.drools.core.util.ObjectHashMap$ObjectEntry | 32721 |
1639924 | |
| my.test.package.TemperatureEvent | 7165 |
917120 | |
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Objects-not-re...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 7 months
Implement timer in rule
by james corrigan
Hi All,
I am trying to implement a timer in a rule so that it executes every 15min i
have the following code:
rule " When average temperature is greater than 19 turn on fans"
timer(int:0 15m)
when
$t : Temperature($room : room)
$fan : Fan( room == $room )
then
"i need to implement this yet
end
I am getting on the timer: "[ERR 101]Line 61:0 no viable alternative at
input 'timer' in rule ......
I read example 2.12. Example timer attribute uses from
https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/t...
and this is how it says to implement a timer.
Any help is greatly appreciated.
Kind regards,
James.
15 years, 7 months
FW: Drools 5.1.0.M2 - WorkItemNodeInstance --Listeners can't get hold of WorkItem object
by Vijay K Pandey
Hi @Salaboy,
Did you get a chance to look into this?
Thanks
Vijay
From: Vijay K Pandey
Sent: Thursday, July 15, 2010 1:26 PM
To: 'rules-users(a)lists.jboss.org'
Subject: FW: [rules-users] Drools 5.1.0.M2 - WorkItemNodeInstance --Listeners can't get hold of WorkItem object
Hi @Salaboy,
I am not sure if you received the email below. Thanks for looking into this.
Vijay
From: Vijay K Pandey
Sent: Tuesday, July 13, 2010 8:53 AM
To: 'Mauricio Salatino'
Subject: RE: [rules-users] Drools 5.1.0.M2 - WorkItemNodeInstance --Listeners can't get hold of WorkItem object
Thanks for a quick response. I added the Transaction Manager piece of code but the problem still persists. Also it uses the attached persistence.xml file which is placed under META-INF directory that has the correct transaction manager look up class.
Thanks
Vijay
From: Mauricio Salatino [mailto:salaboy@gmail.com]
Sent: Tuesday, July 13, 2010 6:40 AM
To: Vijay K Pandey
Subject: Re: [rules-users] Drools 5.1.0.M2 - WorkItemNodeInstance --Listeners can't get hold of WorkItem object
I've just take a quick look to your file and I notice (without running it) that you didn't set the TransactionManager property to your Environment:
env.set( EnvironmentName.TRANSACTION_MANAGER,
TransactionManagerServices.getTransactionManager() );
You also need to have the reference to bitronix inside your persistence.xml file:
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.BTMTransactionManagerLookup"/>
Can you try this and let me know if it fix your problem?
Greetings
On Tue, Jul 13, 2010 at 12:43 AM, Vijay K Pandey <VPandey(a)mdes.ms.gov<mailto:VPandey@mdes.ms.gov>> wrote:
Thanks Salaboy for looking into this.
Here is the Junit Test case(java file attached) I created for this problem.
Line # 129 fails.
Please do let me know if I am doing something wrong or the fix has some issues or maybe there is some other way out to get hold of the "WorkItem" object in the process event listener.
Thanks
Vijay
From: rules-users-bounces(a)lists.jboss.org<mailto:rules-users-bounces@lists.jboss.org> [mailto:rules-users-bounces@lists.jboss.org<mailto:rules-users-bounces@lists.jboss.org>] On Behalf Of Salaboy
Sent: Friday, July 09, 2010 11:11 AM
To: Rules Users List
Subject: Re: [rules-users] Drools 5.1.0.M2 - WorkItemNodeInstance -- Listeners can't get hold of WorkItem object
I would like to take a look on this issue. Can you provide me a test case that show the problem?
- CTO @ http://www.plugtree.com
- MyJourney @ http://salaboy.wordpress.com
- Co-Founder @ http://www.jbug.com.ar
- Mauricio "Salaboy" Salatino -
On Jul 9, 2010, at 12:43, Vijay K Pandey <VPandey(a)mdes.ms.gov<mailto:VPandey@mdes.ms.gov>> wrote:
I guess this problem was due to a fix done in WorkItemNodeInstance? Is this the correct behavior? If yes how do we get hold of "WorkItem" instance in the attached listeners?
http://fisheye.jboss.org/browse/JBossRules/trunk/drools-core/src/main/jav...
Thanks
Vijay
From: Vijay K Pandey
Sent: Tuesday, June 15, 2010 9:20 AM
To: 'Rules Users List'
Subject: RE: Drools 5.1.0.M2 - WorkItemNodeInstance -- Listeners can't get hold of WorkItem object
Any one on this issue? Any Drools Flow expert?
Appreciate your time for taking a look at it.
Thanks
Vijay
From: Vijay K Pandey
Sent: Thursday, June 10, 2010 12:03 PM
To: 'Rules Users List'
Subject: RE: Drools 5.1.0.M2 - WorkItemNodeInstance -- Listeners can't get hold of WorkItem object
Should I log this as a JIRA ticket.
Thanks
Vijay
From: Vijay K Pandey
Sent: Wednesday, June 09, 2010 9:57 AM
To: 'Rules Users List'
Subject: Drools 5.1.0.M2 - WorkItemNodeInstance -- Listeners can't get hold of WorkItem object
Hi,
There is a change done in Drools 5.1.0.M2 - org.drools.workflow.instance.node.WorkItemNodeInstance class in the method
public void triggerCompleted(WorkItem workItem) at line 196 which is setting the workItemId as -1
this.workItemId = -1;
Due to the above change the listeners which are attached to the "complete" event of the work item - such as the method below
public void beforeNodeLeft(ProcessNodeLeftEvent event) are not able to get hold of the associated workitem object as it returns null.
Is there any specific reason that workItemId is set to -1 even before the associated listeners get triggered or is this a bug?
If it was an intended change then how do I get hold of the "WorkItem" object in the attached listeners.
Thanks
Vijay
p.s This change was not there in the snapshot of 18th April 2010 which I was earlier working on. Above is the only change in this class from the snapshot of 18th April and 5.1.0.M2
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org<mailto:rules-users@lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/rules-users
--
- CTO @ http://www.plugtree.com
- MyJourney @ http://salaboy.wordpress.com
- Co-Founder @ http://www.jbug.com.ar
- Salatino "Salaboy" Mauricio -
15 years, 7 months
How to Iterate list in drools
by Dinesh kumar
Hi,
I am facing problems in iterating a list in guvnor.
I tried the following code and it worked.
import java.util.ArrayList;
rule createValidationReport
dialect 'java'
when
ClaimRegistration($ailmentList : ailmentListFromScreen)
then
for(String ailment : (ArrayList<String>) $ailmentList){
System.out.println("ailment "+ailment);
}
System.out.println("then");
end
But my requirement is to iterate the list in the when block and process
something based on the data in the list.
It should be something like
import java.util.ArrayList;
rule createValidationReport
dialect 'java'
when
ClaimRegistration($ailmentList : ailmentListFromScreen)
for(String ailment : (ArrayList<String>) $ailmentList){
System.out.println("ailment "+ailment);
// My condition needs to be evaluated here
}
then
System.out.println("then");
end
Need help on this issue. Is this possible in Drools?
kindly advice.
Regards,
Dinesh
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/How-to-Iterate-list-i...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 7 months
Rules integration with Java -need help
by Dinesh kumar
Hi,
Need help in integrating guvnor with my java application.
I have the set rules to executed for a particular module as individual
packages within guvnor. To fire these rules, I have separate properties file
specifying the URL of each package and mention it within the application as
below.
For module1:
Properties properties = new Properties();
properties.load(new FileInputStream(module1PropertiesFilePath));
RuleAgent agent = RuleAgent.newRuleAgent(properties);
RuleBase ruleBase = agent.getRuleBase();
WorkingMemory workingMemory = ruleBase.newStatefulSession();
workingMemory.insert(module1Object);
workingMemory.fireAllRules();
For module2:
Properties properties = new Properties();
properties.load(new FileInputStream(module2PropertiesFilePath));
RuleAgent agent = RuleAgent.newRuleAgent(properties);
RuleBase ruleBase = agent.getRuleBase();
WorkingMemory workingMemory = ruleBase.newStatefulSession();
workingMemory.insert(module2Object);
workingMemory.fireAllRules();
My properties file looks like this. There will be one properties file for
each module.
##
## RuleAgent configuration file example
##
#setting this means the rulebase will be created fresh whenever there are
#changes
newInstance=true
#this points to a binary compiled rule package, you can have spaces
#seperating multiple files
#file=/foo/bar/boo.pkg /foo/bar/boo2.pkg
#this specifies that packages may appear in a directory
#it will pick up whatever files are dumped in there (.pkg files like above)
#dir=/my/dir
#this specifies a list of urls for packages - these urls
#are those that are exposed by the BRMS
url=
http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/Modu...
#the following can be used with the urls to keep a local cache
#so if the runtime server is restarted, the BRMS does not need
#to be available
#localCacheDir=
#this specifies the frequency at which the sources will be checked for
#changes (in seconds). If you don't set this, it will mean that you have
#to manually poll
poll=30
#this specifies the name of this config, necessary in case logging is used.
name=MyConfig
Instead of specifying the url in the properties file, can i directly have
the url in my java..
How to directly specify the url in java instead of using properties file?
Any suggestions will be of great help..
Regards,
Dinesh
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Rules-integration-wit...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 7 months
fireAllRules performance
by sjoo822
I have several thousand objects that gets inserted into a statefull knowledge
session as show below:
for (Item item : itemList)
{
session.insert(item);
}
session.fireAllRules();
Assuming that all the conditions in the rules only concern with one item at
a time, will there be a big performance difference if I changed the above to
as shown below?
for (Item item : itemList)
{
session.insert(item);
session.fireAllRules();
}
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/fireAllRules-performa...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 7 months