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/WaiterClient.java | 65 +++++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 44 deletions(-) (limited to 'src/WaiterClient.java') diff --git a/src/WaiterClient.java b/src/WaiterClient.java index f6b00b5..5f36fca 100644 --- a/src/WaiterClient.java +++ b/src/WaiterClient.java @@ -14,51 +14,28 @@ package fr.dgac.ivy ; import java.util.Map; -class WaiterClient extends IvyApplicationAdapter implements Runnable { - private static final int INCREMENT = 100; - int timeout; - private IvyClient received=null; - private boolean forever=false; - private Thread t; - String name; - private Map clients ; +class WaiterClient extends WaitFor implements IvyApplicationListener { + private String name; + private Map clients ; - WaiterClient(String n,int timeout,Map clients) { - this.timeout=timeout; - this.clients=clients; - name=n; - if (timeout<=0) forever=true; - t=new Thread(this); - t.setName("Ivy Waiter thread, for client"); - } - - IvyClient waitForClient() { - t.start(); - try { t.join(); } catch (InterruptedException ie) { return null; } - return received; - } + WaiterClient(String n,int timeout,Map clients) { + super(timeout); + this.clients=clients; + name=n; + setName("Ivy Waiter thread, for client"); + } - public void run() { - boolean encore=true; - // System.out.println("DEV WaiterClient start"); - while (encore) { - try { - if (INCREMENT>0) Thread.sleep(INCREMENT); - if (!forever) { - timeout-=INCREMENT; - if (timeout<=0) encore=false; - } - } catch (InterruptedException ie) { - break; - } - if ((received=Ivy.alreadyThere(clients,name))!=null) break; - } - // System.out.println("DEV WaiterClient stop"); - } + boolean check() { + return (received=Ivy.alreadyThere(clients,name)) != null; + } - public void connect(fr.dgac.ivy.IvyClient client) { - if (name.compareTo(client.getApplicationName())!=0) return; - received=client; - t.interrupt(); - } + public void connect(fr.dgac.ivy.IvyClient client) { + if (name.compareTo(client.getApplicationName())!=0) return; + received=client; + interrupt(); } + + public void disconnect( IvyClient client ) { } + public void die( IvyClient client, int id, String msgarg) { } + public void directMessage( IvyClient client, int id,String msgarg ) {} +} -- cgit v1.1