Re: [rules-users] Killing a session
I already used a global limit of rule's firing with success to prevent these kind of problems (with a big number, eventually calculated from rules as Wolfgang said). This works, at least to detect infinite loops, because usually, when this happend, the number of firing increases very fast so the big number is hit quite early. Of course, if you have many rules, and/or many facts, an absolute number could be problematic to set (generally solved by making it easily modifiable so the rules' writer can change this quickly if it find it too low). And if you session is a living daemon thread, you have to find a way to reset the counter... And I agree with Wolfgang, 'most of time', a single rule is looping. May be two... 3 or 4 is rare ... May be you can maintain (in a Session's AgendaListener) a map that count firing for each rule and put a global max number of activation, but by rule. Time duration is a good way too, but needs a additionnal thread to monitor time consumed so far, and the value could be hard to set. Another safer way is to force your users to execute some kind of unit tests before deploying their rules (and these tests are executed with a time and/or rule firing global limit). You can also (if you have some kind of deployment procedure by code), execute these tests as a condition to accept the deployment. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Killing a session
On 15/05/2012, mike wrote: > that's nice ... n' a bit clever ... it could work ... I mean, i could > automatically append that to all sessions given that i control compiling > the drls. > > Is there any setting or something that detects infinite loops? Like it > would abort if if drools runs into an infinite loop? Even wily strategies for loop detection aren't fail-safe. Loops can occur over cycles of two, three, four,... rules. (Four was the max. that has occurred here in 25 years, but that's no guarantee.) Now, if you monitor activations and save the last n rules, that won't work either, because you can have one rule firing repeatedly with varying facts, and that's not necessarily an infinite loop - but it could be, returning to the same set of facts after two, three, four,... activations. So, implementing any of the aforementioned would only help you in the testing stage, you can't rely on it in production runs. > > I guess I could do something with fireAllRules(int max) but figuring out a > reasonable max would be fuzzy. I could also use the no-loop attribute but > it would not pick up some cases of infinite loops. There are scenarios where a maximum can be derived from the number of rules, or facts, or both. A crude safeguard would be a maximum duration, interrupting the thread running the Engine. -W > > Thank you very much for you help > > Cheers > Mike > > > > On Tue, May 15, 2012 at 3:55 PM, Wolfgang Laun > wrote: > >> A very low salience rule depending on nothing and calling halt will stop >> the run: >> >> rule Exit >> salience -9 >> when >> then >> drools.halt(); >> end >> >> -W >> >> >> On 15 May 2012 21:46, mike wrote: >> >>> Well I got this wrong sorry. Yes I can stop a session if I start it with >>> fireUntilHalt() but it never stops. I need it to finish by itself too. >>> >>> Thank you >>> Mike >>> >>> >>> On Tue, May 15, 2012 at 11:06 AM, mike wrote: >>> wow that worked like a charm!!! thank you very much Wolfgang, I owe u a beer or something :) Cheers Mike On Tue, May 15, 2012 at 11:01 AM, mike wrote: > Awesome I'll try that :) > > We got business ppl writing rules ... Those rules are going on > infinite > loops quite often ... Frankly I am not excited about killing the > session, > for me it's just a business request that I am trying to implement > > Thank you very much Wolfgang > > Cheers > Mike > > > On Tue, May 15, 2012 at 10:53 AM, Wolfgang Laun < > wolfgang.l...@gmail.com> wrote: > >> You are confusing jBPM processes and Java threads. >> >> You can interrupt the thread SessionThread, but that's not reliable >> (if IE is handled, for instance), >> >> Best would be to call fireUntilHalt() and call the session's halt >> method. >> >> But why would you want to do this sort of weird thing? >> >> -W >> >> >> On 15/05/2012, mike wrote: >> > Hi there, >> > >> > Is there any way to kill a running session? >> > >> > I've been trying with StatefulKnowledgeSession.abortProcessInstance >> but i >> > can't get it working. >> > >> > For instance .. I got this drl >> > >> > rule "infinite loop" >> > when x : Integer() >> > then >> > System.out.println(x); >> > Thread.sleep(100); >> > insert(x + 1); >> > end >> > >> > n' this Thread >> > >> > public class SessionThread implements Runnable { >> > private StatefulKnowledgeSession session; >> > public SessionThread(StatefulKnowledgeSession session) { >> this.session = >> > session; } >> > public void run() { session.fireAllRules(); } >> > } >> > >> > then i create a session with the drl n' do something like ... >> > >> > session.insert(42); >> > Thread thread = new Thread(new SessionThread(session)); >> > thread.start(); >> > Thread.sleep(1000); >> > session.abortProcessInstance(thread.getId()); >> > >> > I've tried diff processInstanceIds and >> > session.getProcessInstances() >> but >> > nothing seems to stop the running session >> > >> > Thank you >> > Mike >> > >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > > >>> >>> ___ >>> rules-users mailing list >>> rules-users@lists.jboss.org >>> https://lists.jboss.org/mailman/listinfo/rules-users >>> >>> >> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> >> > ___ rules-users mailing list rules-users@lists.jboss.org htt
Re: [rules-users] Killing a session
that's nice ... n' a bit clever ... it could work ... I mean, i could automatically append that to all sessions given that i control compiling the drls. Is there any setting or something that detects infinite loops? Like it would abort if if drools runs into an infinite loop? I guess I could do something with fireAllRules(int max) but figuring out a reasonable max would be fuzzy. I could also use the no-loop attribute but it would not pick up some cases of infinite loops. Thank you very much for you help Cheers Mike On Tue, May 15, 2012 at 3:55 PM, Wolfgang Laun wrote: > A very low salience rule depending on nothing and calling halt will stop > the run: > > rule Exit > salience -9 > when > then > drools.halt(); > end > > -W > > > On 15 May 2012 21:46, mike wrote: > >> Well I got this wrong sorry. Yes I can stop a session if I start it with >> fireUntilHalt() but it never stops. I need it to finish by itself too. >> >> Thank you >> Mike >> >> >> On Tue, May 15, 2012 at 11:06 AM, mike wrote: >> >>> wow that worked like a charm!!! thank you very much Wolfgang, I owe u a >>> beer or something :) >>> >>> Cheers >>> Mike >>> >>> >>> On Tue, May 15, 2012 at 11:01 AM, mike wrote: >>> Awesome I'll try that :) We got business ppl writing rules ... Those rules are going on infinite loops quite often ... Frankly I am not excited about killing the session, for me it's just a business request that I am trying to implement Thank you very much Wolfgang Cheers Mike On Tue, May 15, 2012 at 10:53 AM, Wolfgang Laun < wolfgang.l...@gmail.com> wrote: > You are confusing jBPM processes and Java threads. > > You can interrupt the thread SessionThread, but that's not reliable > (if IE is handled, for instance), > > Best would be to call fireUntilHalt() and call the session's halt > method. > > But why would you want to do this sort of weird thing? > > -W > > > On 15/05/2012, mike wrote: > > Hi there, > > > > Is there any way to kill a running session? > > > > I've been trying with StatefulKnowledgeSession.abortProcessInstance > but i > > can't get it working. > > > > For instance .. I got this drl > > > > rule "infinite loop" > > when x : Integer() > > then > > System.out.println(x); > > Thread.sleep(100); > > insert(x + 1); > > end > > > > n' this Thread > > > > public class SessionThread implements Runnable { > > private StatefulKnowledgeSession session; > > public SessionThread(StatefulKnowledgeSession session) { > this.session = > > session; } > > public void run() { session.fireAllRules(); } > > } > > > > then i create a session with the drl n' do something like ... > > > > session.insert(42); > > Thread thread = new Thread(new SessionThread(session)); > > thread.start(); > > Thread.sleep(1000); > > session.abortProcessInstance(thread.getId()); > > > > I've tried diff processInstanceIds and session.getProcessInstances() > but > > nothing seems to stop the running session > > > > Thank you > > Mike > > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > >>> >> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> >> > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Killing a session
A very low salience rule depending on nothing and calling halt will stop the run: rule Exit salience -9 when then drools.halt(); end -W On 15 May 2012 21:46, mike wrote: > Well I got this wrong sorry. Yes I can stop a session if I start it with > fireUntilHalt() but it never stops. I need it to finish by itself too. > > Thank you > Mike > > > On Tue, May 15, 2012 at 11:06 AM, mike wrote: > >> wow that worked like a charm!!! thank you very much Wolfgang, I owe u a >> beer or something :) >> >> Cheers >> Mike >> >> >> On Tue, May 15, 2012 at 11:01 AM, mike wrote: >> >>> Awesome I'll try that :) >>> >>> We got business ppl writing rules ... Those rules are going on infinite >>> loops quite often ... Frankly I am not excited about killing the session, >>> for me it's just a business request that I am trying to implement >>> >>> Thank you very much Wolfgang >>> >>> Cheers >>> Mike >>> >>> >>> On Tue, May 15, 2012 at 10:53 AM, Wolfgang Laun >> > wrote: >>> You are confusing jBPM processes and Java threads. You can interrupt the thread SessionThread, but that's not reliable (if IE is handled, for instance), Best would be to call fireUntilHalt() and call the session's halt method. But why would you want to do this sort of weird thing? -W On 15/05/2012, mike wrote: > Hi there, > > Is there any way to kill a running session? > > I've been trying with StatefulKnowledgeSession.abortProcessInstance but i > can't get it working. > > For instance .. I got this drl > > rule "infinite loop" > when x : Integer() > then > System.out.println(x); > Thread.sleep(100); > insert(x + 1); > end > > n' this Thread > > public class SessionThread implements Runnable { > private StatefulKnowledgeSession session; > public SessionThread(StatefulKnowledgeSession session) { this.session = > session; } > public void run() { session.fireAllRules(); } > } > > then i create a session with the drl n' do something like ... > > session.insert(42); > Thread thread = new Thread(new SessionThread(session)); > thread.start(); > Thread.sleep(1000); > session.abortProcessInstance(thread.getId()); > > I've tried diff processInstanceIds and session.getProcessInstances() but > nothing seems to stop the running session > > Thank you > Mike > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users >>> >>> >> > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Killing a session
Well I got this wrong sorry. Yes I can stop a session if I start it with fireUntilHalt() but it never stops. I need it to finish by itself too. Thank you Mike On Tue, May 15, 2012 at 11:06 AM, mike wrote: > wow that worked like a charm!!! thank you very much Wolfgang, I owe u a > beer or something :) > > Cheers > Mike > > > On Tue, May 15, 2012 at 11:01 AM, mike wrote: > >> Awesome I'll try that :) >> >> We got business ppl writing rules ... Those rules are going on infinite >> loops quite often ... Frankly I am not excited about killing the session, >> for me it's just a business request that I am trying to implement >> >> Thank you very much Wolfgang >> >> Cheers >> Mike >> >> >> On Tue, May 15, 2012 at 10:53 AM, Wolfgang Laun >> wrote: >> >>> You are confusing jBPM processes and Java threads. >>> >>> You can interrupt the thread SessionThread, but that's not reliable >>> (if IE is handled, for instance), >>> >>> Best would be to call fireUntilHalt() and call the session's halt method. >>> >>> But why would you want to do this sort of weird thing? >>> >>> -W >>> >>> >>> On 15/05/2012, mike wrote: >>> > Hi there, >>> > >>> > Is there any way to kill a running session? >>> > >>> > I've been trying with StatefulKnowledgeSession.abortProcessInstance >>> but i >>> > can't get it working. >>> > >>> > For instance .. I got this drl >>> > >>> > rule "infinite loop" >>> > when x : Integer() >>> > then >>> > System.out.println(x); >>> > Thread.sleep(100); >>> > insert(x + 1); >>> > end >>> > >>> > n' this Thread >>> > >>> > public class SessionThread implements Runnable { >>> > private StatefulKnowledgeSession session; >>> > public SessionThread(StatefulKnowledgeSession session) { this.session = >>> > session; } >>> > public void run() { session.fireAllRules(); } >>> > } >>> > >>> > then i create a session with the drl n' do something like ... >>> > >>> > session.insert(42); >>> > Thread thread = new Thread(new SessionThread(session)); >>> > thread.start(); >>> > Thread.sleep(1000); >>> > session.abortProcessInstance(thread.getId()); >>> > >>> > I've tried diff processInstanceIds and session.getProcessInstances() >>> but >>> > nothing seems to stop the running session >>> > >>> > Thank you >>> > Mike >>> > >>> ___ >>> rules-users mailing list >>> rules-users@lists.jboss.org >>> https://lists.jboss.org/mailman/listinfo/rules-users >>> >> >> > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Killing a session
wow that worked like a charm!!! thank you very much Wolfgang, I owe u a beer or something :) Cheers Mike On Tue, May 15, 2012 at 11:01 AM, mike wrote: > Awesome I'll try that :) > > We got business ppl writing rules ... Those rules are going on infinite > loops quite often ... Frankly I am not excited about killing the session, > for me it's just a business request that I am trying to implement > > Thank you very much Wolfgang > > Cheers > Mike > > > On Tue, May 15, 2012 at 10:53 AM, Wolfgang Laun > wrote: > >> You are confusing jBPM processes and Java threads. >> >> You can interrupt the thread SessionThread, but that's not reliable >> (if IE is handled, for instance), >> >> Best would be to call fireUntilHalt() and call the session's halt method. >> >> But why would you want to do this sort of weird thing? >> >> -W >> >> >> On 15/05/2012, mike wrote: >> > Hi there, >> > >> > Is there any way to kill a running session? >> > >> > I've been trying with StatefulKnowledgeSession.abortProcessInstance but >> i >> > can't get it working. >> > >> > For instance .. I got this drl >> > >> > rule "infinite loop" >> > when x : Integer() >> > then >> > System.out.println(x); >> > Thread.sleep(100); >> > insert(x + 1); >> > end >> > >> > n' this Thread >> > >> > public class SessionThread implements Runnable { >> > private StatefulKnowledgeSession session; >> > public SessionThread(StatefulKnowledgeSession session) { this.session = >> > session; } >> > public void run() { session.fireAllRules(); } >> > } >> > >> > then i create a session with the drl n' do something like ... >> > >> > session.insert(42); >> > Thread thread = new Thread(new SessionThread(session)); >> > thread.start(); >> > Thread.sleep(1000); >> > session.abortProcessInstance(thread.getId()); >> > >> > I've tried diff processInstanceIds and session.getProcessInstances() but >> > nothing seems to stop the running session >> > >> > Thank you >> > Mike >> > >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Killing a session
Awesome I'll try that :) We got business ppl writing rules ... Those rules are going on infinite loops quite often ... Frankly I am not excited about killing the session, for me it's just a business request that I am trying to implement Thank you very much Wolfgang Cheers Mike On Tue, May 15, 2012 at 10:53 AM, Wolfgang Laun wrote: > You are confusing jBPM processes and Java threads. > > You can interrupt the thread SessionThread, but that's not reliable > (if IE is handled, for instance), > > Best would be to call fireUntilHalt() and call the session's halt method. > > But why would you want to do this sort of weird thing? > > -W > > > On 15/05/2012, mike wrote: > > Hi there, > > > > Is there any way to kill a running session? > > > > I've been trying with StatefulKnowledgeSession.abortProcessInstance but i > > can't get it working. > > > > For instance .. I got this drl > > > > rule "infinite loop" > > when x : Integer() > > then > > System.out.println(x); > > Thread.sleep(100); > > insert(x + 1); > > end > > > > n' this Thread > > > > public class SessionThread implements Runnable { > > private StatefulKnowledgeSession session; > > public SessionThread(StatefulKnowledgeSession session) { this.session = > > session; } > > public void run() { session.fireAllRules(); } > > } > > > > then i create a session with the drl n' do something like ... > > > > session.insert(42); > > Thread thread = new Thread(new SessionThread(session)); > > thread.start(); > > Thread.sleep(1000); > > session.abortProcessInstance(thread.getId()); > > > > I've tried diff processInstanceIds and session.getProcessInstances() but > > nothing seems to stop the running session > > > > Thank you > > Mike > > > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Killing a session
You are confusing jBPM processes and Java threads. You can interrupt the thread SessionThread, but that's not reliable (if IE is handled, for instance), Best would be to call fireUntilHalt() and call the session's halt method. But why would you want to do this sort of weird thing? -W On 15/05/2012, mike wrote: > Hi there, > > Is there any way to kill a running session? > > I've been trying with StatefulKnowledgeSession.abortProcessInstance but i > can't get it working. > > For instance .. I got this drl > > rule "infinite loop" > when x : Integer() > then > System.out.println(x); > Thread.sleep(100); > insert(x + 1); > end > > n' this Thread > > public class SessionThread implements Runnable { > private StatefulKnowledgeSession session; > public SessionThread(StatefulKnowledgeSession session) { this.session = > session; } > public void run() { session.fireAllRules(); } > } > > then i create a session with the drl n' do something like ... > > session.insert(42); > Thread thread = new Thread(new SessionThread(session)); > thread.start(); > Thread.sleep(1000); > session.abortProcessInstance(thread.getId()); > > I've tried diff processInstanceIds and session.getProcessInstances() but > nothing seems to stop the running session > > Thank you > Mike > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users