aboutsummaryrefslogtreecommitdiff
path: root/src/After.java
diff options
context:
space:
mode:
authorjestin2005-11-22 12:16:36 +0000
committerjestin2005-11-22 12:16:36 +0000
commit8e92224db5274f8a028f28f830b52e78ee88fda2 (patch)
tree2d4281a99d94329bce5b23af65377243cccbd98e /src/After.java
parent5d466ac8508cf202bd025bc9d813b07fc47ac44b (diff)
downloadivy-java-8e92224db5274f8a028f28f830b52e78ee88fda2.zip
ivy-java-8e92224db5274f8a028f28f830b52e78ee88fda2.tar.gz
ivy-java-8e92224db5274f8a028f28f830b52e78ee88fda2.tar.bz2
ivy-java-8e92224db5274f8a028f28f830b52e78ee88fda2.tar.xz
See changes inside.
major change in multibus error handling. I reintroduced bugs ..
Diffstat (limited to 'src/After.java')
-rw-r--r--src/After.java59
1 files changed, 59 insertions, 0 deletions
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 <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
+ *
+ * (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);
+ }
+
+}