diff options
author | jestin | 2012-05-13 08:54:38 +0000 |
---|---|---|
committer | jestin | 2012-05-13 08:54:38 +0000 |
commit | e854a58a81ec90e419a4b3effa5a83caac05df90 (patch) | |
tree | 16eb84a66b62ff38e744c8cd474df81561436b9f /src/WaitFor.java | |
parent | 4ffe8b84071babe544086f94c66431380d301d59 (diff) | |
download | ivy-java-e854a58a81ec90e419a4b3effa5a83caac05df90.zip ivy-java-e854a58a81ec90e419a4b3effa5a83caac05df90.tar.gz ivy-java-e854a58a81ec90e419a4b3effa5a83caac05df90.tar.bz2 ivy-java-e854a58a81ec90e419a4b3effa5a83caac05df90.tar.xz |
Modified the tests to remove bus.getDomain(null)
make Waiter and WaiterClient sons of WaitFor
Added a few tests into svn
Diffstat (limited to 'src/WaitFor.java')
-rw-r--r-- | src/WaitFor.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/WaitFor.java b/src/WaitFor.java new file mode 100644 index 0000000..04b5172 --- /dev/null +++ b/src/WaitFor.java @@ -0,0 +1,55 @@ +/** + * a helper class to implement "Wait for Message/Client" + * @author Yannick Jestin + * @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a> + * + * CHANGELOG: + * 1.2.16: + * - factorize code from Waiter and WaiterClient + */ + +package fr.dgac.ivy ; + +abstract class WaitFor implements Runnable { + private static final int INCREMENT = 100; + int timeout; + IvyClient received=null; + boolean forever=false; + private Thread t; + + void setName(String s) { t.setName(s); } + void interrupt() { t.interrupt(); } + + WaitFor(int timeout) { + this.timeout=timeout; + if (timeout<=0) forever=true; + t=new Thread(this); + } + + public IvyClient waitFor() { + t.start(); + try { t.join(); } catch (InterruptedException ie) { return null; } + return received; + } + + public void run() { + boolean encore=true; + // System.out.println("DEV Waiter start"); + while (encore) { + try { + if (INCREMENT>0) Thread.sleep(INCREMENT); + if (!forever) { + timeout-=INCREMENT; + if (timeout<=0) encore=false; + } + } catch (InterruptedException ie) { + break; + } + if (check()) break; + } + // System.out.println("DEV Waiter stop"); + } + + abstract boolean check(); // is called in the thread, leaves if true + +} |