There is no out of the box way to do this, you could add an event
listener and check yourself for recursion and halt the session if it is
spotted.
Mark
Isabelle Hupont wrote:
Hi!
I'm developing a software where the user creates his own rules, saves then,
and finally fires them in order to preprocess a set of data.
I have implemented a method for controlling infinite loops (its simply a
timer). I would like to notify to the user the rule that has caused the
infinite loop, in order to change it. My code is the following:
public void fireRules(Instances instances) {
try {
assertInstances(instances);
// Worker thread to execute task that may hang.
WorkerThread workerThread = new WorkerThread();
// Wait for timeout or task end.
synchronized (this) {
workerThread.start();
try {
this.wait(60000);
} catch (InterruptedException e) {
log.error(e.getLocalizedMessage(),e);
}
if (!workerThread.isWorkDone()) {
// If work is not done then workingMemory.fireAllRules()
// hasn't finished (the timeout has expired).
workingMemory.halt();
// Here comes the code for capturing
rule that has code the loop
throw new PersistenceException("Operation timeout. Please modify rule
XXX" );
}
}
cleanWorkingMemory();
} catch (PersistenceException e) {
log.error(e.getLocalizedMessage(),e);
}
log.debug("Rule firing finished");
}
private class WorkerThread extends Thread {
private boolean workDone = false;
public boolean isWorkDone() {
synchronized (SingletonInferenceEngine.this) {
return workDone;
}
}
public void run() {
workingMemory.fireAllRules();
synchronized (SingletonInferenceEngine.this) {
workDone = true;
SingletonInferenceEngine.this.notifyAll();
}
}
}
Can you help me?
Thanks in advance!