From 8e92224db5274f8a028f28f830b52e78ee88fda2 Mon Sep 17 00:00:00 2001 From: jestin Date: Tue, 22 Nov 2005 12:16:36 +0000 Subject: See changes inside. major change in multibus error handling. I reintroduced bugs .. --- src/After.java | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/After.java (limited to 'src/After.java') diff --git a/src/After.java b/src/After.java new file mode 100644 index 0000000..298830d --- /dev/null +++ b/src/After.java @@ -0,0 +1,59 @@ +/** + * an utility waiting for a message to come, then exiting. + * + * @author Yannick Jestin + * @author http://www.tls.cena.fr/products/ivy/ + * + * (c) CENA + * + * Changelog: + * 1.2.8: new in the ivy package + * TODO / BUG: sur un die, quitter avec un -1 + */ +package fr.dgac.ivy.tools ; +import fr.dgac.ivy.* ; +import gnu.getopt.Getopt; + +public class After implements IvyMessageListener { + + public final static int DEFAULTTIMEOUT = 0 ; + + public static final String helpmsg = "usage: java fr.dgac.ivy.After [options] regexp\n\t-b BUS\tspecifies the Ivy bus domain\n\t-t\ttime out in seconds, defaults to "+DEFAULTTIMEOUT+"\n\t-h\thelp\n\n\t regexp is a Perl5 compatible regular expression"; + + public static void main(String[] args) throws IvyException { + Getopt opt = new Getopt("After",args,"b:t:"); + int c; + String domain=Ivy.getDomain(null); + String name="AFTER"; + int timeout = DEFAULTTIMEOUT; + while ((c = opt.getopt()) != -1) switch (c) { + case 'b': domain=opt.getOptarg(); break; + case 't': timeout=Integer.parseInt(opt.getOptarg()); break; + case 'h': + default: System.out.println(helpmsg); System.exit(0); + } + if (opt.getOptind()!=args.length-1) { System.out.println(helpmsg); System.exit(0); } + String regexp=args[opt.getOptind()]; + Ivy bus=new Ivy(name,name+" ready",null); + bus.bindMsgOnce(regexp,new After(bus)); + bus.start(domain); + if (timeout>0) { + System.out.println("waiting "+timeout+"s for "+regexp); + try { Thread.sleep(timeout*1000); } catch (InterruptedException ie) { } + System.out.println(regexp+" not received, bailing out"); + bus.stop(); + System.exit(-1); + } else { + System.out.println("waiting forever for "+regexp); + } + } + + private Ivy bus; + public After(Ivy b) { bus=b; } + + public void receive(IvyClient ic,String[] args) { + bus.stop(); + System.exit(0); + } + +} -- cgit v1.1