From 90ac7a3566995cc244f9fdaff41e6c5122c7ca2e Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 25 Feb 2011 10:42:05 +0000 Subject: using getopt --- tests/TestReady.java | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'tests/TestReady.java') diff --git a/tests/TestReady.java b/tests/TestReady.java index fc3bd91..49d9336 100644 --- a/tests/TestReady.java +++ b/tests/TestReady.java @@ -1,4 +1,6 @@ import fr.dgac.ivy.*; +import gnu.getopt.*; + /** * Ivy java ReadyMessage tester. @@ -7,7 +9,7 @@ import fr.dgac.ivy.*; * * (c) CENA * - * usage: java TestReady & java TestReady 2 + * usage: java TestReady & java TestReady -o * */ @@ -54,7 +56,7 @@ class TestReady implements IvyApplicationListener { } } - TestReady() { + TestReady(String domain) { try { bus = new Ivy(me, ready_message, this); @@ -62,7 +64,7 @@ class TestReady implements IvyApplicationListener { bus.bindMsg ("^are you there "+me, new Question()); bus.bindMsg ("^(yes i am "+other+")", new Reply()); - bus.start(null); + bus.start(domain); } catch (IvyException ie) { System.err.println("can't run the Ivy bus" + ie.getMessage()); } @@ -84,14 +86,28 @@ class TestReady implements IvyApplicationListener { } public static void main(String args[]) { + Getopt opt = new Getopt("TestReady",args,"b:o"); + String domain=Ivy.getDomain(null); + int c; + boolean swap = false; + while ((c = opt.getopt()) != -1) switch (c) { + case 'b': + domain=opt.getOptarg(); + break; + case 'o': + swap=true; + break; + default: + System.exit(0); + } - if (args.length >= 1) { + if (swap) { me = "B"; other = "A"; ready_message = "B ready"; ready_bind = "^A ready"; } System.out.println("I am "+me); - new TestReady(); + new TestReady(domain); } } -- cgit v1.1