Infinite loop occurs even though no-loop is used
by ST
Hi,
I have encountered an infinite loop in the following example. Where
TestVariable is has three fields, "context", "name", and "value". Context and
name are Strings. Value is an Object. To work around the infinite loop, I need
to do some ugly type casting.
---------------------------
package testobjects;
public class TestVariable {
private String context;
private String name;
private Object value;
public TestVariable() {
}
public TestVariable(String context, String name, Object value) {
setContext(context);
setName(name);
setValue(value);
}
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public String toString() {
StringBuffer sbResult = new StringBuffer(17);
sbResult.append("");
sbResult
.append("context: ").append(getContext()).append(", ")
.append("name: ").append(getName()).append(", ")
.append("value: ").append(getValue());
return sbResult.toString();
}
}
---------------------------
package com.sample
import testobjects.TestVariable
import java.util.List
rule "init"
salience 1000
when
eval(true);
then
insert (new TestVariable("Price Items Rules Context" , "Unit Price", null));
insert (new TestVariable("Price Items Rules Context", "Pricing Category",
"INTERNATIONAL"));
end
rule "test 1"
no-loop true
when
$unitPriceVariable : TestVariable(context == "Price Items Rules Context" && name
== "Unit Price")
TestVariable(context == "Price Items Rules Context" && name == "Pricing
Category" && $pricingCategoryValue : value)
$pricingCategory : String() from $pricingCategoryValue
eval($pricingCategory.equals("INTERNATIONAL"))
then
$unitPriceVariable.setValue("542.00");
update($unitPriceVariable);
end
------------
The problem goes away if I change the "test 1" rule into the following:
rule "test 1"
no-loop true
when
$unitPriceVariable : TestVariable(context == "Price Items Rules Context" && name
== "Unit Price")
TestVariable(context == "Price Items Rules Context" && name == "Pricing
Category" && $pricingCategoryValue : value)
eval(((String)$pricingCategoryValue).equals("INTERNATIONAL"))
then
// $unitPriceVariable.setValue("542.00");
update($unitPriceVariable);
end
16 years, 9 months
Re: [rules-users] Three questions
by Godmar Back
Brian, let me take a stab at answering your questions.
On Feb 11, 2008 5:46 PM, Brian Trezise <Brian.Trezise(a)intellidata.net> wrote:
>
> When I put in
> SchemaConstants.familyKey, it tells me I've got an unexpected token.
That's because Drools's LHS do not allow function calls.
"containsKey()" is a function call.
Drools cannot guarantee how often left-hand sides are evaluated, so to
rule out side-effects, function calls are forbidden altogether.
Providing an operator to test for containment in a map's keys is
another improvement request I submitted, please add a comment to
http://jira.jboss.org/jira/browse/JBRULES-1457 if you need that too.
If your map does not contain NULL values, you can use the MVEL
operator [] like so:
pFamilies[SchemaConstants.CERAMIC_CHIP_CAPACITORS] != null
>
> Is there a way to store the regex in a local rule variable? Ie,
>
> String pattern = "MAR(K|KE|KED)? ";
>
> Description matches pattern, …
>
I'm not aware of local variables (though they would certainly be
useful, maybe similar to Scheme's let) - To avoid clobbering the code
with literals like that, I usually put them into Java code, e.g.
Utils.Patterns.MarkedPattern = "MAR(K|KE|KED)?";
>
> Finally, this is a rather long line, is there a way to split apart the
> testing of the map condition from the match condition into a separate part,
> to let it match the .containsKey on a separate line?
>
Newlines should not be significant.
- Godmar
16 years, 9 months
Invalid package exception
by Matija
I have a utility that compiles a package then serializes it to disk in
a completely standard fashion. Then, in the application, the package
is deserialized to construct a rule base.
Now, this works well except if I add a rule flow to it (from a .rfm
file) - then I get the following exception on deserialization
(original compilation of the package and serialization goes okay):
org.drools.rule.InvalidRulePackage
at org.drools.rule.Package.checkValidity(Package.java:424)
at org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:364)
Anyone know what might be going on?
Regards,
M.
16 years, 9 months
two different versions...
by hamid akhtarshenas
Hi,
I have a question, How can i handle with Drools the following case:
i have two different versions of the same rule. The First one is allready deployed (On classpath, in a J2EE environment). I would like to deploy the second version, but all existing requests should still process with the old Version and new incoming requests should process with the new Version. Thanks a lot.
br,
Hamid
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
16 years, 9 months
Problem durring addPackageFromDrl
by Tushar Sinha
_____
PackageBuilderConfiguration conf=new PackageBuilderConfiguration();
conf.setCompiler(PackageBuilderConfiguration.JANINO);
//Building package builder with defined configuration
final PackageBuilder builder=new PackageBuilder(conf);
//Class ab=null;
try
{
//FileInputStream fs=new
FileInputStream("C:\\jdevstudio10133\\jdev\\mywork\\ServletApplication\\Proj
ect1\\src\\project1\\Test.drl");
//ab=Class.forName("project1.RuleTest2");
//builder.addPackageFromDrl(new
InputStreamReader(ab.getResourceAsStream("Test.drl")));
builder.addPackageFromDrl(new
InputStreamReader(getClass().getResourceAsStream("/Test.drl")));
}
catch(Exception e)
{
System.out.println("Error!"+e.getMessage());
}
//building rule base
final RuleBase ruleBase=RuleBaseFactory.newRuleBase();
ruleBase.addPackage(builder.getPackage());//adding package to the
rule base
final WorkingMemory
workingMemory=ruleBase.newWorkingMemory();//creating new working memory
final FactHandle fa=workingMemory.assertObject(taskObj);//asserting
received object from caller
workingMemory.fireAllRules();//firing rules
This is my code snippet.
It gives me Null value Exception every time I run the code. Can any one help
me.
Tushar
DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.
16 years, 9 months
property change listener for collections
by Andreas Langegger
hello,
when I have a bean and I want to use a property change listener for
collection members, how can I tell the listener the old state of the
collection?
This is the code for simple fields from the docs:
public void setState(final String newState) {
String oldState = this.state;
this.state = newState;
this.changes.firePropertyChange( "state",
oldState,
newState );
}
and now I want to hook in the firePropertyChange for the following
method which adds some elements to a set:
protected Set<Var> knownVariables = new HashSet<Var>();
public void addKnownVariable(String var) {
this.knownVariables.add(var);
changes.firePropertyChange("knownVariables", OLDSTATE??!,
knownVariables);
}
Will I have to copy the whole collection, switch the complete field
collection object that I can supply the "old state"?
thanks,
Andy
16 years, 9 months
brms deployment on tomcat error
by Houssam Haitof
Hi,
I made a fresh install of tomcat 6.0.16 and drools-4.0.4-brms under Fedora 8 "Linux 2.6.23.15-137.fc8 x86_64". I followed the steps in http://wiki.jboss.org/wiki/Wiki.jsp?page=JBRMSjsfdependencies to fix the jsf dependencies. However, running tomcat gives this error:
...
INFO: Starting Servlet Engine: Apache Tomcat/6.0.16
Feb 24, 2008 3:02:38 PM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "listeners.ContextListener" is already configured for this context. The duplicate definition has been ignored.
Feb 24, 2008 3:02:38 PM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "listeners.SessionListener" is already configured for this context. The duplicate definition has been ignored.
ContextListener: attributeAdded('com.sun.faces.config.WebConfiguration', 'com.sun.faces.config.WebConfiguration@33589e56')
Feb 24, 2008 3:02:39 PM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "org.jboss.seam.servlet.SeamListener" is already configured for this context. The duplicate definition has been ignored.
[Fatal Error] :1:1: Premature end of file.
Feb 24, 2008 3:02:41 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Feb 24, 2008 3:02:41 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/drools-jbrms] startup failed due to previous errors
...
Any idea? you help would be very appreciated.
-Houssam
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
16 years, 9 months
Re: deadlock when rules get updated?
by mmquelo massi
Hi,
Sorry to reply with another question but I need it to ask u...
Ho do u define the localDir???
I need to use it as well and I do not know how to use it.
Should I put the .pkg file somewhere in Jboss dir?
As far as concerned your issue.... how do u implement
the ruleagent???
I do the same steps in order to get the rulebase but I encapsulated
everything within a singleton "getSession()" method.... just
like the "drools insurance example".
Did u do the same??
Let me know.
Massi
16 years, 9 months
Deploying style and Rule Sessions...
by mmquelo massi
Hi there,
I know... I am a "question generator".... sorry about that!
Just a couple of questions on Drools 4.0.4 BRMS:
1) Is a statefull session necessary in order to use a ruleflow?
Can we use stateless sessions as well?
2) What kind of RuleAgent configuration do we need to provide
in order to adopt a "push style" (par 7.1.5.3.2) rules deploy?
Do we first have to set the newInstace property to true?
I guess we do because setting newInstance to true we are
constrained to call the gerRuleBase() method
in order to get the new rules from the BRMS.
In this way the BRMS would "push" the new rules every "poll"
seconds, but we would use them only when we decide to call
getRuleBase() method. In this way we would have control on
the Rule update, wouldn't we???????
Thank You as usual guys!
Massi
16 years, 9 months