diff options
Diffstat (limited to 'src/WaiterClient.java')
-rw-r--r-- | src/WaiterClient.java | 65 |
1 files changed, 21 insertions, 44 deletions
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 <Integer,IvyClient>clients ; +class WaiterClient extends WaitFor implements IvyApplicationListener { + private String name; + private Map <Integer,IvyClient>clients ; - WaiterClient(String n,int timeout,Map <Integer,IvyClient>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 <Integer,IvyClient>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 ) {} +} |