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

Greg Barton greg_barton at yahoo.com
Tue Sep 29 20:50:45 EDT 2009


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 <akarypid at yahoo.gr>
To: Rules Users List <rules-users at 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 at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



      



More information about the rules-users mailing list