From e854a58a81ec90e419a4b3effa5a83caac05df90 Mon Sep 17 00:00:00 2001 From: jestin Date: Sun, 13 May 2012 08:54:38 +0000 Subject: Modified the tests to remove bus.getDomain(null) make Waiter and WaiterClient sons of WaitFor Added a few tests into svn --- src/Waiter.java | 50 +++++++++++--------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) (limited to 'src/Waiter.java') diff --git a/src/Waiter.java b/src/Waiter.java index d625217..4679f09 100644 --- a/src/Waiter.java +++ b/src/Waiter.java @@ -1,5 +1,5 @@ /** - * a helper class to implement faitForClient, Wait for Message + * a helper class to implement "Wait for Message" in {@link Ivy.waitForMsg} * @author Yannick Jestin * @author http://www.tls.cena.fr/products/ivy/ * @@ -10,45 +10,17 @@ package fr.dgac.ivy ; -class Waiter implements Runnable, IvyMessageListener { - private static final int INCREMENT = 100; - int timeout; - private IvyClient received=null; - private boolean forever=false; - private Thread t; +class Waiter extends WaitFor implements IvyMessageListener { - public Waiter(int timeout) { - this.timeout=timeout; - if (timeout<=0) forever=true; - t=new Thread(this); - t.setName("Ivy Waiter thread, for message"); - } - - public IvyClient waitFor() { - t.start(); - try { t.join(); } catch (InterruptedException ie) { return null; } - return received; - } + public Waiter(int timeout) { + super(timeout); + setName("Ivy Waiter thread, for message"); + } - 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; - } - } - // System.out.println("DEV Waiter stop"); - } + boolean check() { return false; } - public void receive(IvyClient ic, String[] args) { - received=ic; - t.interrupt(); - } + public void receive(IvyClient ic, String[] args) { + received=ic; + interrupt(); } +} -- cgit v1.1