From be5724a2d22decb502d81e8d88a5922fbffa5f33 Mon Sep 17 00:00:00 2001 From: jestin Date: Fri, 30 Jul 2004 12:55:46 +0000 Subject: ooops, those should have been in the repository ... --- src/Waiter.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ src/WaiterClient.java | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/Waiter.java create mode 100644 src/WaiterClient.java (limited to 'src') diff --git a/src/Waiter.java b/src/Waiter.java new file mode 100644 index 0000000..c4eb29b --- /dev/null +++ b/src/Waiter.java @@ -0,0 +1,52 @@ +/** + * @author Yannick Jestin + * @author http://www.tls.cena.fr/products/ivy/ + * + * CHANGELOG: + * 1.2.4: + */ + +package fr.dgac.ivy ; +import java.util.*; + +class Waiter implements Runnable, IvyMessageListener { + private static final int INCREMENT = 100; + int timeout; + private IvyClient received=null; + private boolean forever=false; + private Thread t; + + public Waiter(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 { + t.sleep(INCREMENT); + if (!forever) { + timeout-=INCREMENT; + if (timeout<=0) encore=false; + } + } catch (InterruptedException ie) { + break; + } + } + // System.out.println("DEV Waiter stop"); + } + + public void receive(IvyClient ic, String[] args) { + received=ic; + t.interrupt(); + } + } diff --git a/src/WaiterClient.java b/src/WaiterClient.java new file mode 100644 index 0000000..931a048 --- /dev/null +++ b/src/WaiterClient.java @@ -0,0 +1,55 @@ +/** + * @author Yannick Jestin + * @author http://www.tls.cena.fr/products/ivy/ + * + * CHANGELOG: + * 1.2.4: + */ + +package fr.dgac.ivy ; +import java.util.*; + +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; + + WaiterClient(String n,int timeout) { + this.timeout=timeout; + name=n; + if (timeout<=0) forever=true; + t=new Thread(this); + } + + IvyClient waitForClient() { + t.start(); + try { t.join(); } catch (InterruptedException ie) { return null; } + return received; + } + + public void run() { + boolean encore=true; + // System.out.println("DEV WaiterClient start"); + while (encore) { + try { + t.sleep(INCREMENT); + if (!forever) { + timeout-=INCREMENT; + if (timeout<=0) encore=false; + } + } catch (InterruptedException ie) { + break; + } + } + // System.out.println("DEV WaiterClient stop"); + } + + public void connect(fr.dgac.ivy.IvyClient client) { + if (name.compareTo(client.getApplicationName())!=0) return; + received=client; + t.interrupt(); + } + } -- cgit v1.1