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();}

}

}