[rules-users] Drools Flow: waiting for process to complete without polling

Kris Verlaenen kris.verlaenen at cs.kuleuven.be
Thu Oct 1 11:42:24 EDT 2009


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 <akarypid at 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 at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 




Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the rules-users mailing list