How about this (anyone see any problems with this approach?)
Add an Integer to the input objects (so you don't need to run the
initialisation rule).
Then any rules that use the count have the Integer as a parameter. If you
want to increment it you would retract the old value and assert a new one
with a larger value.
If you need more than one counter, or different equals behaviour, implement
a NamedInteger class that associates a string with an integer value, and
use <class-field> in a parameter to pick up the counter you want. Or you
could implement a generic Name relation but it makes the rule files
difficult to read.
If you need to share variable data with other rules, is working memory the
best place to keep it?
Adrian.
"Amit Jain"
<[EMAIL PROTECTED] To:
<[email protected]>
o.in> cc:
Subject: Re: [drools-user] Data
Sharing in rules attached fiel
16/11/2005 09:13
Please respond
to user
Opps the file has not attached.
<?xml version="1.0"?>
<rule-set name="GetRanking"
xmlns="http://drools.org/rules"
xmlns:java="http://drools.org/semantics/java"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/rules rules.xsd
http://drools.org/semantics/java java.xsd">
<application-data identifier="count">
java.lang.Integer
</application-data>
<rule name="Rule 1" salience="100">
<parameter identifier="str">
<class>java.lang.String</class>
</parameter>
<java:condition>true</java:condition>
<java:consequence>
if(count == null){
count = new Integer(0);
}
System.out.println(count.intValue());
</java:consequence>
</rule>
<rule name="Rule 2" salience="90">
<parameter identifier="str">
<class>java.lang.String</class>
</parameter>
<java:condition>true</java:condition>
<java:consequence>
if(count != null){
System.out.println(count.intValue());
}
System.out.println(count);
</java:consequence>
</rule>
</rule-set>
----- Original Message -----
From: Amit Jain
To: [email protected]
Sent: Wednesday, November 16, 2005 2:39 PM
Subject: Re: [drools-user] Data Sharing in rules
Thanks for ur reply Mark but I am not getting the expected result. I have
attached a demo rule file to test application data.
Please have a look at the attached demo rule file where I have used
application data. I changed the value of count(global variable) to
Integer(0) in Rule 1 and I am getting null in Rule 2.
here is the outcome when the rules are fired.
0
null
Please see where am I making mistake.
With Regards
Amit
----- Original Message -----
From: "Mark Proctor" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, November 16, 2005 1:13 PM
Subject: Re: [drools-user] Data Sharing in rules
> application data is global - you might be having problems with
immutable
> objects.
> Amit Jain wrote:
> > HI!
> >
> > I need a variable which i want to use in all my rules. If i change
the value
> > of this variable it should be vissible in other rules as well. Is it
> > possible to do something like that in rule file. I tried to use
application
> > data but the value its changed in one rule is nto vissible in other.
> >
> > With Regards
> > Amit
> >
> >
> >
> >
> >
>
**********************************************************************
This e-mail and any attachment is intended for the named addressee(s) only, or
person authorised to receive it on their behalf. The content should be treated
as confidential and the recipient may not disclose this message or any
attachment to anyone else without authorisation. Unauthorised use, copying or
disclosure may be unlawful. If this transmission is received in error please
notify the sender immediately and delete this message from your e-mail system.
Any view expressed by the sender of this message or any attachment may be
personal and may not represent the view held by First Choice Holidays PLC and
its subsidiaries. All electronic transmissions to and from First Choice are
recorded, may be monitored and are scanned for viruses and content. E-mails
containing viruses will be deleted without notification. Whilst we maintain
virus checks on inbound e-mails we accept no liability for viruses or other
material introduced with this message.
All companies form part of the First Choice Holidays PLC group of companies.
First Choice Holidays PLC Company Registration No: 48967 (England)
Registered Office: First Choice House, London Road, Crawley, WestSussex RH10 9GX
**********************************************************************