diff options
Diffstat (limited to 'examples/ivyTranslater.java')
-rw-r--r-- | examples/ivyTranslater.java | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/examples/ivyTranslater.java b/examples/ivyTranslater.java index 497ac87..5299338 100644 --- a/examples/ivyTranslater.java +++ b/examples/ivyTranslater.java @@ -1,46 +1,45 @@ /** * Yet another Ivy java program example * - * This is the example from the documentations, it connects to the bus, and - * translate the messages beginning with "Hello" by the same message, where - * "Hello" is replaced by "Bonjour". + * This is the example from the documentation * * @author Yannick Jestin <jestin@cena.fr> * * (c) CENA * - * This program is distributed as is, under the LGPL licence, which should be - * present in the package. + * This program is distributed as is * */ import fr.dgac.ivy.* ; class ivyTranslater implements IvyMessageListener { - private Ivy bus; + private Ivy bus; - ivyTranslater() { - bus = new Ivy("IvyTranslater","Hello le monde",null); - bus.bindMsg("^Hello(.*)",this); - bus.bindMsg("^Bye$",new IvyMessageListener() { - // callback for "Bye" message - public void receive(IvyClient client, - String[] args) {System.exit(0);} - }); - try { - // starts the bus on the default domain or IVY_DOMAIN property - bus.start(null); - } catch (IvyException ie) { - System.err.println("can't run the Ivy bus" + ie.getMessage()); + ivyTranslater() throws IvyException { + // initialization, name and ready message + bus = new Ivy("IvyTranslater","IvyTranslater Ready",null); + bus.bindMsg("^Hello(.*)",this); + bus.bindMsg("^Bye$",new IvyMessageListener() { + // callback for "Bye" message + public void receive(IvyClient client, String[] args) { + bus.stop(); } - } + }); + // starts the bus on the default domain + bus.start(null); + } - // callback associated to the "Hello" messages" - public void receive(IvyClient client, String[] args) { + // callback associated to the "Hello" messages" + public void receive(IvyClient client, String[] args) { + try { bus.sendMsg("Bonjour"+((args.length>0)?args[0]:"")); + } catch (IvyException ie) { + System.out.println("can't send my message !"); } + } - public static void main(String args[]) { - new ivyTranslater(); - } + public static void main(String args[]) throws IvyException { + new ivyTranslater(); + } } |