NPE when retracting the objects in working memory...
by Reddy Ramesh-in2259c
Hi,
I am getting null pointer exception when i retract objects from working
memory. please help me in resolving this problem....
my rule goes like this...
package com.moto.nms
import com.moto.nms.Event;
import com.adventnet.nms.topodb.ManagedObject;
import com.motorola.nmatg.nms.topology.ManagedEntity;
global com.moto.nms.Consecutive con; // Consecutive is an simple
class file which has two simple methods, getValue() and setValue().
rule "duplicate"
salience 29
when
e1 : Event( firsttime1 : time , severity1 : severity == 1 )
e2 : Event( firsttime2 : time > firsttime1 , severity == severity1 )
not Event( severity == -1 , time > firsttime1 , time < firsttime2)
then
System.out.println("matched the fact");
e1.setCompressionStatus("compress_"+con.getValue());
e2.setCompressionStatus("compress_"+con.getValue());
end
rule "duplicate_x"
salience 29
when
e1 : Event(firsttime1 : time , severity == 1 )
e2 : Event(firsttime2 : time > firsttime1 , severity == 1)
exists Event( severity == -1, time > firsttime1 , time < firsttime2)
then
System.out.println("matched 2nd fact");
con.setValue(con.getValue() +1);
end
exception is like this...
Caught Exceptionjava.lang.NullPointerException
java.lang.NullPointerException
at org.drools.reteoo.beta.DefaultRightMemory.remove(Unknown Source)
at org.drools.reteoo.BetaMemory.remove(Unknown Source)
at org.drools.reteoo.NotNode.retractObject(Unknown Source)
at org.drools.reteoo.ObjectSource.propagateRetractObject(Unknown Source)
at org.drools.reteoo.RightInputAdapterNode.retractTuple(Unknown Source)
at org.drools.reteoo.TupleSource.propagateRetractTuple(Unknown Source)
at org.drools.reteoo.NotNode.retractTuple(Unknown Source)
at org.drools.reteoo.TupleSource.propagateRetractTuple(Unknown Source)
at org.drools.reteoo.JoinNode.retractTuple(Unknown Source)
at org.drools.reteoo.LeftInputAdapterNode.retractObject(Unknown Source)
at org.drools.reteoo.ObjectSource.propagateRetractObject(Unknown Source)
at org.drools.reteoo.AlphaNode.retractObject(Unknown Source)
at org.drools.reteoo.ObjectSource.propagateRetractObject(Unknown Source)
at org.drools.reteoo.ObjectTypeNode.retractObject(Unknown Source)
at org.drools.reteoo.Rete.retractObject(Unknown Source)
at org.drools.reteoo.ReteooRuleBase.retractObject(Unknown Source)
at org.drools.reteoo.ReteooWorkingMemory.doRetract(Unknown Source)
at org.drools.common.AbstractWorkingMemory.retractObject(Unknown Source)
at org.drools.common.AbstractWorkingMemory.retractObject(Unknown Source)
at com.moto.nms.TestEvents3.retractAll(TestEvents3.java:219)
at com.moto.nms.TestEvents3.readRule(TestEvents3.java:158)
at com.moto.nms.TestEvents3.main(TestEvents3.java:242)
TestEvents3.java class is like this....
package com.moto.nms;
//related to IO..
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.InputStream;
import java.util.List;
import java.util.Iterator;
//related to Drools..
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
import org.drools.WorkingMemory;
import org.drools.FactHandle;
import org.drools.FactException;
import com.moto.nms.Event;
import com.moto.nms.NMSEvent;
import com.moto.nms.TopoInterface1;
import com.moto.nms.GenerateEvents;
import com.adventnet.nms.topodb.ManagedObject;
import com.moto.nms.Consecutive;
public class TestEvents3 {
private Reader reader;
private RuleBase rulebase;
private WorkingMemory wm;
private List factHandles;
public TestEvents3(){
}
public void readRule(String readername) throws Exception{
InputStream str = null;
str = TestEvents.class.getResourceAsStream(readername);
if(str == null)
{
System.out.println("unable to read rule file");
return;
}
reader = new InputStreamReader(str); //read in the source
PackageBuilder builder = new PackageBuilder(); //building up the rule
package
builder.addPackageFromDrl(reader);
Package pkg = builder.getPackage(); //get the compiled package
rulebase = RuleBaseFactory.newRuleBase();
rulebase.addPackage( pkg ); //adding the package to the rule base
Consecutive con = new Consecutive();
wm = rulebase.newWorkingMemory();
wm.setGlobal("con", con);
System.out.println("\n\n"+System.currentTimeMillis());
Event ev1 = new Event(183, 1, "port02", "LOS",
System.currentTimeMillis());
//Thread.sleep(450);
Event ev9 = new Event(192, 1, "port02", "LOS",
System.currentTimeMillis());
//Thread.sleep(400);
Event ev10 = new Event(307, 1, "port02", "LOS",
System.currentTimeMillis());
Thread.sleep(500);
Event ev11= new Event(306, 1, "port02", "LOS",
System.currentTimeMillis());
Thread.sleep(200);
Event ev12= new Event(305, 1, "port02", "LOS",
System.currentTimeMillis());
Thread.sleep(250);
Event ev13= new Event(304, -1, "port02", "LOS",
System.currentTimeMillis());
Thread.sleep(600);
Event ev14= new Event(302, 1, "port02", "LOS",
System.currentTimeMillis());
Thread.sleep(200);
Event ev15= new Event(301, 1, "port02", "LOS",
System.currentTimeMillis());
Thread.sleep(200);
Event ev16= new Event(308, 1, "port02", "LOS",
System.currentTimeMillis());
wm.assertObject(ev1);
wm.assertObject(ev9);
wm.assertObject(ev10);
wm.assertObject(ev11);
wm.assertObject(ev12);
wm.assertObject(ev13);
wm.assertObject(ev14);
wm.assertObject(ev15);
wm.assertObject(ev16);
System.out.println("\n\n"+System.currentTimeMillis());
System.out.println("\n\nFiring rules...\n");
wm.fireAllRules();
factHandles = wm.getObjects();
System.out.println("\n\nAll the Objects in WOrking Memory are as
Follows...\n");
for(int i=0; i<factHandles.size(); i++)
{
System.out.println(factHandles.get(i));
}
System.out.println("The CompressionStatus of the events are...");
System.out.println(ev1.getCompressionStatus());
System.out.println(ev9.getCompressionStatus());
System.out.println(ev10.getCompressionStatus());
System.out.println(ev11.getCompressionStatus());
System.out.println(ev12.getCompressionStatus());
System.out.println(ev13.getCompressionStatus());
System.out.println(ev14.getCompressionStatus());
System.out.println(ev15.getCompressionStatus());
System.out.println(ev16.getCompressionStatus());
System.out.println("The DeletionStatus of the events are...");
System.out.println(ev1.getDeletionStatus());
System.out.println(ev9.getDeletionStatus());
System.out.println(ev10.getDeletionStatus());
System.out.println(ev11.getDeletionStatus());
System.out.println(ev12.getDeletionStatus());
System.out.println(ev13.getDeletionStatus());
System.out.println(ev14.getDeletionStatus());
System.out.println(ev15.getDeletionStatus());
System.out.println(ev16.getDeletionStatus());
Thread.sleep(1000);
System.out.println("Starting retracting....");
Thread.sleep(1000);
retractAll();
System.out.println(System.currentTimeMillis());
}
public void retractAll()
{
factHandles = wm.getFactHandles();
Iterator itr = factHandles.iterator();
if(factHandles == null)
{
System.out.println("invalid FactHandler List");
return;
}
System.out.println("size of fact handles..:"+factHandles.size());
while(itr.hasNext())
{
try{
FactHandle fh = (FactHandle)itr.next();
if(fh == null)
System.out.println("Here object is null, Cannot be retracted");
else
{
wm.retractObject(fh);
System.out.println("Retracted object : "+ fh);
}
}catch (FactException e){
e.printStackTrace();
}
}
return;
}
public static void main(String[] args){
TestEvents3 te = new TestEvents3();
try{
te.readRule("/AlarmSuppression.drl");
}catch(Exception ex){
System.out.println("Caught Exception" +ex);
ex.printStackTrace();}
}
}
Thanks,
RameshReddy,
Trainee,
Motorola India.
17 years, 9 months
Correlation of events
by Framewala, Ashfaq Y
Hi,
I am working on a system where I need to correlate few error conditions
happening in the network infrastructure. I have gone through the
documentation for Jboss rules engine (Drools) and I am planning to use
it for the correlation purpose.
Can anyone let me know a way in which I can get an object from
workingmemory in the "then" part of the rule? For e.g., I need the
following
rule "new error"
when
$error : Error (state == NEW_ERROR)
then
(search workingmemory if this error was already
registered)
if (found)
{
$errFromWorkingMemory.setLastTimestamp(currentTimestamp)
retract($error);
}
End
Thanks,
Ashfaq
17 years, 9 months
Decision Tables and Application Deployment
by Druler123
Hello Everybody,
I've just started working on a project that will make use of Decision Tables
and Drools. I have read the documentation on the JBoss site and reviewed the
webinar. So the next step obviously is to join a forum and this looks like a
great place to start.
My question is in regards to actually loading in the table file. Looking at
the example I saw something similiar to the following:
I seem to keep seeing the tables being loaded into the working memory by a
Class Loader. Is this my only option? Also, that being said, is the
recommended approach for deployment to deploy the Decision tables in a jar
file and import that jar file into say a web service project in order to
reference it? Or should it be distributed across the multiple project (like
the server's) classpath?
Besides what the webinar and tutorials have demonstrated, I'm still a bit
confused as to how everything fits together...
Any help would be much appreciated!!
--
View this message in context: http://www.nabble.com/Decision-Tables-and-Application-Deployment-tf327690...
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 9 months
issues with 'contains' and 'and'
by Amarendra Mishra
Hi,
I am trying to write a protoype with JBoss Rules 3.0.5
I am having problem in getting the following working properly :
rule "CompDept Product Qualification Rule"
salience 7
no-loop true;
when
$cust:( Customer( productIDs contains "Computer")
or Customer(productIDs contains "monitor"))
# Customer(compDeptState == Customer.NOTRUN) <-------- Commented line
then
$cust.setCompDeptState (Customer.DONE);
System.out.println("getStatus after...." + $cust.getCompDeptState () );
$cust.addQualifiedProduct("CompDeptProduct");
System.out.println("CompDeptProduct qualified...." );
modify($cust);
end
where productIDs are defined as Vector in Customer class.
If I run the above rule it goes in recursive mode (I have another rule in the drl that also acts on the same customer object and modifies it).
If I uncomment the commented line my LHS it's not evaluating to true and RHS is not running.
Any help would be appreciated.
Kind Regards,
Amarendra.
____________________________________________________________________________________
Bored stiff? Loosen up...
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front
17 years, 9 months
accessing the data base
by Francisco Brum
Hi everybody!
I would like to be able to access the data base during the execution of a rule.
The reason it's because instead of asserting in the working memory information as a global, it would be easy to make a SQL query using hibernate to consult the information.
Can I implement this in a function of my global fact or there is another way?
Thanks in advance for your attention!
__________________________________
Francisco Brum - francisco.brum(a)link.pt <mailto:rui.arrenega@link.pt>
Link Consulting - http://www.link.pt/ <http://www.link.pt/>
Tel.: 213 100 031
Av. Duque D'Ávila, 23 4º Esq.
1000-138 Lisboa
17 years, 9 months
modify object Tree?
by seeker
I have a fact which holds a reference to another fact. I wonder which one do
I have to modify in my RHS.
My Objects are Room and Thermometer. Room holds reference to Thermometer
(and that has a property describing the value).
When my rule fires I want to decrease the temperature level to simulate that
the room gets colder until a certain value A is reached. So the rule should
be called several times until the actual level equals A.
This works ONE time when I set the new value on Thermometer and modify
Thermometer, not reaching A (the rule isnt fired again).
But works as expected when I modify Room instead of Thermometer (rules is
fired several times).
I'm new to drools and wonder if that is desired or if I do something wrong.
To make things more confusing: When several rules met the same conditions,
does only one rule gets fired or do all get fired (as I read it from Figure
1.19 of the documention).
If I modify Room my other rules _dont_ get fired. When I had modified
Thermometer my other rules _do_ get fired.
Is there anyone who can shed a little light on that for me?
--
View this message in context: http://www.nabble.com/modify-object-Tree--tf3268137.html#a9085281
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 9 months
logging with Jini
by Johnson, Brad
Hello
I am using the rules engine within a Jini service. It seems to work
except for logging. Jini only supports java.util.logger from Sun. Rules
runs fine most of the time, I just am not able to see any of the log
messages. I am now having an issue I cannot diagnose without seeing the
Rules log messages.
Is there some adaptor to connect up the way Rules does logging with
java.util.logger?
Thanks
Brad
17 years, 9 months
Autoboxing
by wernejen@TU-Cottbus.De
Hi everbody,
I'm trying to translate an other rule-language in JBossRules (with
XSL(T)).
One of my major problems is the autoboxing- without unboxing-support in
the engine.
I think it is a general problem, because (1) everyone who is writing a
rule has to know what types the properties in the objects (beans)
to be used are. I think it is enough to know is it a digit, a boolean
or... The trouble begins in an evaluation:
when
Person ($age1 : age, name == 'Mike')
Person ($age2 : age, name == 'Peter')
eval ($age1 > $age2) // !!! it's wrong
eval ($age1.intValue() > $age2.intValue()) // it's ok if the Objects
// are Integer and not
// Double or ...
..
I think a rule-creator without java-knowlege has only little
understanding for this. (... and rules are for specialist from different
domains???)
(2) another conflict is in the different handling in fieldconstraints and
evaluations.
I can use all operators for simple types in field constraints but not in
evaluations:
when
Person (age > 20) // here I use the field as a primintiv type
Person (age < 30)
..
I know that all of them based on java and oop and I need this knowledge
for the RHS, but this confusion is not helpful for beginners or user
from other domains.
I don't know, what the reason for autoboxing (without unboxing
especially in java 5) is.
I'm confused by the documentation.
(Drools Documentation: "... If you use Java 5, then you get the best of
both worlds ..." (context autoboxing).
Another line in the drool documentation: "All bound primitive
declarations are boxed, there is currently no auto-unboxing (if you use
java 5, this is all automatic).")
Will the unboxing be supported in futur versions?
(... or afford a possibility for switch off the autoboxing?)
Thanks,
-jens
17 years, 9 months
RE: [rules-users] debugging with 3.1M1 IDE?
by Anstis, Michael (M.)
Barry, on reading your email I downloaded the current binaries and
followed the installation instructions for the Eclipse plugin. I simply
copied org.drools.ide_3.1.0.1.jar to
<eclipse-install>\sdk-3.2.1\eclipse\plugins and I could put breakpoints
in the RHS of my rules. I started a new debug configuration in Eclipse
by clicking on the "Debug..." on the dropdown list beside the "bug" icon
and choosing a new "Drools Application".
Sorry all appears OK to me :-(
Mike
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Barry Kaplan
Sent: 22 February 2007 14:25
To: Rules Users List
Subject: Re: [rules-users] debugging with 3.1M1 IDE?
Well, I just checked out head and rebuilt the IDE with both the feature
and plugin. But I get no drools launch type....
(BTW, The ant/maven build seem to run clean. But importing the drools
projects into eclipse results in lots of projects with errors. Is this
expected for M1.)
-barry
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
17 years, 9 months