Re: [rules-users] Drools Flow: waiting for process to complete without polling
You could either embed Drools inside your application, or run it as a separate service, either are probably fine. Note that, if you configure persistence, it will automatically store the state of your process instances at safe points during the execution of your application. That means that you can shut it down safely and continue across applications. Kris Quoting Alexandros Karypidis akary...@yahoo.gr: Hello Kris, Thank you for your reply. I am currenty doing test-driven development outside an application server to learn the API. I launch processes from within a unit test method; hence my need to wait in this manner so that I can perform a final assertion on process state (after the process is complete). You are totally correct to point out that in real life, I will be executing long-running processes from within JBoss in my application across multiple executions of the application. So what is the typical approach for doing that? Do you typically install Drools as a service in a SAR, or do you launch it with a servlet startup listener when the WAR starts? Also, how do you make sure a clean undeploy/shutdown occurs where process execution is gracefully suspended and process states are saved? Can you give me some pointers? Thank you. Kris Verlaenen wrote: I'm not sure that having a thread wait like this until all processes have completed is a good idea in general, as in theory processes could run for a long time (hours/days/weeks/...). Unless of course you are only using synchronous processes, but in that case the engine will only return once the process has been completed anyway (if you call it synchronously). But the approach you suggest is valid, you can register an event listener to react whenever a process instance is completed, or similarly you could use the history log to retrieve this kind of information (making it decoupled from the actual execution). Kris Quoting Alexandros Karypidis akary...@yahoo.gr: Hello, I'm not very experienced in the Drools Flow API so I'm looking into the best way to code a simple thing: wait for all processes in a session to complete without polling. The only way I could thing of from the javadoc reference I read, is to synchronize and do a wait()/notify() using a ProcessEventListener. It seems a lot of work for a use-case that is too basic. I set up a listener like this: pel = new ProcessEventListener() { // ... public void afterProcessCompleted(ProcessCompletedEvent pce) { synchronized (this) { notifyAll(); } } } ksession.addEventListener(pel); ...then wait for processes (one in this simplified case) to complete like this: synchronized (pel) { new Thread(new Runnable() { public void run() { ksession.fireUntilHalt(); } }).start(); ksession.startProcess(some.process); pel.wait(); // the notifyAll() resumes this } Is there a better way to do this? ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools Flow: waiting for process to complete without polling
I'm not sure that having a thread wait like this until all processes have completed is a good idea in general, as in theory processes could run for a long time (hours/days/weeks/...). Unless of course you are only using synchronous processes, but in that case the engine will only return once the process has been completed anyway (if you call it synchronously). But the approach you suggest is valid, you can register an event listener to react whenever a process instance is completed, or similarly you could use the history log to retrieve this kind of information (making it decoupled from the actual execution). Kris Quoting Alexandros Karypidis akary...@yahoo.gr: Hello, I'm not very experienced in the Drools Flow API so I'm looking into the best way to code a simple thing: wait for all processes in a session to complete without polling. The only way I could thing of from the javadoc reference I read, is to synchronize and do a wait()/notify() using a ProcessEventListener. It seems a lot of work for a use-case that is too basic. I set up a listener like this: pel = new ProcessEventListener() { // ... public void afterProcessCompleted(ProcessCompletedEvent pce) { synchronized (this) { notifyAll(); } } } ksession.addEventListener(pel); ...then wait for processes (one in this simplified case) to complete like this: synchronized (pel) { new Thread(new Runnable() { public void run() { ksession.fireUntilHalt(); } }).start(); ksession.startProcess(some.process); pel.wait(); // the notifyAll() resumes this } Is there a better way to do this? ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools Flow: waiting for process to complete without polling
Hello Kris, Thank you for your reply. I am currenty doing test-driven development outside an application server to learn the API. I launch processes from within a unit test method; hence my need to wait in this manner so that I can perform a final assertion on process state (after the process is complete). You are totally correct to point out that in real life, I will be executing long-running processes from within JBoss in my application across multiple executions of the application. So what is the typical approach for doing that? Do you typically install Drools as a service in a SAR, or do you launch it with a servlet startup listener when the WAR starts? Also, how do you make sure a clean undeploy/shutdown occurs where process execution is gracefully suspended and process states are saved? Can you give me some pointers? Thank you. Kris Verlaenen wrote: I'm not sure that having a thread wait like this until all processes have completed is a good idea in general, as in theory processes could run for a long time (hours/days/weeks/...). Unless of course you are only using synchronous processes, but in that case the engine will only return once the process has been completed anyway (if you call it synchronously). But the approach you suggest is valid, you can register an event listener to react whenever a process instance is completed, or similarly you could use the history log to retrieve this kind of information (making it decoupled from the actual execution). Kris Quoting Alexandros Karypidis akary...@yahoo.gr: Hello, I'm not very experienced in the Drools Flow API so I'm looking into the best way to code a simple thing: wait for all processes in a session to complete without polling. The only way I could thing of from the javadoc reference I read, is to synchronize and do a wait()/notify() using a ProcessEventListener. It seems a lot of work for a use-case that is too basic. I set up a listener like this: pel = new ProcessEventListener() { // ... public void afterProcessCompleted(ProcessCompletedEvent pce) { synchronized (this) { notifyAll(); } } } ksession.addEventListener(pel); ...then wait for processes (one in this simplified case) to complete like this: synchronized (pel) { new Thread(new Runnable() { public void run() { ksession.fireUntilHalt(); } }).start(); ksession.startProcess(some.process); pel.wait(); // the notifyAll() resumes this } Is there a better way to do this? ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Drools Flow: waiting for process to complete without polling
Hello, I'm not very experienced in the Drools Flow API so I'm looking into the best way to code a simple thing: wait for all processes in a session to complete without polling. The only way I could thing of from the javadoc reference I read, is to synchronize and do a wait()/notify() using a ProcessEventListener. It seems a lot of work for a use-case that is too basic. I set up a listener like this: pel = new ProcessEventListener() { // ... public void afterProcessCompleted(ProcessCompletedEvent pce) { synchronized (this) { notifyAll(); } } } ksession.addEventListener(pel); ...then wait for processes (one in this simplified case) to complete like this: synchronized (pel) { new Thread(new Runnable() { public void run() { ksession.fireUntilHalt(); } }).start(); ksession.startProcess(some.process); pel.wait(); // the notifyAll() resumes this } Is there a better way to do this? ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools Flow: waiting for process to complete without polling
java.util.concurrent.CountDownLatch, if you have java 1.5 available. You have to know the number of processes you're waiting on first, though. The javadoc for CountDownLatch has a usage example. A CyclicBarrier could do the same thing repeatedly. (CountDownLatch is single use.) - Original Message From: Alexandros Karypidis akary...@yahoo.gr To: Rules Users List rules-users@lists.jboss.org Sent: Tuesday, September 29, 2009 7:01:56 PM Subject: [rules-users] Drools Flow: waiting for process to complete without polling Hello, I'm not very experienced in the Drools Flow API so I'm looking into the best way to code a simple thing: wait for all processes in a session to complete without polling. The only way I could thing of from the javadoc reference I read, is to synchronize and do a wait()/notify() using a ProcessEventListener. It seems a lot of work for a use-case that is too basic. I set up a listener like this: pel = new ProcessEventListener() { // ... public void afterProcessCompleted(ProcessCompletedEvent pce) { synchronized (this) { notifyAll(); } } } ksession.addEventListener(pel); ...then wait for processes (one in this simplified case) to complete like this: synchronized (pel) { new Thread(new Runnable() { public void run() { ksession.fireUntilHalt(); } }).start(); ksession.startProcess(some.process); pel.wait(); // the notifyAll() resumes this } Is there a better way to do this? ___ 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